예제 #1
0
        private TLSerializationMode?GetVectorItemsSerializationModeOverride(ITLVectorSerializer vectorSerializer, PropertyInfo propertyInfo,
                                                                            TLSerializationContext context)
        {
            Type propType = propertyInfo.PropertyType;

            if (vectorSerializer.SupportedType != propType)
            {
                throw new NotSupportedException(string.Format("Current vector serializer doesn't support type: {0}. It supports: {1}", propType,
                                                              vectorSerializer.SupportedType));
            }

            TLSerializationMode?itemsSerializationModeOverride = TLSerializationMode.Bare;

            // Check for items serializer.
            // If items have multiple constructors or have a TLTypeAttribute (in other words it is TL type),
            // then items must be serialized as boxed.
            Type          itemsType            = vectorSerializer.ItemsType;
            ITLSerializer vectorItemSerializer = context.Rig.GetSerializerByObjectType(itemsType);

            if (vectorItemSerializer is ITLMultiConstructorSerializer || itemsType.GetTypeInfo().GetCustomAttribute <TLTypeAttribute>() != null)
            {
                itemsSerializationModeOverride = TLSerializationMode.Boxed;
            }
            else
            {
                // Check for TLVector attribute with items serialization mode override.
                var tlVectorAttribute = propertyInfo.GetCustomAttribute <TLVectorAttribute>();
                if (tlVectorAttribute != null)
                {
                    itemsSerializationModeOverride = tlVectorAttribute.ItemsModeOverride;
                }
            }
            return(itemsSerializationModeOverride);
        }
예제 #2
0
        protected override object ReadBody(TLSerializationContext context)
        {
            object obj = Activator.CreateInstance(_objectType);

            for (int i = 0; i < _properties.Length; i++)
            {
                TLPropertyInfo tlPropertyInfo = _properties[i];
                PropertyInfo   propertyInfo   = tlPropertyInfo.PropertyInfo;

                object propertyValue;

                Type propType = propertyInfo.PropertyType;

                ITLSerializer tlSerializer = context.Rig.GetSerializerByObjectType(propType);

                if (tlSerializer is ITLVectorSerializer)
                {
                    var vectorSerializer = tlSerializer as ITLVectorSerializer;
                    TLSerializationMode?itemsSerializationModeOverride = GetVectorItemsSerializationModeOverride(vectorSerializer, propertyInfo, context);
                    propertyValue = vectorSerializer.Read(context, tlPropertyInfo.SerializationModeOverride, itemsSerializationModeOverride);
                }
                else
                {
                    propertyValue = tlSerializer.Read(context, tlPropertyInfo.SerializationModeOverride);
                }
                tlPropertyInfo.PropertyInfo.SetValue(obj, propertyValue);
            }
            return(obj);
        }
예제 #3
0
        private object ReadBodyInternal(TLSerializationContext context, TLSerializationMode?itemsSerializationModeOverride = null)
        {
            Func <TLSerializationContext, TLSerializationMode?, object> read;

            if (IsItemsTypeObject)
            {
                read = (sc, m) => TLRig.Deserialize <T>(sc, m);
            }
            else
            {
                ITLSerializer serializer = GetSerializer(context);
                read = serializer.Read;
            }

            int length = context.Streamer.ReadInt32();
            var list   = (List <T>)Activator.CreateInstance(SupportedTypeInternal, length);

            for (int i = 0; i < length; i++)
            {
                var item = (T)read(context, itemsSerializationModeOverride);
                list.Add(item);
            }

            return(list);
        }
예제 #4
0
        private void WriteBodyInternal(object obj, TLSerializationContext context, TLSerializationMode?itemsSerializationModeOverride = null)
        {
            Action <object, TLSerializationContext, TLSerializationMode?> write;

            if (IsItemsTypeObject)
            {
                write = TLRig.Serialize;
            }
            else
            {
                ITLSerializer serializer = GetSerializer(context);
                write = serializer.Write;
            }

            var vector = obj as List <T>;

            if (vector == null)
            {
                // TODO: log wrong type.
                throw new InvalidOperationException("This serializer supports only List<> types.");
            }
            int length = vector.Count;

            // Length.
            context.Streamer.WriteInt32(length);

            // Child objects.
            for (int i = 0; i < length; i++)
            {
                write(vector[i], context, itemsSerializationModeOverride);
            }
        }
