コード例 #1
0
		/// <summary>
		///     Initializes a new instance of the <see cref="TLPropertyAttribute" /> class.
		/// </summary>
		/// <param name="order">Order in constructor.</param>
		/// <param name="serializationModeOverride">Serialization mode override.</param>
		public TLPropertyAttribute(uint order,uint flag, bool isFlag, TLSerializationMode serializationModeOverride)
		{
			Order = order;
			Flag = flag;
			IsFlag = true;
			SerializationModeOverride = serializationModeOverride;
		}
コード例 #2
0
 /// <summary>
 ///     Initializes a new instance of the <see cref="TLPropertyAttribute" /> class.
 /// </summary>
 /// <param name="order">Order in constructor.</param>
 /// <param name="serializationModeOverride">Serialization mode override.</param>
 public TLPropertyAttribute(uint order, uint flag, bool isFlag, TLSerializationMode serializationModeOverride)
 {
     Order  = order;
     Flag   = flag;
     IsFlag = true;
     SerializationModeOverride = serializationModeOverride;
 }
コード例 #3
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);
     }
 }
コード例 #4
0
 public TLCustomObjectSerializer(uint constructorNumber, Type objectType, IEnumerable <TLPropertyInfo> properties,
                                 TLSerializationMode serializationMode = TLSerializationMode.Boxed)
 {
     _constructorNumber = constructorNumber;
     _objectType        = objectType;
     _properties        = properties.OrderBy(info => info.Order).ToArray();
     SerializationMode  = serializationMode;
 }
コード例 #5
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);
        }
コード例 #6
0
 public TLCustomObjectSerializer(
     uint constructorNumber,
     Type objectType,
     IEnumerable<TLPropertyInfo> properties,
     TLSerializersBucket serializersBucket,
     TLSerializationMode serializationMode = TLSerializationMode.Boxed)
     : base(constructorNumber)
 {
     _objectType = objectType;
     _serializationAgents = CreateSerializationAgents(properties, serializersBucket);
     SerializationMode = serializationMode;
 }
コード例 #7
0
 public TLCustomObjectSerializer(
     uint constructorNumber,
     Type objectType,
     IEnumerable <TLPropertyInfo> properties,
     TLSerializersBucket serializersBucket,
     TLSerializationMode serializationMode = TLSerializationMode.Boxed)
     : base(constructorNumber)
 {
     _objectType          = objectType;
     _serializationAgents = CreateSerializationAgents(properties, serializersBucket);
     SerializationMode    = serializationMode;
 }
コード例 #8
0
        /// <summary>
        ///     Initializes a new instance of the <see cref="TLPropertyInfo" /> class.
        /// </summary>
        /// <param name="order">Order in constructor.</param>
        /// <param name="propertyInfo">Property info.</param>
        /// <param name="serializationModeOverride">Serialization mode override.</param>
		public TLPropertyInfo(uint order, uint flag, bool isFlag, PropertyInfo propertyInfo, TLSerializationMode? serializationModeOverride = null)
        {
			//Console.WriteLine("##### new before TLProperty info propertyInfo  " +  propertyInfo + " flags " + isFlag);
            Order = order;
            PropertyInfo = propertyInfo;
			if (isFlag) {
				IsFlag = true;
				Flag = flag;
			}
            SerializationModeOverride = serializationModeOverride;
			//Console.WriteLine("##### new TLProperty info propertyInfo  " +  propertyInfo + " flags " + IsFlag);
        }
コード例 #9
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));
         }
     }
 }
コード例 #10
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);
        }
コード例 #11
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);
        }
コード例 #12
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));
        }
コード例 #13
0
 /// <summary>
 ///     Initializes a new instance of the <see cref="TLPropertyAttribute" /> class.
 /// </summary>
 /// <param name="order">Order in constructor.</param>
 /// <param name="serializationModeOverride">Serialization mode override.</param>
 public TLPropertyAttribute(uint order, TLSerializationMode serializationModeOverride)
 {
     Order = order;
     SerializationModeOverride = serializationModeOverride;
 }
コード例 #14
0
 public virtual object Read(TLSerializationContext context, TLSerializationMode? modeOverride = null)
 {
     ReadAndCheckConstructorNumber(context, modeOverride);
     return ReadBody(context);
 }
コード例 #15
0
 public void Write(object obj, TLSerializationContext context, TLSerializationMode? modeOverride = null)
 {
     var value = (bool) obj;
     context.Streamer.WriteUInt32(value ? TrueConstructorNumber : FalseConstructorNumber);
 }
コード例 #16
0
 /// <summary>
 ///     Initializes a new instance of the <see cref="TLPropertyInfo" /> class.
 /// </summary>
 /// <param name="order">Order in constructor.</param>
 /// <param name="propertyInfo">Property info.</param>
 /// <param name="serializationModeOverride">Serialization mode override.</param>
 public TLPropertyInfo(uint order, PropertyInfo propertyInfo, TLSerializationMode? serializationModeOverride = null)
 {
     Order = order;
     PropertyInfo = propertyInfo;
     SerializationModeOverride = serializationModeOverride;
 }
コード例 #17
0
 /// <summary>
 ///     Initializes a new instance of the <see cref="TLPropertyAttribute" /> class.
 /// </summary>
 /// <param name="order">Order in constructor.</param>
 /// <param name="serializationModeOverride">Serialization mode override.</param>
 public TLPropertyAttribute(uint order, TLSerializationMode serializationModeOverride)
 {
     Order = order;
     SerializationModeOverride = serializationModeOverride;
 }
コード例 #18
0
 /// <summary>
 ///     Initializes a new instance of the <see cref="TLVectorAttribute" /> class.
 /// </summary>
 /// <param name="itemsModeOverride">Vector items serialization mode override.</param>
 public TLVectorAttribute(TLSerializationMode itemsModeOverride)
 {
     ItemsModeOverride = itemsModeOverride;
 }
コード例 #19
0
 public TLVectorPropertySerializationAgent(TLPropertyInfo tlPropertyInfo, ITLVectorSerializer serializer, TLSerializationMode? itemsSerializationModeOverride)
     : base(tlPropertyInfo)
 {
     _serializer = serializer;
     _itemsSerializationModeOverride = itemsSerializationModeOverride;
 }
コード例 #20
0
 /// <summary>
 ///     Initializes a new instance of the <see cref="TLVectorAttribute" /> class.
 /// </summary>
 /// <param name="itemsModeOverride">Vector items serialization mode override.</param>
 public TLVectorAttribute(TLSerializationMode itemsModeOverride)
 {
     ItemsModeOverride = itemsModeOverride;
 }