// Token: 0x0600037D RID: 893 RVA: 0x00013144 File Offset: 0x00011344
        protected internal override object Deserialize(int key, object value, ProtoReader source)
        {
            IProtoSerializer serializer = ((MetaType)this.types[key]).Serializer;

            if (value == null && Helpers.IsValueType(serializer.ExpectedType))
            {
                if (serializer.RequiresOldValue)
                {
                    value = Activator.CreateInstance(serializer.ExpectedType);
                }
                return(serializer.Read(value, source));
            }
            return(serializer.Read(value, source));
        }
Пример #2
0
        /// <summary>
        /// Applies a protocol-buffer stream to an existing instance (which may be null).
        /// </summary>
        /// <param name="key">Represents the type (including inheritance) to consider.</param>
        /// <param name="value">The existing instance to be modified (can be null).</param>
        /// <param name="source">The binary stream to apply to the instance (cannot be null).</param>
        /// <returns>The updated instance; this may be different to the instance argument if
        /// either the original instance was null, or the stream defines a known sub-type of the
        /// original instance.</returns>
        protected internal override object Deserialize(int key, object value, ProtoReader source)
        {
            //Helpers.DebugWriteLine("Deserialize", value);
            IProtoSerializer ser = ((MetaType)types[key]).Serializer;

            if (value == null && ser.ExpectedType.IsValueType)
            {
                return(ser.Read(Activator.CreateInstance(ser.ExpectedType), source));
            }
            else
            {
                return(ser.Read(value, source));
            }
        }
Пример #3
0
        public override object Read(ProtoReader source, ref ProtoReader.State state, object value)
        {
            TDictionary typed = (AppendToCollection ? ((TDictionary)value) : null)
                                ?? (TDictionary)Activator.CreateInstance(concreteType);

            do
            {
                var          key        = DefaultKey;
                var          typedValue = DefaultValue;
                SubItemToken token      = ProtoReader.StartSubItem(source, ref state);
                int          field;
                while ((field = source.ReadFieldHeader(ref state)) > 0)
                {
                    switch (field)
                    {
                    case 1:
                        key = (TKey)keyTail.Read(source, ref state, null);
                        break;

                    case 2:
                        typedValue = (TValue)Tail.Read(source, ref state, Tail.RequiresOldValue ? (object)typedValue : null);
                        break;

                    default:
                        source.SkipField(ref state);
                        break;
                    }
                }

                ProtoReader.EndSubItem(token, source, ref state);
                typed[key] = typedValue;
            } while (source.TryReadFieldHeader(ref state, fieldNumber));

            return(typed);
        }
Пример #4
0
        public override object Read(object untyped, ProtoReader source)
        {
            TDictionary typed = AppendToCollection ? ((TDictionary)untyped) : null;

            //if (typed == null) typed = (TDictionary)Activator.CreateInstance(concreteType);
            if (typed == null)
            {
                typed = (TDictionary)ActivatorUtils.FastCreateInstance(concreteType);
            }

            do
            {
                var          key   = DefaultKey;
                var          value = DefaultValue;
                SubItemToken token = ProtoReader.StartSubItem(source);
                int          field;
                while ((field = source.ReadFieldHeader()) > 0)
                {
                    switch (field)
                    {
                    case 1:
                        key = (TKey)keyTail.Read(null, source);
                        break;

                    case 2:
                        value = (TValue)Tail.Read(Tail.RequiresOldValue ? (object)value : null, source);
                        break;

                    default:
                        source.SkipField();
                        break;
                    }
                }

                ProtoReader.EndSubItem(token, source);
                typed[key] = value;
            } while (source.TryReadFieldHeader(fieldNumber));

            return(typed);
        }