예제 #5
0
 protected override void WriteBody(object obj, TLSerializationContext context)
 {
     for (int i = 0; i < _serializationAgents.Length; i++)
     {
         ITLPropertySerializationAgent agent = _serializationAgents[i];
         agent.Write(obj, context);
     }
 }
예제 #6
0
 /// <summary>
 ///     Writes a header with constructor number.
 /// </summary>
 /// <param name="context">Serialization context.</param>
 /// <param name="modeOverride">Serialization mode override.</param>
 protected virtual void WriteHeader(TLSerializationContext context, TLSerializationMode? modeOverride = null)
 {
     if ((!modeOverride.HasValue && SerializationMode != TLSerializationMode.Bare) || (modeOverride.HasValue && modeOverride.Value == TLSerializationMode.Boxed))
     {
         // If type is boxed (not bare) then write type constructor number.
         context.Streamer.WriteUInt32(ConstructorNumber);
     }
 }
 protected override void WriteBody(object obj, TLSerializationContext context)
 {
     for (int i = 0; i < _serializationAgents.Length; i++)
     {
         ITLPropertySerializationAgent agent = _serializationAgents[i];
         agent.Write(obj, context);
     }
 }
예제 #8
0
 /// <summary>
 ///     Writes a header with constructor number.
 /// </summary>
 /// <param name="context">Serialization context.</param>
 /// <param name="modeOverride">Serialization mode override.</param>
 protected virtual void WriteHeader(TLSerializationContext context, TLSerializationMode?modeOverride = null)
 {
     if ((!modeOverride.HasValue && SerializationMode != TLSerializationMode.Bare) || (modeOverride.HasValue && modeOverride.Value == TLSerializationMode.Boxed))
     {
         // If type is boxed (not bare) then write type constructor number.
         context.Streamer.WriteUInt32(ConstructorNumber);
     }
 }
예제 #9
0
        protected override void WriteBody(object obj, TLSerializationContext context)
        {
            var        str      = (string)obj;
            TLStreamer streamer = context.Streamer;

            byte[] bytes = Encoding.GetBytes(str);

            streamer.WriteTLBytes(bytes);
        }
예제 #10
0
        protected override void WriteBody(object obj, TLSerializationContext context)
        {
            var str = (string) obj;
            TLStreamer streamer = context.Streamer;

            byte[] bytes = Encoding.GetBytes(str);

            streamer.WriteTLBytes(bytes);
        }
예제 #11
0
        private static ITLSerializer GetSerializer(TLSerializationContext context)
        {
            ITLSerializer serializer = context.Rig.GetSerializer <T>();

            if (serializer == null)
            {
                throw new TLSerializerNotFoundException(string.Format("There is no serializer for a type: '{0}'.", ItemsTypeInternal.FullName));
            }
            return(serializer);
        }
 protected override object ReadBody(TLSerializationContext context)
 {
     object obj = Activator.CreateInstance(_objectType);
     for (int i = 0; i < _serializationAgents.Length; i++)
     {
         ITLPropertySerializationAgent agent = _serializationAgents[i];
         agent.Read(obj, context);
     }
     return obj;
 }
예제 #13
0
        protected override object ReadBody(TLSerializationContext context)
        {
            object obj = Activator.CreateInstance(_objectType);

            for (int i = 0; i < _serializationAgents.Length; i++)
            {
                ITLPropertySerializationAgent agent = _serializationAgents[i];
                agent.Read(obj, context);
            }
            return(obj);
        }
        public void Write(object obj, TLSerializationContext context, TLSerializationMode? modeOverride = null)
        {
            Type objType = obj.GetType();
            ITLSingleConstructorSerializer serializer;
            if (!_serializersTypeIndex.TryGetValue(objType, out serializer))
            {
                throw new NotSupportedException(string.Format("Object type '{0}' is not supported by this serializer.", objType));
            }

            TLRig.Serialize(obj, context, modeOverride);
        }
예제 #15
0
        public void Write(object obj, TLSerializationContext context, TLSerializationMode?modeOverride = null)
        {
            Type objType = obj.GetType();
            ITLSingleConstructorSerializer serializer;

            if (!_serializersTypeIndex.TryGetValue(objType, out serializer))
            {
                throw new NotSupportedException(string.Format("Object type '{0}' is not supported by this serializer.", objType));
            }

            TLRig.Serialize(obj, context, modeOverride);
        }
