Exemplo n.º 1
0
        public override bool Serialize(ref PacketOutStream Data, bool Force)
        {
            if (val == null)
            {
                return(false);
            }

            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, true);
                    PacketProcessor.WriteField(ref Data, (EPacketFieldType)ValueType, KP.Value, true);
                }

                return(true);
            }

            return(false);
        }
Exemplo n.º 2
0
        public override bool Serialize(ref PacketOutStream Data, bool Force)
        {
            Log.Debug("WriteList", "Serialize : " + val);

            if (val == null)
            {
                return(false);
            }

            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 ISerializablePacket[])
            {
                ISerializablePacket[] Packets = val as ISerializablePacket[];

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

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

                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, (ulong)Values[i], true);
                }
            }
            else if (val is List <long> )
            {
                List <long> Values = val as List <long>;

                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], true);
                }
            }
            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], true);
                }
            }
            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], true);
                }
            }
            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], true);
                }

                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, true);
                }

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

            return(true);
        }