Esempio n. 1
0
        public override void Deserialize(ref PacketInStream Data)
        {
            long DicData = Data.ReadEncoded7Bit();

            int KeyType;
            int ValueType;
            int Count;

            PacketInStream.Decode3Parameters(DicData, out KeyType, out ValueType, out Count);
            Dictionary <ISerializableField, ISerializableField> Dic = new Dictionary <ISerializableField, ISerializableField>();


            Log.Debug("DicBitField", "KeyType = " + KeyType + ",ValueType=" + ValueType + ",Count=" + Count);

            for (int i = 0; i < Count; ++i)
            {
                ISerializableField Key   = PacketProcessor.ReadField(ref Data, i, KeyType);
                ISerializableField Value = PacketProcessor.ReadField(ref Data, i, ValueType);

                if (Key != null && Value != null)
                {
                    Dic.Add(Key, Value);
                }
            }

            val = Dic;
        }
        public static ISerializableField ReadField(ref PacketInStream Stream)
        {
            long FieldData = Stream.ReadEncoded7Bit();

            if (FieldData < 0)
            {
                return(null);
            }

            int FieldType;
            int FieldIndex;

            if (!PacketInStream.Decode2Parameters(FieldData, out FieldType, out FieldIndex))
            {
                return(null);
            }

            return(ReadField(ref Stream, FieldIndex, FieldType));
        }
Esempio n. 3
0
        public override void Deserialize(ref PacketInStream Data)
        {
            long ListData = Data.ReadEncoded7Bit();
            int  ListType;
            int  ListCount;

            PacketInStream.Decode2Parameters(ListData, out ListType, out ListCount);
            List <ISerializableField> Fields = new List <ISerializableField>();

            Log.Debug("Packet", "------> List : " + ListType + "(" + ListCount + ")");
            for (int i = 0; i < ListCount; ++i)
            {
                ISerializableField Field = PacketProcessor.GetFieldType((EPacketFieldType)ListType);
                if (Field != null)
                {
                    Field.Deserialize(ref Data);
                    Fields.Add(Field);
                }
            }

            val = Fields;
        }
Esempio n. 4
0
        public override void Deserialize(ref PacketInStream Data)
        {
            long Opcode = Data.ReadEncoded7Bit();
            PacketHandlerDefinition Handler = PacketProcessor.GetPacketHandler(Opcode);
            ISerializablePacket     Packet  = Activator.CreateInstance(Handler.GetClass()) as ISerializablePacket;

            ISerializableField Field = null;

            Log.Debug("Packet", "----------------------> New " + Opcode.ToString("X8"));
            Packet.Opcode = Opcode;

            while ((Field = PacketProcessor.ReadField(ref Data)) != null)
            {
                Log.Debug("Packet", "------> ++T : " + Field.PacketType);
                Packet.AddField(Field.Index, Field);
            }

            Log.Debug("Packet", "----------------------> End ");

            Packet.ApplyToFieldInfo();
            val = Packet;
        }
Esempio n. 5
0
 public override void Deserialize(ref PacketInStream Data)
 {
     val = Data.ReadEncoded7Bit();
 }
Esempio n. 6
0
        public override void Deserialize(ref PacketInStream Data)
        {
            long Size = Data.ReadEncoded7Bit();

            val = Data.Read((int)Size);
        }
Esempio n. 7
0
        public bool ReadPacket()
        {
            if (Received.Count <= 0)
            {
                return(false);
            }

            if (!ReceiveCompress && !Crypted)
            {
                PacketInStream Packet = new PacketInStream(Received.ToArray(), Received.Count);
                long           Size   = Packet.ReadEncoded7Bit();

                if (Size > Packet.Length)
                {
                    return(false);
                }

                Received.RemoveRange(0, (int)(Packet.Position + Size));

                ISerializablePacket Pack = PacketProcessor.ReadPacket(ref Packet);
                if (Pack != null)
                {
                    Pack.OnRead(this);
                }

                return(true);
            }

            if (Crypted)
            {
                byte[] Packet = Received.ToArray();
                Received.Clear();
                Decrypt(Packet);
            }

            if (ReceiveCompress)
            {
                int End = -1;
                while ((End = GetEndCompression(ref Decrypted)) >= 0)
                {
                    byte[] ToUnCompress = new byte[End];
                    Buffer.BlockCopy(Decrypted.ToArray(), 0, ToUnCompress, 0, End);
                    Decrypted.RemoveRange(0, End);

                    byte[] Result = UnCompress(ToUnCompress);

                    Log.Dump("Decrypted", Result, 0, Result.Length);
                    PacketInStream Packet = new PacketInStream(Result, Result.Length);
                    long           Size   = Packet.ReadEncoded7Bit();

                    if (Size > Packet.Length)
                    {
                        Log.Error("ReadPacket", "Size > Packet.Lenght,Size=" + Size + ",Lenght=" + Packet.Length);
                        Packet.Dispose();
                        continue;
                    }

                    ISerializablePacket Pack = PacketProcessor.ReadPacket(ref Packet);
                    if (Pack != null)
                    {
                        Pack.OnRead(this);
                    }

                    Packet.Dispose();
                }
            }

            return(false);
        }
Esempio n. 8
0
 public override void Deserialize(ref PacketInStream Data)
 {
     val = Data.ReadEncoded7Bit();
 }