예제 #16
0
        private object ReadBodyInternal(TLSerializationContext context, TLSerializationMode?itemsSerializationModeOverride = null)
        {
            int length = context.Streamer.ReadInt32();
            var list   = (List <T>)Activator.CreateInstance(SupportedTypeInternal, length);

            for (int i = 0; i < length; i++)
            {
                var item = TLRig.Deserialize <T>(context, itemsSerializationModeOverride);
                list.Add(item);
            }

            return(list);
        }
예제 #17
0
 /// <summary>
 ///     Reads and checks constructor number.
 /// </summary>
 /// <param name="context">Context.</param>
 /// <param name="modeOverride">Mode override.</param>
 /// <exception cref="InvalidTLConstructorNumberException">When actual constructor number is not as expected.</exception>
 protected void ReadAndCheckConstructorNumber(TLSerializationContext context, TLSerializationMode? modeOverride = null)
 {
     if ((!modeOverride.HasValue && SerializationMode != TLSerializationMode.Bare) || (modeOverride.HasValue && modeOverride.Value == TLSerializationMode.Boxed))
     {
         // If type is boxed (not bare) then read type constructor number and check for supporting.
         uint constructorNumber = context.Streamer.ReadUInt32();
         if (constructorNumber != ConstructorNumber)
         {
             throw new InvalidTLConstructorNumberException(string.Format("Invalid TL constructor number. Expected: {0}, actual: {1}.", ConstructorNumber,
                 constructorNumber));
         }
     }
 }
예제 #18
0
 /// <summary>
 ///     Reads and checks constructor number.
 /// </summary>
 /// <param name="context">Context.</param>
 /// <param name="modeOverride">Mode override.</param>
 /// <exception cref="InvalidTLConstructorNumberException">When actual constructor number is not as expected.</exception>
 protected void ReadAndCheckConstructorNumber(TLSerializationContext context, TLSerializationMode?modeOverride = null)
 {
     if ((!modeOverride.HasValue && SerializationMode != TLSerializationMode.Bare) || (modeOverride.HasValue && modeOverride.Value == TLSerializationMode.Boxed))
     {
         // If type is boxed (not bare) then read type constructor number and check for supporting.
         uint constructorNumber = context.Streamer.ReadUInt32();
         if (constructorNumber != ConstructorNumber)
         {
             throw new InvalidTLConstructorNumberException(string.Format("Invalid TL constructor number. Expected: {0}, actual: {1}.", ConstructorNumber,
                                                                         constructorNumber));
         }
     }
 }
예제 #19
0
        protected override object ReadBody(TLSerializationContext context)
        {
            bool hasFlags   = false;
            uint flagsValue = 0;

            object obj = Activator.CreateInstance(_objectType);

            hasFlags = CheckForFlags(obj);

            if (hasFlags)
            {
                var properties = obj.GetType().GetProperties();
                ITLPropertySerializationAgent flagAgent = _serializationAgents[0];
                //deserialize anf read the flags
                flagAgent.Read(obj, context);
                flagsValue = (uint)properties[0].GetValue(obj);
                //convert it to binary
                string binary = Convert.ToString(flagsValue, 2);
                //the length of the binary is the maximum index of flasg in the message,
                //anything greater than this index, is useless and should directly exit
                var maxIndex = binary.Length - 1;
                for (int i = 1; i < _serializationAgents.Length; i++)
                {
                    var currentPropertyInfo = properties[i];
                    var propInfo            = currentPropertyInfo.GetCustomAttribute <TLPropertyAttribute>();
                    //convert the flags to binary
                    if (propInfo.IsFlag)
                    {
                        if (maxIndex < propInfo.Flag)
                        {                        //since the length is smaller than the flag index, it means this flag was not sent in the msg
                            continue;
                        }
                        if (binary[(int)(maxIndex - propInfo.Flag)] == '0')
                        {                        //if the flag is set to zero
                            continue;
                        }
                    }
                    ITLPropertySerializationAgent agent = _serializationAgents[i];
                    agent.Read(obj, context);
                }
            }
            else
            {
                for (int i = 0; i < _serializationAgents.Length; i++)
                {
                    ITLPropertySerializationAgent agent = _serializationAgents[i];
                    agent.Read(obj, context);
                }
            }
            return(obj);
        }
