Exemplo n.º 1
0
        public override object Deserialize(List<byte> byteList, TLPropertyAttribute attribute)
        {
            int count = byteList.ReadByte();
            int startOffset = 1;

            if (count >= 254)
            {
                count = byteList.ReadByte();
                count += byteList.ReadByte() << 8;
                count += byteList.ReadByte() << 16;
                startOffset = 4;
            }

            TLBytes bytes = new TLBytes(byteList.Take(count).ToArray());
            byteList.RemoveRange(0, count);

            int offset = (count + startOffset) % 4;
            if (offset != 0)
            {
                int offsetCount = 4 - offset;
                for (int i = 0; i < offsetCount; i++)
                    byteList.ReadByte();
            }

            return bytes;
        }
 public override object Deserialize(List<byte> byteList, TLPropertyAttribute attribute)
 {
     int arrCount = attribute.ArrayLength;
     byte[] arr = byteList.Take(arrCount).ToArray();
     byteList.RemoveRange(0, arrCount);
     return arr;
 }
Exemplo n.º 3
0
        public override byte[] Serialize(object input, TLPropertyAttribute attribute)
        {
            TLBytes bytes = (TLBytes)input;
            int len = bytes.Content.Length;
            int startOffset = 1;

            List<byte> list = new List<byte>();

            if (len >= 254)
            {
                list.Add(254);
                list.Add((byte)(len & 0xFF));
                list.Add((byte)((len >> 8) & 0xFF));
                list.Add((byte)((len >> 16) & 0xFF));
                startOffset = 4;
            }
            else
            {
                list.Add((byte)len);
            }

            list.AddRange(bytes.Content);

            int offset = (len + startOffset) % 4;
            if (offset != 0)
            {
                int offsetCount = 4 - offset;
                list.AddRange(Enumerable.Repeat((byte)0x00, offsetCount));
            }

            return list.ToArray();
        }
Exemplo n.º 4
0
        public override object Deserialize(List<byte> byteList, TLPropertyAttribute attribute)
        {
            UInt32 value = (UInt32)TLRootSerializer.Deserialize(byteList, typeof(UInt32));
            if (value == BoolTrue)
                return true;
            if (value == BoolFalse)
                return false;

            throw new ArgumentException("Unrecognized bool sequence.");
        }
Exemplo n.º 5
0
        public override object Deserialize(List<byte> byteList, TLPropertyAttribute attribute)
        {
            UInt32 expectedClassId = GetSerializerType().GetClassId();
            UInt32 classId = (UInt32)TLRootSerializer.Deserialize(byteList, typeof(UInt32));
            if (expectedClassId != classId)
                throw new NotSupportedException(string.Format(CultureInfo.CurrentCulture, "{0} =/= {1}", expectedClassId, classId));

            dynamic vector = Activator.CreateInstance(typeof(TLVector<>).MakeGenericType(attribute.VectorType));

            int len = (int)TLRootSerializer.Deserialize(byteList, typeof(Int32));

            for (int i = 0; i < len; i++)
                vector.Content.Add((dynamic)TLRootSerializer.Deserialize(byteList, attribute.VectorType));

            return vector;
        }
Exemplo n.º 6
0
        public override byte[] Serialize(object input, TLPropertyAttribute attribute)
        {
            dynamic vector = input;

            UInt32 classId = GetSerializerType().GetClassId();
            int len = vector.Content.Count;

            List<byte> byteList = new List<byte>();
            byteList.AddRange(TLRootSerializer.Serialize(classId));
            byteList.AddRange(TLRootSerializer.Serialize(len));

            foreach (dynamic d in vector.Content)
                byteList.AddRange(TLRootSerializer.Serialize(d));

            return byteList.ToArray();
        }
Exemplo n.º 7
0
 public override byte[] Serialize(object input, TLPropertyAttribute attribute)
 {
     return TLRootSerializer.Serialize((bool)input ? BoolTrue : BoolFalse);
 }
 public abstract byte[] Serialize(object input, TLPropertyAttribute attribute);
 public abstract object Deserialize(List<byte> byteList, TLPropertyAttribute attribute);
Exemplo n.º 10
0
 public override byte[] Serialize(object input, TLPropertyAttribute attribute)
 {
     return TLRootSerializer.Serialize(new TLBytes(Encoding.UTF8.GetBytes((string)input)));
 }
Exemplo n.º 11
0
 public override object Deserialize(List<byte> byteList, TLPropertyAttribute attribute)
 {
     TLBytes bytes = (TLBytes)TLRootSerializer.Deserialize(byteList, typeof(TLBytes));
     return Encoding.UTF8.GetString(bytes.Content);
 }
Exemplo n.º 12
0
 public override object Deserialize(List<byte> byteList, TLPropertyAttribute attribute)
 {
     byte[] arr = byteList.Take(8).ToArray();
     byteList.RemoveRange(0, 8);
     return BitConverter.ToUInt64(arr, 0);
 }
Exemplo n.º 13
0
 public override byte[] Serialize(object input, TLPropertyAttribute attribute)
 {
     return BitConverter.GetBytes((UInt64)input);
 }
 public override byte[] Serialize(object input, TLPropertyAttribute attribute)
 {
     return (byte[])input;
 }