Пример #1
0
        public override bool Serialize(ref PacketOutStream Data)
        {
            if (val is Dictionary <long, ISerializablePacket> )
            {
                Dictionary <long, ISerializablePacket> Dic = val as Dictionary <long, ISerializablePacket>;
                int KeyType   = (int)EPacketFieldType.Unsigned7BitEncoded;
                int ValueType = (int)EPacketFieldType.Packet;
                int Count     = Dic.Count;

                if (Count <= 0)
                {
                    return(false);
                }

                long DicData;
                PacketOutStream.Encode3Parameters(out DicData, KeyType, ValueType, Count);
                Data.WriteEncoded7Bit(DicData);

                foreach (KeyValuePair <long, ISerializablePacket> KP in Dic)
                {
                    PacketProcessor.WriteField(ref Data, (EPacketFieldType)KeyType, KP.Key);
                    PacketProcessor.WriteField(ref Data, (EPacketFieldType)ValueType, KP.Value);
                }

                return(true);
            }

            return(false);
        }
Пример #2
0
        public override bool Serialize(ref PacketOutStream Data)
        {
            Log.Success("WriteList", "Serialize : " + val);

            if (val is List <ISerializablePacket> )
            {
                List <ISerializablePacket> Packets = val as List <ISerializablePacket>;

                /*if (Packets.Count <= 0)
                 *  return false;*/

                long ListData;
                PacketOutStream.Encode2Parameters(out ListData, (int)EPacketFieldType.Packet, Packets.Count);
                Data.WriteEncoded7Bit(ListData);

                foreach (ISerializablePacket Packet in Packets)
                {
                    PacketProcessor.WritePacket(ref Data, Packet, false, true, true);
                }
            }
            else if (val is List <long> )
            {
                List <long> Values = val as List <long>;

                /*if (Values.Count <= 0)
                 *  return false;*/

                long ListData;
                PacketOutStream.Encode2Parameters(out ListData, (int)EPacketFieldType.Unsigned7BitEncoded, Values.Count);
                Data.WriteEncoded7Bit(ListData);

                for (int i = 0; i < Values.Count; ++i)
                {
                    PacketProcessor.WriteField(ref Data, EPacketFieldType.Unsigned7BitEncoded, (long)Values[i]);
                }
            }
            else if (val is List <uint> )
            {
                List <uint> Values = val as List <uint>;

                /*if (Values.Count <= 0)
                 *  return false;*/

                long ListData;
                PacketOutStream.Encode2Parameters(out ListData, (int)EPacketFieldType.Raw4Bytes, Values.Count);
                Data.WriteEncoded7Bit(ListData);

                for (int i = 0; i < Values.Count; ++i)
                {
                    PacketProcessor.WriteField(ref Data, EPacketFieldType.Raw4Bytes, (uint)Values[i]);
                }
            }
            else if (val is List <float> )
            {
                List <float> Values = val as List <float>;

                /*if (Values.Count <= 0)
                 *  return false;*/

                long ListData;
                PacketOutStream.Encode2Parameters(out ListData, (int)EPacketFieldType.Raw4Bytes, Values.Count);
                Data.WriteEncoded7Bit(ListData);

                for (int i = 0; i < Values.Count; ++i)
                {
                    PacketProcessor.WriteField(ref Data, EPacketFieldType.Raw4Bytes, Values[i]);
                }
            }
            else if (val is List <string> )
            {
                List <string> Strs = val as List <string>;

                /*if (Strs.Count <= 0)
                 *  return false;*/

                long ListData;
                PacketOutStream.Encode2Parameters(out ListData, (int)EPacketFieldType.ByteArray, Strs.Count);
                Data.WriteEncoded7Bit(ListData);

                for (int i = 0; i < Strs.Count; ++i)
                {
                    PacketProcessor.WriteField(ref Data, EPacketFieldType.ByteArray, (string)Strs[i]);
                }

                return(true);
            }
            else if (val is List <ISerializableField> )
            {
                List <ISerializableField> Strs = val as List <ISerializableField>;

                if (Strs.Count <= 0)
                {
                    return(false);
                }

                ISerializableField Field = Strs[0];

                long ListData;
                PacketOutStream.Encode2Parameters(out ListData, (int)Field.PacketType, Strs.Count);
                Data.WriteEncoded7Bit(ListData);

                for (int i = 0; i < Strs.Count; ++i)
                {
                    PacketProcessor.WriteField(ref Data, Strs[i].PacketType, Strs[i].val);
                }

                return(true);
            }
            else
            {
                return(false);
            }

            return(true);
        }