Пример #1
0
        public NetworkPacket Deserialize(MessageReader br)
        {
            var packetSize = br.ReadInt32();
            var packet     = new NetworkPacket();

            packet.Id = br.ReadInt16();
            var payload = br.ReadBytes(packetSize - HeaderSize);//dataSize

            if (packetLookup.TryGetValue(packet.Id, out var targetType))
            {
                try
                {
                    packet.Data = binarySerializer.Deserialize(payload, targetType);

                    return(packet);
                }
                catch (Exception exc)
                {
                    var hoverOverMe = GenerateDebugCode(payload, targetType);
                    throw;
                }
            }

            throw new Exception($"Unable to deserialize packet. No type lookups registered for packet ID ({packet.Id}).");

            //packet.Data = payload;
            //return packet;
        }
Пример #2
0
        public NetworkPacket Deserialize(MessageReader br)
        {
            var packetSize = br.ReadInt32();
            var packet     = new NetworkPacket();

            packet.Id = br.ReadInt16();
            var payload = br.ReadBytes(packetSize - HeaderSize);//dataSize

            if (packetLookup.TryGetValue(packet.Id, out var targetType))
            {
                packet.Data = binarySerializer.Deserialize(payload, targetType);
                return(packet);
            }

            if (logger != null)
            {
                logger.LogInformation($"Unable to deserialize packet. No type lookups registered for packet ID ({packet.Id}).");
            }

            return(null);
            //throw new Exception($"Unable to deserialize packet. No type lookups registered for packet ID ({packet.Id}).");
        }