예제 #20
0
        /// <summary>
        ///     Base serializer writes only header with type id. Then calls <see cref="WriteBody" />.
        /// </summary>
        /// <param name="obj">Object to be serialized.</param>
        /// <param name="context">Serialization context.</param>
        /// <param name="modeOverride">Override of default type serialization mode.</param>
        public virtual void Write([NotNull] object obj, TLSerializationContext context, TLSerializationMode?modeOverride = null)
        {
            if (obj == null)
            {
                throw new ArgumentNullException("obj");
            }

            if (obj.GetType() != SupportedType)
            {
                throw new TLSerializationException(string.Format("Expected object of type {0}, actual object type {1}.", SupportedType, obj.GetType()));
            }

            WriteHeader(context, modeOverride);
            WriteBody(obj, context);
        }
예제 #21
0
        /// <summary>
        ///     Base serializer writes only header with type id. Then calls <see cref="WriteBody" />.
        /// </summary>
        /// <param name="obj">Object to be serialized.</param>
        /// <param name="context">Serialization context.</param>
        /// <param name="modeOverride">Override of default type serialization mode.</param>
        public virtual void Write([NotNull] object obj, TLSerializationContext context, TLSerializationMode? modeOverride = null)
        {
            if (obj == null)
            {
                throw new ArgumentNullException("obj");
            }

            if (obj.GetType() != SupportedType)
            {
                throw new TLSerializationException(string.Format("Expected object of type {0}, actual object type {1}.", SupportedType, obj.GetType()));
            }

            WriteHeader(context, modeOverride);
            WriteBody(obj, context);
        }
        public object Read(TLSerializationContext context, TLSerializationMode? modeOverride = null)
        {
            if (modeOverride.HasValue && modeOverride.Value == TLSerializationMode.Bare)
            {
                throw new InvalidOperationException("TLMultiConstructorObjectSerializer doesn't support bare type deserialization.");
            }

            uint constructorNumber = context.Streamer.ReadUInt32();
            ITLSingleConstructorSerializer serializer;
            if (!_serializersConstructorNumberIndex.TryGetValue(constructorNumber, out serializer))
            {
                throw new NotSupportedException(string.Format("Construction number 0x{0:X} is not supported by this serializer.", constructorNumber));
            }

            return serializer.Read(context, TLSerializationMode.Bare);
        }
예제 #23
0
        public object Read(TLSerializationContext context, TLSerializationMode?modeOverride = null)
        {
            if (modeOverride.HasValue && modeOverride.Value == TLSerializationMode.Bare)
            {
                throw new InvalidOperationException("TLMultiConstructorObjectSerializer doesn't support bare type deserialization.");
            }

            uint constructorNumber = context.Streamer.ReadUInt32();
            ITLSingleConstructorSerializer serializer;

            if (!_serializersConstructorNumberIndex.TryGetValue(constructorNumber, out serializer))
            {
                throw new NotSupportedException(string.Format("Construction number 0x{0:X} is not supported by this serializer.", constructorNumber));
            }

            return(serializer.Read(context, TLSerializationMode.Bare));
        }
예제 #24
0
        protected override Message ReadTypedBody(TLSerializationContext context)
        {
            TLStreamer streamer = context.Streamer;

            ulong msgId      = streamer.ReadUInt64();
            uint  seqNo      = streamer.ReadUInt32();
            int   bodyLength = streamer.ReadInt32();

            if (streamer.BytesTillEnd < bodyLength)
            {
                throw new TLSerializationException(String.Format("Body length ({0}) is greated than available to read bytes till end ({1}).", bodyLength,
                                                                 streamer.BytesTillEnd));
            }

            object body = TLRig.Deserialize(context);

            return(new Message(msgId, seqNo, body));
        }
