コード例 #1
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);
     }
 }
コード例 #2
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);
        }
コード例 #3
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);
        }
コード例 #4
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);
                }
            }
        }