Пример #5
0
        public object Read(object value, ProtoReader source)
        {
            if (isRootType && value != null)
            {
                Callback(value, TypeModel.CallbackType.BeforeDeserialize, source.Context);
            }
            int  fieldNumber, lastFieldNumber = 0, lastFieldIndex = 0;
            bool fieldHandled;

            //Helpers.DebugWriteLine(">> Reading fields for " + forType.FullName);
            while ((fieldNumber = source.ReadFieldHeader()) > 0)
            {
                fieldHandled = false;
                if (fieldNumber < lastFieldNumber)
                {
                    lastFieldNumber = lastFieldIndex = 0;
                }
                for (int i = lastFieldIndex; i < fieldNumbers.Length; i++)
                {
                    if (fieldNumbers[i] == fieldNumber)
                    {
                        IProtoSerializer ser = serializers[i];
                        //Helpers.DebugWriteLine(": " + ser.ToString());
                        Type serType = ser.ExpectedType;
                        if (value == null)
                        {
                            if (serType == forType)
                            {
                                value = CreateInstance(source, true);
                            }
                        }
                        else
                        {
                            if (serType != forType && ((IProtoTypeSerializer)ser).CanCreateInstance() &&
                                serType
#if WINRT
                                .GetTypeInfo()
#endif
                                .IsSubclassOf(value.GetType()))
                            {
                                value = ProtoReader.Merge(source, value, ((IProtoTypeSerializer)ser).CreateInstance(source));
                            }
                        }

                        if (ser.ReturnsValue)
                        {
                            value = ser.Read(value, source);
                        }
                        else
                        { // pop
                            ser.Read(value, source);
                        }

                        lastFieldIndex  = i;
                        lastFieldNumber = fieldNumber;
                        fieldHandled    = true;
                        break;
                    }
                }
                if (!fieldHandled)
                {
                    //Helpers.DebugWriteLine(": [" + fieldNumber + "] (unknown)");
                    if (value == null)
                    {
                        value = CreateInstance(source, true);
                    }
                    if (isExtensible)
                    {
                        source.AppendExtensionData((IExtensible)value);
                    }
                    else
                    {
                        source.SkipField();
                    }
                }
            }
            //Helpers.DebugWriteLine("<< Reading fields for " + forType.FullName);
            if (value == null)
            {
                value = CreateInstance(source, true);
            }
            if (isRootType)
            {
                Callback(value, TypeModel.CallbackType.AfterDeserialize, source.Context);
            }
            return(value);
        }
Пример #6
0
        public object Read(object value, ProtoReader source)
        {
            if (isRootType && value != null)
            {
                Callback(value, TypeModel.CallbackType.BeforeDeserialize, source.Context);
            }
            int num  = 0;
            int num2 = 0;
            int num3;

            while ((num3 = source.ReadFieldHeader()) > 0)
            {
                bool flag = false;
                if (num3 < num)
                {
                    num = (num2 = 0);
                }
                for (int i = num2; i < fieldNumbers.Length; i++)
                {
                    if (fieldNumbers[i] != num3)
                    {
                        continue;
                    }
                    IProtoSerializer protoSerializer = serializers[i];
                    Type             expectedType    = protoSerializer.ExpectedType;
                    if (value == null)
                    {
                        if (expectedType == forType)
                        {
                            value = CreateInstance(source, includeLocalCallback: true);
                        }
                    }
                    else if (expectedType != forType && ((IProtoTypeSerializer)protoSerializer).CanCreateInstance() && expectedType.IsSubclassOf(value.GetType()))
                    {
                        value = ProtoReader.Merge(source, value, ((IProtoTypeSerializer)protoSerializer).CreateInstance(source));
                    }
                    if (protoSerializer.ReturnsValue)
                    {
                        value = protoSerializer.Read(value, source);
                    }
                    else
                    {
                        protoSerializer.Read(value, source);
                    }
                    num2 = i;
                    num  = num3;
                    flag = true;
                    break;
                }
                if (!flag)
                {
                    if (value == null)
                    {
                        value = CreateInstance(source, includeLocalCallback: true);
                    }
                    if (isExtensible)
                    {
                        source.AppendExtensionData((IExtensible)value);
                    }
                    else
                    {
                        source.SkipField();
                    }
                }
            }
            if (value == null)
            {
                value = CreateInstance(source, includeLocalCallback: true);
            }
            if (isRootType)
            {
                Callback(value, TypeModel.CallbackType.AfterDeserialize, source.Context);
            }
            return(value);
        }
Пример #7
0
        public object Read(object value, ProtoReader source)
        {
            int num;

            if (this.isRootType && (value != null))
            {
                this.Callback(value, TypeModel.CallbackType.BeforeDeserialize, source.Context);
            }
            int num2 = 0;
            int num3 = 0;

            while ((num = source.ReadFieldHeader()) > 0)
            {
                bool flag = false;
                if (num < num2)
                {
                    num2 = num3 = 0;
                }
                for (int i = num3; i < this.fieldNumbers.Length; i++)
                {
                    if (this.fieldNumbers[i] == num)
                    {
                        IProtoSerializer serializer   = this.serializers[i];
                        Type             expectedType = serializer.ExpectedType;
                        if (value == null)
                        {
                            if (expectedType == this.forType)
                            {
                                value = this.CreateInstance(source, true);
                            }
                        }
                        else if (((expectedType != this.forType) && ((IProtoTypeSerializer)serializer).CanCreateInstance()) && expectedType.IsSubclassOf(value.GetType()))
                        {
                            value = ProtoReader.Merge(source, value, ((IProtoTypeSerializer)serializer).CreateInstance(source));
                        }
                        if (serializer.ReturnsValue)
                        {
                            value = serializer.Read(value, source);
                        }
                        else
                        {
                            serializer.Read(value, source);
                        }
                        num3 = i;
                        num2 = num;
                        flag = true;
                        break;
                    }
                }
                if (!flag)
                {
                    if (value == null)
                    {
                        value = this.CreateInstance(source, true);
                    }
                    if (this.isExtensible)
                    {
                        source.AppendExtensionData((IExtensible)value);
                        continue;
                    }
                    source.SkipField();
                }
            }
            if (value == null)
            {
                value = this.CreateInstance(source, true);
            }
            if (this.isRootType)
            {
                this.Callback(value, TypeModel.CallbackType.AfterDeserialize, source.Context);
            }
            return(value);
        }