예제 #25
0
        protected override void WriteBody(object obj, TLSerializationContext context)
        {
            bool hasFlags   = false;
            uint flagsValue = 0;

            hasFlags = CheckForFlags(obj);

            if (hasFlags)
            {
                var properties = obj.GetType().GetProperties();
                flagsValue = (uint)properties[0].GetValue(obj);
                string binary = Convert.ToString(flagsValue, 2);

                var maxIndex = binary.Length - 1;
                for (int i = 0; i < _serializationAgents.Length; i++)
                {
                    var currentPropertyInfo = properties[i];
                    var propInfo            = currentPropertyInfo.GetCustomAttribute <TLPropertyAttribute>();
                    //convert the flags to binary
                    if (propInfo.IsFlag)
                    {
                        if (maxIndex < propInfo.Flag)
                        {                        //since the length is smaller than the flag index, it means this flag was not sent in the msg
                            continue;
                        }
                        if (binary[(int)(maxIndex - propInfo.Flag)] == '0')
                        {                        //if the flag is set to zero
                            continue;
                        }
                    }
                    ITLPropertySerializationAgent agent = _serializationAgents[i];
                    agent.Write(obj, context);
                }
            }
            else
            {
                for (int i = 0; i < _serializationAgents.Length; i++)
                {
                    ITLPropertySerializationAgent agent = _serializationAgents[i];
                    agent.Write(obj, context);
                }
            }
        }
예제 #26
0
        public object Read(TLSerializationContext context, TLSerializationMode? modeOverride = null)
        {
            if (modeOverride.HasValue && modeOverride.Value == TLSerializationMode.Bare)
            {
                throw new InvalidOperationException("BooleanSerializer doesn't support bare type serialization.");
            }

            uint constructorNumber = context.Streamer.ReadUInt32();
            if (constructorNumber == TrueConstructorNumber)
            {
                return true;
            }
            if (constructorNumber == FalseConstructorNumber)
            {
                return false;
            }

            throw new InvalidOperationException(string.Format("Invalid boolean value: '{0}', or not supported by current BooleanSerializer.", constructorNumber));
        }
		protected override void WriteBody(object obj, TLSerializationContext context)
		{
			bool hasFlags = false;
			uint flagsValue = 0;

			hasFlags = CheckForFlags(obj);

			if (hasFlags)
			{
				var properties = obj.GetType().GetProperties();
				flagsValue = (uint)properties[0].GetValue(obj);
				string binary = Convert.ToString(flagsValue, 2);

				var maxIndex = binary.Length - 1;
				for (int i = 0; i < _serializationAgents.Length; i++)
				{
					var currentPropertyInfo = properties[i];
					var propInfo = currentPropertyInfo.GetCustomAttribute<TLPropertyAttribute>();
					//convert the flags to binary
					if (propInfo.IsFlag)
					{
						if (maxIndex < propInfo.Flag)
						{//since the length is smaller than the flag index, it means this flag was not sent in the msg
							continue;
						} 
						if (binary[(int)(maxIndex - propInfo.Flag)] == '0')
						{//if the flag is set to zero
							continue;
						}
					}
					ITLPropertySerializationAgent agent = _serializationAgents[i];
					agent.Write(obj, context);
				}
			}
			else
			{
				for (int i = 0; i < _serializationAgents.Length; i++)
				{
					ITLPropertySerializationAgent agent = _serializationAgents[i];
					agent.Write(obj, context);
				}
			}
		}
예제 #28
0
        public object Read(TLSerializationContext context, TLSerializationMode?modeOverride = null)
        {
            if (modeOverride.HasValue && modeOverride.Value == TLSerializationMode.Bare)
            {
                throw new InvalidOperationException("BooleanSerializer doesn't support bare type serialization.");
            }

            uint constructorNumber = context.Streamer.ReadUInt32();

            if (constructorNumber == TrueConstructorNumber)
            {
                return(true);
            }
            if (constructorNumber == FalseConstructorNumber)
            {
                return(false);
            }

            throw new InvalidOperationException(string.Format("Invalid boolean value: '{0}', or not supported by current BooleanSerializer.", constructorNumber));
        }
예제 #29
0
        protected override void WriteBody(object obj, TLSerializationContext context)
        {
            for (int i = 0; i < _properties.Length; i++)
            {
                TLPropertyInfo tlPropertyInfo = _properties[i];
                PropertyInfo   propertyInfo   = tlPropertyInfo.PropertyInfo;

                Type   propType      = propertyInfo.PropertyType;
                object propertyValue = propertyInfo.GetValue(obj);

                ITLSerializer tlSerializer = context.Rig.GetSerializerByObjectType(propType);

                if (tlSerializer is ITLVectorSerializer)
                {
                    var vectorSerializer = tlSerializer as ITLVectorSerializer;
                    TLSerializationMode?itemsSerializationModeOverride = GetVectorItemsSerializationModeOverride(vectorSerializer, propertyInfo, context);
                    vectorSerializer.Write(propertyValue, context, tlPropertyInfo.SerializationModeOverride, itemsSerializationModeOverride);
                }
                else
                {
                    tlSerializer.Write(propertyValue, context, tlPropertyInfo.SerializationModeOverride);
                }
            }
        }
