Example #1
0
        // unpack a message we received
        public static T Unpack <T>(byte[] data)
        {
            using (PooledNetworkReader networkReader = NetworkReaderPool.GetReader(data))
            {
                int msgType = GetId <T>();

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

                return(networkReader.Read <T>());
            }
        }
        // unpack a message we received
        public static T Unpack <T>(byte[] data) where T : IMessageBase, new()
        {
            using (PooledNetworkReader networkReader = NetworkReaderPool.GetReader(data))
            {
                int msgType = GetId <T>();

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

                T message = new T();
                message.Deserialize(networkReader);

                return(message);
            }
        }