Пример #8
0
        public object Read(object value, ProtoReader source)
        {
            var token = ProtoReader.StartSubItem(source);

            if (_isRootType && value != null)
            {
                Callback(value, TypeModel.CallbackType.BeforeDeserialize, source.Context);
            }
            int fieldNumber, lastFieldNumber = 0, lastFieldIndex = 0;

            //Helpers.DebugWriteLine(">> Reading fields for " + forType.FullName);
            while ((fieldNumber = source.ReadFieldHeader()) > 0)
            {
                bool fieldHandled = false;
                if (fieldNumber < lastFieldNumber)
                {
                    lastFieldNumber = lastFieldIndex = 0;
                }
                for (int i = lastFieldIndex; i < _fieldNumbers.Length; i++)
                {
                    if (_fieldNumbers[i] == fieldNumber)
                    {
                        IProtoSerializer ser = _serializers[i];
                        //Helpers.DebugWriteLine(": " + ser.ToString());
                        Type serType = ser.ExpectedType;
                        if (value == null || !Helpers.IsInstanceOfType(ExpectedType, value))
                        {
                            if (serType == ExpectedType && CanCreateInstance)
                            {
                                value = CreateInstance(source, true);
                            }
                        }
                        value = ser.Read(value, source);

                        lastFieldIndex  = i;
                        lastFieldNumber = fieldNumber;
                        fieldHandled    = true;
                        break;
                    }
                }
                if (!fieldHandled)
                {
                    //Helpers.DebugWriteLine(": [" + fieldNumber + "] (unknown)");
                    if (value == null)
                    {
                        value = CreateInstance(source, true);
                    }
                    if (_isExtensible)
                    {
                        source.AppendExtensionData((IExtensible)value);
                    }
                    else
                    {
                        source.SkipField();
                    }
                }
            }
            //Helpers.DebugWriteLine("<< Reading fields for " + forType.FullName);
            if (value == null)
            {
                value = CreateInstance(source, true);
            }
            if (_isRootType)
            {
                Callback(value, TypeModel.CallbackType.AfterDeserialize, source.Context);
            }
            ProtoReader.EndSubItem(token, source);
            return(value);
        }
Пример #9
0
        public object Read(object value, ProtoReader source)
        {
            if (this.isRootType && value != null)
            {
                this.Callback(value, TypeModel.CallbackType.BeforeDeserialize, source.Context);
            }
            int num  = 0;
            int num1 = 0;

            while (true)
            {
                int num2 = source.ReadFieldHeader();
                int num3 = num2;
                if (num2 <= 0)
                {
                    break;
                }
                bool flag = false;
                if (num3 < num)
                {
                    int num4 = 0;
                    num1 = num4;
                    num  = num4;
                }
                int num5 = num1;
                while (num5 < (int)this.fieldNumbers.Length)
                {
                    if (this.fieldNumbers[num5] != num3)
                    {
                        num5++;
                    }
                    else
                    {
                        IProtoSerializer protoSerializer = this.serializers[num5];
                        Type             expectedType    = protoSerializer.ExpectedType;
                        if (value == null)
                        {
                            if (expectedType == this.forType)
                            {
                                value = this.CreateInstance(source, true);
                            }
                        }
                        else if (expectedType != this.forType && ((IProtoTypeSerializer)protoSerializer).CanCreateInstance() && expectedType.IsSubclassOf(value.GetType()))
                        {
                            value = ProtoReader.Merge(source, value, ((IProtoTypeSerializer)protoSerializer).CreateInstance(source));
                        }
                        if (!protoSerializer.ReturnsValue)
                        {
                            protoSerializer.Read(value, source);
                        }
                        else
                        {
                            value = protoSerializer.Read(value, source);
                        }
                        num1 = num5;
                        num  = num3;
                        flag = true;
                        break;
                    }
                }
                if (!flag)
                {
                    if (value == null)
                    {
                        value = this.CreateInstance(source, true);
                    }
                    if (!this.isExtensible)
                    {
                        source.SkipField();
                    }
                    else
                    {
                        source.AppendExtensionData((IExtensible)value);
                    }
                }
            }
            if (value == null)
            {
                value = this.CreateInstance(source, true);
            }
            if (this.isRootType)
            {
                this.Callback(value, TypeModel.CallbackType.AfterDeserialize, source.Context);
            }
            return(value);
        }