예제 #30
0
        protected override void WriteTypedBody(Message message, TLSerializationContext context)
        {
            TLStreamer streamer = context.Streamer;

            streamer.WriteUInt64(message.MsgId);
            streamer.WriteUInt32(message.Seqno);

            // Skip 4 bytes for a body length.
            streamer.Position += 4;

            long bodyStartPosition = streamer.Position;

            TLRig.Serialize(message.Body, context, TLSerializationMode.Boxed);
            long bodyEndPosition = streamer.Position;

            long bodyLength = bodyEndPosition - bodyStartPosition;

            streamer.Position = bodyStartPosition - 4;

            // Write a body length.
            streamer.WriteInt32((int)bodyLength);

            streamer.Position = bodyEndPosition;
        }
예제 #31
0
 protected override object ReadBody(TLSerializationContext context)
 {
     byte[] bytes = context.Streamer.ReadTLBytes();
     return Encoding.GetString(bytes, 0, bytes.Length);
 }
예제 #32
0
 protected override object ReadBody(TLSerializationContext context)
 {
     return(ReadBodyInternal(context, DefaultItemsSerializationMode));
 }
예제 #33
0
 protected override void WriteBody(object obj, TLSerializationContext context)
 {
     context.Streamer.WriteTLBytes((byte[]) obj);
 }
 protected override void WriteValue(object propertyValue, TLSerializationContext context)
 {
     _serializer.Write(propertyValue, context, TLPropertyInfo.SerializationModeOverride, _itemsSerializationModeOverride);
 }
 protected override void WriteValue(object propertyValue, TLSerializationContext context)
 {
     TLRig.Serialize(propertyValue, context, TLSerializationMode.Boxed);
 }
 protected abstract void WriteValue(object propertyValue, TLSerializationContext context);
 public void Write(object obj, TLSerializationContext context)
 {
     object propertyValue = obj.GetType().GetProperty(_propertyName).GetValue(obj);
     WriteValue(propertyValue, context);
 }
예제 #38
0
 protected override object ReadBody(TLSerializationContext context)
 {
     return context.Streamer.ReadInt256();
 }
		protected override object ReadBody(TLSerializationContext context)
		{
			bool hasFlags = false;
			uint flagsValue = 0;

			object obj = Activator.CreateInstance(_objectType);

			hasFlags = CheckForFlags(obj);

			if (hasFlags)
			{
				var properties = obj.GetType().GetProperties();
				ITLPropertySerializationAgent flagAgent = _serializationAgents[0];
				//deserialize anf read the flags
				flagAgent.Read(obj, context);
				flagsValue = (uint)properties[0].GetValue(obj);
				//convert it to binary
				string binary = Convert.ToString(flagsValue, 2);
				//the length of the binary is the maximum index of flasg in the message,
				//anything greater than this index, is useless and should directly exit
				var maxIndex = binary.Length - 1;
				for (int i = 1; i < _serializationAgents.Length; i++)
				{
					var currentPropertyInfo = properties[i];
					var propInfo = currentPropertyInfo.GetCustomAttribute<TLPropertyAttribute>();
					//convert the flags to binary
					if (propInfo.IsFlag)
					{
						if (maxIndex < propInfo.Flag)
						{//since the length is smaller than the flag index, it means this flag was not sent in the msg
							continue;
						} 
						if (binary[(int)(maxIndex - propInfo.Flag)] == '0')
						{//if the flag is set to zero
							continue;
						}
					}
					ITLPropertySerializationAgent agent = _serializationAgents[i];
					agent.Read(obj, context);
				}
			}
			else
			{
				for (int i = 0; i < _serializationAgents.Length; i++)
				{
					ITLPropertySerializationAgent agent = _serializationAgents[i];
					agent.Read(obj, context);
				}
			}
			return obj;
		}
