Exemplo n.º 1
0
        // unpack a message we received
        public static T UnpackFromByteArray <T>(byte[] data)
            where T : struct, NetworkMessage
        {
            using (PooledNetworkReader networkReader = NetworkReaderPool.GetReader(data))
            {
                int msgType = MessagePacking.GetId <T>();

                int id = networkReader.ReadUShort();
                if (id != msgType)
                {
                    throw new FormatException($"Invalid message,  could not unpack {typeof(T).FullName}");
                }

                return(networkReader.Read <T>());
            }
        }