/// <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; }
/// <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; }
/// <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); } }
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; }
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); }
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; }
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; }
/// <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); }
/// <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)); } } }
/// <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); }
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)); }
/// <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; }
public virtual object Read(TLSerializationContext context, TLSerializationMode? modeOverride = null) { ReadAndCheckConstructorNumber(context, modeOverride); return ReadBody(context); }
public void Write(object obj, TLSerializationContext context, TLSerializationMode? modeOverride = null) { var value = (bool) obj; context.Streamer.WriteUInt32(value ? TrueConstructorNumber : FalseConstructorNumber); }
/// <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; }
/// <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; }
public TLVectorPropertySerializationAgent(TLPropertyInfo tlPropertyInfo, ITLVectorSerializer serializer, TLSerializationMode? itemsSerializationModeOverride) : base(tlPropertyInfo) { _serializer = serializer; _itemsSerializationModeOverride = itemsSerializationModeOverride; }