예제 #40
0
 public void Write(object obj, TLSerializationContext context, TLSerializationMode? modeOverride = null)
 {
     var value = (bool) obj;
     context.Streamer.WriteUInt32(value ? TrueConstructorNumber : FalseConstructorNumber);
 }
예제 #41
0
 protected override object ReadBody(TLSerializationContext context)
 {
     return(context.Streamer.ReadInt256());
 }
예제 #42
0
 /// <summary>
 ///     Write a body.
 /// </summary>
 /// <param name="obj">Object to be serialized.</param>
 /// <param name="context">Serialization context.</param>
 protected abstract void WriteBody(object obj, TLSerializationContext context);
예제 #43
0
 protected override void WriteBody(object obj, TLSerializationContext context)
 {
     WriteBodyInternal(obj, context, DefaultItemsSerializationMode);
 }
예제 #44
0
 protected override void WriteBody(object obj, TLSerializationContext context)
 {
     context.Streamer.WriteDouble((double) obj);
 }
예제 #45
0
 /// <summary>
 ///     Reads a body.
 /// </summary>
 /// <param name="context">Serialization context.</param>
 /// <returns>Body of an object.</returns>
 protected abstract object ReadBody(TLSerializationContext context);
예제 #46
0
 protected override void WriteBody(object obj, TLSerializationContext context)
 {
     context.Streamer.WriteInt256((Int256) obj);
 }
예제 #47
0
 /// <summary>
 ///     Base serializer writes only header with type id. Then calls <see cref="WriteBody" />.
 /// </summary>
 /// <param name="obj">Object to be serialized.</param>
 /// <param name="context">Serialization context.</param>
 /// <param name="modeOverride">Override of default type serialization mode.</param>
 public virtual void Write(object obj, TLSerializationContext context, TLSerializationMode?modeOverride = null)
 {
     WriteHeader(context, modeOverride);
     WriteBody(obj, context);
 }
 public void Read(object obj, TLSerializationContext context)
 {
     object value = ReadValue(context);
     obj.GetType().GetProperty(_propertyName).SetValue(obj, value);
 }
예제 #49
0
 public virtual object Read(TLSerializationContext context, TLSerializationMode?modeOverride = null)
 {
     ReadAndCheckConstructorNumber(context, modeOverride);
     return(ReadBody(context));
 }
 protected abstract object ReadValue(TLSerializationContext context);
예제 #51
0
 public void Write(object vector, TLSerializationContext context, TLSerializationMode?modeOverride, TLSerializationMode?itemsModeOverride)
 {
     WriteHeader(context, modeOverride);
     WriteBodyInternal(vector, context, itemsModeOverride);
 }
 protected override object ReadValue(TLSerializationContext context)
 {
     return TLRig.Deserialize<object>(context, TLSerializationMode.Boxed);
 }
예제 #53
0
 protected override void WriteBody(object obj, TLSerializationContext context)
 {
     context.Streamer.WriteUInt64((ulong) obj);
 }
 protected override object ReadValue(TLSerializationContext context)
 {
     return _serializer.Read(context, TLPropertyInfo.SerializationModeOverride, _itemsSerializationModeOverride);
 }
예제 #55
0
 /// <summary>
 ///     Reads a body.
 /// </summary>
 /// <param name="context">Serialization context.</param>
 /// <returns>Body of an object.</returns>
 protected abstract object ReadBody(TLSerializationContext context);
예제 #56
0
 /// <summary>
 ///     Write a body.
 /// </summary>
 /// <param name="obj">Object to be serialized.</param>
 /// <param name="context">Serialization context.</param>
 protected abstract void WriteBody(object obj, TLSerializationContext context);
예제 #57
0
 public object Read(TLSerializationContext context, TLSerializationMode?modeOverride, TLSerializationMode?itemsModeOverride)
 {
     ReadAndCheckConstructorNumber(context, modeOverride);
     return(ReadBodyInternal(context, itemsModeOverride));
 }
예제 #58
0
 protected override void WriteBody(object obj, TLSerializationContext context)
 {
     context.Streamer.WriteInt256((Int256)obj);
 }
예제 #59
0
 public virtual object Read(TLSerializationContext context, TLSerializationMode? modeOverride = null)
 {
     ReadAndCheckConstructorNumber(context, modeOverride);
     return ReadBody(context);
 }