示例#1
0
        /// <summary>
        ///     Deserialize an object from TL serialization context.
        /// </summary>
        /// <remarks>
        ///     Constructor number for the object is automatically determined by reading the first number from the streamer,
        ///     hence object within the context streamer must be serialized as boxed type.
        /// </remarks>
        /// <param name="context">TL serialization context.</param>
        /// <returns>Deserialized object.</returns>
        /// <exception cref="TLSerializerNotFoundException">When serializer not found.</exception>
        public static object Deserialize(TLSerializationContext context)
        {
            // Here streamer's position must point to a boxed TL type.
            TLStreamer streamer = context.Streamer;

            // Read a constructor number and restore the streamer position.
            streamer.PushPosition();
            uint constructorNumber = streamer.ReadUInt32();

            //Console.WriteLine("Retrived constructor number " + constructorNumber);
            streamer.PopPosition();

            ITLSerializer serializer = context.Rig.GetSerializerByConstructorNumber(constructorNumber);



            //Console.WriteLine("Got serializer for above constructor number" + serializer.SupportedType);



            if (serializer == null)
            {
                throw new TLSerializerNotFoundException(
                          string.Format("Constructor number: 0x{0:X8} is not supported by any registered serializer.", constructorNumber));
            }

            return(serializer.Read(context, TLSerializationMode.Boxed));
        }
示例#2
0
文件: TLRig.cs 项目: andri-ys/SharpTL
        /// <summary>
        ///     Serialize an object.
        /// </summary>
        /// <param name="obj">The object.</param>
        /// <param name="context">TL serialization context.</param>
        /// <param name="modeOverride">Serialization mode override.</param>
        /// <exception cref="TLSerializerNotFoundException">When serializer not found.</exception>
        public static void Serialize(object obj, TLSerializationContext context, TLSerializationMode?modeOverride = null)
        {
            var           objType    = obj.GetType();
            ITLSerializer serializer = context.Rig.GetSerializerByObjectType(objType);

            if (serializer == null)
            {
                throw new TLSerializerNotFoundException(string.Format("There is no serializer for a type: '{0}'.", objType.FullName));
            }
            serializer.Write(obj, context, modeOverride);
        }
示例#3
0
        /// <summary>
        ///     Deserialize an object from TL serialization context.
        /// </summary>
        /// <param name="objType">Type of the object.</param>
        /// <param name="context">TL serialization context.</param>
        /// <param name="modeOverride">Serialization mode override.</param>
        /// <returns>Deserialized object.</returns>
        /// <exception cref="TLSerializerNotFoundException">When serializer not found.</exception>
        public static object Deserialize(Type objType, TLSerializationContext context, TLSerializationMode?modeOverride = null)
        {
            if (objType == typeof(object))
            {
                return(Deserialize(context));
            }

            ITLSerializer serializer = context.Rig.GetSerializerByObjectType(objType);

            if (serializer == null)
            {
                throw new TLSerializerNotFoundException(string.Format("There is no serializer for a type: '{0}'.", objType.FullName));
            }
            return(serializer.Read(context, modeOverride));
        }
示例#4
0
文件: TLRig.cs 项目: andri-ys/SharpTL
        /// <summary>
        ///     Deserialize an object from TL serialization context.
        /// </summary>
        /// <remarks>
        ///     Constructor number for the object is automatically determined by reading the first number from the streamer,
        ///     hence object within the context streamer must be serialized as boxed type.
        /// </remarks>
        /// <param name="context">TL serialization context.</param>
        /// <returns>Deserialized object.</returns>
        /// <exception cref="TLSerializerNotFoundException">When serializer not found.</exception>
        public static object Deserialize(TLSerializationContext context)
        {
            TLStreamer streamer = context.Streamer;

            // Read a constructor number.
            uint          constructorNumber = streamer.ReadUInt32();
            ITLSerializer serializer        = context.Rig.GetSerializerByConstructorNumber(constructorNumber);

            if (serializer == null)
            {
                throw new TLSerializerNotFoundException(string.Format("Constructor number: 0x{0:X8} is not supported by any registered serializer.", constructorNumber));
            }

            // Bare because construction number has already been read.
            return(serializer.Read(context, TLSerializationMode.Bare));
        }
示例#5
0
 /// <summary>
 ///     Deserialize an object from TL serialization context.
 /// </summary>
 /// <typeparam name="T">Type of the object.</typeparam>
 /// <param name="context">TL serialization context.</param>
 /// <param name="modeOverride">Serialization mode override.</param>
 /// <returns>Deserialized object.</returns>
 public static T Deserialize <T>(TLSerializationContext context, TLSerializationMode?modeOverride = null)
 {
     return((T)Deserialize(typeof(T), context, modeOverride));
 }