private static Product Read(Product product1, ProtoReader reader1)
        {
            int num;

            while ((num = reader1.ReadFieldHeader()) > 0)
            {
                switch (num)
                {
                case 1:
                    if (product1 == null)
                    {
                        product1 = new Product();
                    }
                    product1.ProductID = reader1.ReadInt32();
                    continue;

                case 2:
                    if (product1 == null)
                    {
                        product1 = new Product();
                    }
                    product1.ProductName = reader1.ReadString();
                    continue;

                case 3:
                    if (product1 == null)
                    {
                        product1 = new Product();
                    }
                    product1.SupplierID = new int?(reader1.ReadInt32());
                    continue;
                }
            }
            return(product1);
        }
        public object Read(object value, ProtoReader source)
        {
            UnityEngine.LayerMask data = (UnityEngine.LayerMask)value;

            int fieldNumber = 0;

            SubItemToken token = ProtoReader.StartSubItem(source);

            while ((fieldNumber = source.ReadFieldHeader()) != 0)
            {
                switch (fieldNumber)
                {
                case 1:
                    data.value = source.ReadInt32();
                    break;

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

            ProtoReader.EndSubItem(token, source);

            return(data);
        }
        /// <summary>
        /// Parses a TimeSpan from a protobuf stream using the standardized format, google.protobuf.Duration
        /// </summary>
        public static TimeSpan ReadDuration(ProtoReader source)
        {
            long         seconds = 0;
            int          nanos   = 0;
            SubItemToken token   = ProtoReader.StartSubItem(source);
            int          fieldNumber;

            while ((fieldNumber = source.ReadFieldHeader()) > 0)
            {
                switch (fieldNumber)
                {
                case 1:
                    seconds = source.ReadInt64();
                    break;

                case 2:
                    nanos = source.ReadInt32();
                    break;

                default:
                    source.SkipField();
                    break;
                }
            }
            ProtoReader.EndSubItem(token, source);
            return(FromDurationSeconds(seconds, nanos));
        }
Esempio n. 4
0
        public object Read(object value, ProtoReader source)

        {
            Helpers.DebugAssert(value == null); // since replaces

            return(source.ReadInt32());
        }
Esempio n. 5
0
        public object Read(object value, ProtoReader source)
        {
            Helpers.DebugAssert(value == null); // since replaces
            int wireValue = source.ReadInt32();

            if (map == null)
            {
                return(WireToEnum(wireValue));
            }
            for (int i = 0; i < map.Length; i++)
            {
                if (map[i].WireValue == wireValue)
                {
                    return(map[i].TypedValue);
                }
            }
            //针对找不到的本地没有的枚举,转成一个小或等于0的默认值
            for (int i = 0; i < map.Length; i++)
            {
                if (map[i].WireValue <= 0)
                {
                    UnityEngine.Debug.LogError("找不到" + wireValue + "|对应的枚举,因此转换成默认值" + map[i].TypedValue.GetType() + "." + map[i].TypedValue);
                    return(map[i].TypedValue);
                }
            }
            source.ThrowEnumException(ExpectedType, wireValue);
            return(null); // to make compiler happy
        }
Esempio n. 6
0
        MetaType TryRead(MetaType metaType, ProtoReader source, int recursionLevel)
        {
            SubType[] subTypes = metaType.GetSubtypes();
            int       fieldNumber;
            SubType   subType;

            if (recursionLevel == 0)
            {
                if (source.WireType != WireType.String)
                {
                    fieldNumber = source.ReadInt32() - 1;
                    subType     = subTypes.FirstOrDefault(st => st.FieldNumber == fieldNumber);
                    return(subType?.DerivedType ?? metaType); // versioning
                }
            }
            SubItemToken?token = null;

            if (recursionLevel == 0)
            {
                token = ProtoReader.StartSubItem(source);
            }

            try
            {
                if (!ProtoReader.HasSubValue(WireType.Variant, source))
                {
                    return(metaType);
                }

                fieldNumber = source.ReadInt32() - 1;
                subType     = subTypes.FirstOrDefault(st => st.FieldNumber == fieldNumber);
                return(subType != null // versioning
                            ? TryRead(subType.DerivedType, source, recursionLevel + 1)
                            : metaType);
            }
            finally
            {
                if (token != null)
                {
                    ProtoReader.EndSubItem(token.Value, true, source);
                }
            }
        }
        public object Read(object value, ProtoReader source)
        {
            UnityEngine.AnimationCurve data = (UnityEngine.AnimationCurve)
                                                  (value == null ? CreateInstance(source) : value);

            int fieldNumber = 0;

            SubItemToken token = ProtoReader.StartSubItem(source);

            while ((fieldNumber = source.ReadFieldHeader()) != 0)
            {
                switch (fieldNumber)
                {
                case 1:
                    data.preWrapMode = (UnityEngine.WrapMode)source.ReadInt32();
                    break;

                case 2:
                    data.postWrapMode = (UnityEngine.WrapMode)source.ReadInt32();
                    break;

                case 3:
                    keys.Clear();
                    do
                    {
                        keys.Add((UnityEngine.Keyframe) this.keyframeSerializer.Read(
                                     new UnityEngine.Keyframe(), source));
                    } while (source.TryReadFieldHeader(3));
                    data.keys = keys.ToArray();
                    break;

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

            ProtoReader.EndSubItem(token, source);

            return(data);
        }
        private static void Merge(ProtoReader reader, ref ProtoReader.State state, ref protogen.OrderLine obj)
        {
            int field;

            if (obj == null)
            {
                obj = new protogen.OrderLine();
            }
            while ((field = reader.ReadFieldHeader(ref state)) != 0)
            {
                switch (field)
                {
                case 1:
                    obj.OrderID = reader.ReadInt32(ref state);
                    break;

                case 2:
                    obj.ProductID = reader.ReadInt32(ref state);
                    break;

                case 3:
                    obj.UnitPrice = reader.ReadDouble(ref state);
                    break;

                case 4:
                    reader.Hint(WireType.SignedVariant);
                    obj.Quantity = reader.ReadInt32(ref state);
                    break;

                case 5:
                    obj.Discount = reader.ReadSingle(ref state);
                    break;

                default:
                    reader.AppendExtensionData(ref state, obj);
                    break;
                }
            }
        }
Esempio n. 9
0
            public void ShouldSerializeDecimalColumnType()
            {
                // Arrange
                var dataReader = this.CreateDataReader(42m);

                // Act
                var reader = new ProtoReader(this.Serialize(dataReader), null, null);

                // Assert
                var readerContext = new ProtoReaderContext(reader);

                readerContext.ReadUntilColumnType();

                Assert.Equal(12, reader.ReadInt32());
            }
Esempio n. 10
0
            public void ShouldSerializeDateTimeColumnType()
            {
                // Arrange
                var dataReader = this.CreateDataReader(new DateTime(1969, 10, 29, 22, 30, 0));

                // Act
                var reader = new ProtoReader(this.Serialize(dataReader), null, null);

                // Assert
                var readerContext = new ProtoReaderContext(reader);

                readerContext.ReadUntilColumnType();

                Assert.Equal(2, reader.ReadInt32());
            }
Esempio n. 11
0
            public void ShouldSerializeTimeSpanColumnType()
            {
                // Arrange
                var dataReader = this.CreateDataReader(TimeSpan.FromTicks(1));

                // Act
                var reader = new ProtoReader(this.Serialize(dataReader), null, null);

                // Assert
                var readerContext = new ProtoReaderContext(reader);

                readerContext.ReadUntilColumnType();

                Assert.Equal(15, reader.ReadInt32());
            }
Esempio n. 12
0
            public void ShouldSerializeCharArrayColumnType()
            {
                // Arrange
                var dataReader = this.CreateDataReader(new[] { 'f', 'o', 'o' });

                // Act
                var reader = new ProtoReader(this.Serialize(dataReader), null, null);

                // Assert
                var readerContext = new ProtoReaderContext(reader);

                readerContext.ReadUntilColumnType();

                Assert.Equal(14, reader.ReadInt32());
            }
Esempio n. 13
0
 public object Read(object value, ProtoReader source)
 {
     Helpers.DebugAssert(value == null); // since replaces
     int wireValue = source.ReadInt32();
     if(map == null) {
         return WireToEnum(wireValue);
     }
     for(int i = 0 ; i < map.Length ; i++) {
         if(map[i].WireValue == wireValue) {
             return map[i].Value;
         }
     }
     source.ThrowEnumException(ExpectedType, wireValue);
     return null; // to make compiler happy
 }
Esempio n. 14
0
#pragma warning disable RCS1213
        private static Product Read(ref ProtoReader.State state, Product product1, ProtoReader reader1)
#pragma warning restore RCS1213
        {
            int num;

            while ((num = reader1.ReadFieldHeader(ref state)) > 0)
            {
                switch (num)
                {
                case 1:
                    if (product1 == null)
                    {
                        product1 = new Product();
                    }
                    product1.ProductID = reader1.ReadInt32(ref state);
                    continue;

                case 2:
                    if (product1 == null)
                    {
                        product1 = new Product();
                    }
                    product1.ProductName = reader1.ReadString(ref state);
                    continue;

                case 3:
                    if (product1 == null)
                    {
                        product1 = new Product();
                    }
                    product1.SupplierID = new int?(reader1.ReadInt32(ref state));
                    continue;
                }
            }
            return(product1);
        }
Esempio n. 15
0
        private static int ReadRowId(ProtoReader reader)
        {
            var token   = ProtoReader.StartSubItem(reader);
            var fieldId = reader.ReadFieldHeader();

            if (fieldId != ProtobufFieldIds.RowId)
            {
                return(-1);
            }

            var rowId        = reader.ReadInt32();
            var dummyFieldId = reader.ReadFieldHeader();

            ProtoReader.EndSubItem(token, reader);
            return(rowId);
        }
Esempio n. 16
0
            public void ShouldSerializeInt32Value()
            {
                // Arrange
                var value      = 42;
                var dataReader = this.CreateDataReader(value);

                // Act
                var reader = new ProtoReader(this.Serialize(dataReader), null, null);

                // Assert
                var readerContext = new ProtoReaderContext(reader);

                readerContext.ReadUntilFieldValue();

                Assert.Equal(value, reader.ReadInt32());
            }
Esempio n. 17
0
        public object Read(object value, ProtoReader source)
        {
            UnityEngine.Gradient data = (UnityEngine.Gradient)(value == null ? CreateInstance(source) : value);

            int fieldNumber = 0;

            SubItemToken token = ProtoReader.StartSubItem(source);

            while ((fieldNumber = source.ReadFieldHeader()) != 0)
            {
                switch (fieldNumber)
                {
                case 1:
                    data.mode = (UnityEngine.GradientMode)source.ReadInt32();
                    break;

                case 2:
                    alphaKeys.Clear();
                    do
                    {
                        alphaKeys.Add((UnityEngine.GradientAlphaKey) this.alphaKeySerializer.Read(
                                          new UnityEngine.GradientAlphaKey(), source));
                    } while (source.TryReadFieldHeader(2));
                    data.alphaKeys = alphaKeys.ToArray();
                    break;

                case 3:
                    colorKeys.Clear();
                    do
                    {
                        colorKeys.Add((UnityEngine.GradientColorKey) this.colorKeySerializer.Read(
                                          new UnityEngine.GradientColorKey(), source));
                    } while (source.TryReadFieldHeader(3));
                    data.colorKeys = colorKeys.ToArray();
                    break;

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

            ProtoReader.EndSubItem(token, source);

            return(data);
        }
Esempio n. 18
0
 public object Read(object value, ProtoReader source)
 {
     int num = source.ReadInt32();
     if (this.map == null)
     {
         return this.WireToEnum(num);
     }
     for (int i = 0; i < this.map.Length; i++)
     {
         if (this.map[i].WireValue == num)
         {
             return this.map[i].TypedValue;
         }
     }
     source.ThrowEnumException(this.ExpectedType, num);
     return null;
 }
Esempio n. 19
0
        public object Read(object value, ProtoReader source)
        {
            int num = source.ReadInt32();

            if (map == null)
            {
                return(WireToEnum(num));
            }
            for (int i = 0; i < map.Length; i++)
            {
                if (map[i].WireValue == num)
                {
                    return(map[i].TypedValue);
                }
            }
            source.ThrowEnumException(ExpectedType, num);
            return(null);
        }
Esempio n. 20
0
        private void ReadUpdate(Dictionary <int, int> remoteToLocalRowIds, ProtoReader reader)
        {
            var token = ProtoReader.StartSubItem(reader);

            var fieldId = reader.ReadFieldHeader();

            if (fieldId == ProtobufFieldIds.RowId) // Check for row id
            {
                var rowId = reader.ReadInt32();

                int localRowId;
                if (remoteToLocalRowIds.TryGetValue(rowId, out localRowId))
                {
                    WriteFieldsToTable(_table, _fieldIdsToColumns, reader, remoteToLocalRowIds[rowId]);
                }
            }

            ProtoReader.EndSubItem(token, reader);
        }
Esempio n. 21
0
        public object Read(object value, ProtoReader source)
        {
            Helpers.DebugAssert(value == null); // since replaces
            int wireValue = source.ReadInt32();

            if (map == null)
            {
                return(WireToEnum(wireValue));
            }
            for (int i = 0; i < map.Length; i++)
            {
                if (map[i].WireValue == wireValue)
                {
                    return(map[i].TypedValue);
                }
            }
            source.ThrowEnumException(ExpectedType, wireValue);
            return(null); // to make compiler happy
        }
        public object Read(object value, ProtoReader source)
        {
            UnityEngine.Keyframe data = (UnityEngine.Keyframe)value;

            int fieldNumber = 0;

            SubItemToken token = ProtoReader.StartSubItem(source);

            while ((fieldNumber = source.ReadFieldHeader()) != 0)
            {
                switch (fieldNumber)
                {
                case 1:
                    data.time = source.ReadSingle();
                    break;

                case 2:
                    data.value = source.ReadSingle();
                    break;

                case 3:
                    data.inTangent = source.ReadSingle();
                    break;

                case 4:
                    data.outTangent = source.ReadSingle();
                    break;

                case 5:
                    data.tangentMode = source.ReadInt32();
                    break;

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

            ProtoReader.EndSubItem(token, source);

            return(data);
        }
Esempio n. 23
0
        public object Read(object value, ProtoReader source)
        {
            Helpers.DebugAssert(value == null); // since replaces
            int wireValue = source.ReadInt32();

            if (map == null)
            {
                return(WireToEnum(wireValue));
            }
            for (int i = 0; i < map.Length; i++)
            {
                if (map[i].WireValue == wireValue)
                {
                    return(map[i].TypedValue);
                }
            }

            // return first value from the enum
            return(map[0]);
        }
        private void ReadColumn()
        {
            var    token = ProtoReader.StartSubItem(reader);
            int    field;
            string name          = null;
            var    protoDataType = (ProtoDataType)(-1);

            while ((field = reader.ReadFieldHeader()) != 0)
            {
                switch (field)
                {
                case 1:
                    name = reader.ReadString();
                    break;

                case 2:
                    protoDataType = (ProtoDataType)reader.ReadInt32();
                    break;

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

            switch (protoDataType)
            {
            case ProtoDataType.Int:
                colReaders.Add(() => reader.ReadInt32());
                break;

            case ProtoDataType.Short:
                colReaders.Add(() => reader.ReadInt16());
                break;

            case ProtoDataType.Decimal:
                colReaders.Add(() => BclHelpers.ReadDecimal(reader));
                break;

            case ProtoDataType.String:
                colReaders.Add(() => reader.ReadString());
                break;

            case ProtoDataType.Guid:
                colReaders.Add(() => BclHelpers.ReadGuid(reader));
                break;

            case ProtoDataType.DateTime:
                colReaders.Add(() => BclHelpers.ReadDateTime(reader));
                break;

            case ProtoDataType.Bool:
                colReaders.Add(() => reader.ReadBoolean());
                break;

            case ProtoDataType.Byte:
                colReaders.Add(() => reader.ReadByte());
                break;

            case ProtoDataType.Char:
                colReaders.Add(() => (char)reader.ReadInt16());
                break;

            case ProtoDataType.Double:
                colReaders.Add(() => reader.ReadDouble());
                break;

            case ProtoDataType.Float:
                colReaders.Add(() => reader.ReadSingle());
                break;

            case ProtoDataType.Long:
                colReaders.Add(() => reader.ReadInt64());
                break;

            case ProtoDataType.ByteArray:
                colReaders.Add(() => ProtoReader.AppendBytes(null, reader));
                break;

            case ProtoDataType.CharArray:
                colReaders.Add(() => reader.ReadString().ToCharArray());
                break;

            case ProtoDataType.TimeSpan:
                colReaders.Add(() => BclHelpers.ReadTimeSpan(reader));
                break;

            default:
                throw new NotSupportedException(protoDataType.ToString());
            }

            ProtoReader.EndSubItem(token, reader);
            dataTable.Columns.Add(name, ConvertProtoDataType.ToClrType(protoDataType));
        }
Esempio n. 25
0
 // Token: 0x06003581 RID: 13697 RVA: 0x00134A6E File Offset: 0x00132E6E
 public object Read(object value, ProtoReader source)
 {
     return(source.ReadInt32());
 }
Esempio n. 26
0
        static DataTable ProtoRead(Stream stream)
        {
            DataTable table = new DataTable();

            object[] values = null;
            using (ProtoReader reader = new ProtoReader(stream, null, null))
            {
                int field;
                List <Func <object> > colReaders = new List <Func <object> >();
                SubItemToken          token;
                while ((field = reader.ReadFieldHeader()) != 0)
                {
                    switch (field)
                    {
                    case 1:
                        table.TableName = reader.ReadString();
                        break;

                    case 2:
                        string     name       = null;
                        MappedType mappedType = (MappedType)(-1);
                        token = ProtoReader.StartSubItem(reader);
                        while ((field = reader.ReadFieldHeader()) != 0)
                        {
                            switch (field)
                            {
                            case 1:
                                name = reader.ReadString();
                                break;

                            case 2:
                                mappedType = (MappedType)reader.ReadInt32();
                                break;

                            default:
                                reader.SkipField();
                                break;
                            }
                        }
                        Type type;
                        switch (mappedType)
                        {
                        case MappedType.Int32:
                            type = typeof(int);
                            colReaders.Add(() => reader.ReadInt32());
                            break;

                        case MappedType.Int16:
                            type = typeof(short);
                            colReaders.Add(() => reader.ReadInt16());
                            break;

                        case MappedType.Decimal:
                            type = typeof(decimal);
                            colReaders.Add(() => BclHelpers.ReadDecimal(reader));
                            break;

                        case MappedType.String:
                            type = typeof(string);
                            colReaders.Add(() => reader.ReadString());
                            break;

                        case MappedType.Guid:
                            type = typeof(Guid);
                            colReaders.Add(() => BclHelpers.ReadGuid(reader));
                            break;

                        case MappedType.DateTime:
                            type = typeof(DateTime);
                            colReaders.Add(() => BclHelpers.ReadDateTime(reader));
                            break;

                        default:
                            throw new NotSupportedException(mappedType.ToString());
                        }
                        ProtoReader.EndSubItem(token, reader);
                        table.Columns.Add(name, type);
                        values = null;
                        break;

                    case 3:
                        if (values == null)
                        {
                            values = new object[table.Columns.Count];
                        }
                        else
                        {
                            Array.Clear(values, 0, values.Length);
                        }
                        token = ProtoReader.StartSubItem(reader);
                        while ((field = reader.ReadFieldHeader()) != 0)
                        {
                            if (field > values.Length)
                            {
                                reader.SkipField();
                            }
                            else
                            {
                                int i = field - 1;
                                values[i] = colReaders[i]();
                            }
                        }
                        ProtoReader.EndSubItem(token, reader);
                        table.Rows.Add(values);
                        break;

                    default:
                        reader.SkipField();
                        break;
                    }
                }
            }
            return(table);
        }
Esempio n. 27
0
 public object Read(object value, ProtoReader source)
 {
     return source.ReadInt32();
 }
 public object Read(object value, ProtoReader source)
 {
     Helpers.DebugAssert(value == null); // since replaces
     return source.ReadInt32();
 }
Esempio n. 29
0
        private static void Merge(ProtoReader reader, ref ProtoReader.State state, ref protogen.Order obj)
        {
            SubItemToken tok;
            int          field;

            if (obj == null)
            {
                obj = new protogen.Order();
            }
            while ((field = reader.ReadFieldHeader(ref state)) != 0)
            {
                switch (field)
                {
                case 1:
                    obj.OrderID = reader.ReadInt32(ref state);
                    break;

                case 2:
                    obj.CustomerID = reader.ReadString(ref state);
                    break;

                case 3:
                    obj.EmployeeID = reader.ReadInt32(ref state);
                    break;

                case 4:
                    obj.OrderDate = BclHelpers.ReadTimestamp(reader, ref state);
                    break;

                case 5:
                    obj.RequiredDate = BclHelpers.ReadTimestamp(reader, ref state);
                    break;

                case 6:
                    obj.ShippedDate = BclHelpers.ReadTimestamp(reader, ref state);
                    break;

                case 7:
                    obj.ShipVia = reader.ReadInt32(ref state);
                    break;

                case 8:
                    obj.Freight = reader.ReadDouble(ref state);
                    break;

                case 9:
                    obj.ShipName = reader.ReadString(ref state);
                    break;

                case 10:
                    obj.ShipAddress = reader.ReadString(ref state);
                    break;

                case 11:
                    obj.ShipCity = reader.ReadString(ref state);
                    break;

                case 12:
                    obj.ShipRegion = reader.ReadString(ref state);
                    break;

                case 13:
                    obj.ShipPostalCode = reader.ReadString(ref state);
                    break;

                case 14:
                    obj.ShipCountry = reader.ReadString(ref state);
                    break;

                case 15:
                    do
                    {
                        protogen.OrderLine _15 = default;
                        tok = ProtoReader.StartSubItem(reader, ref state);
                        Merge(reader, ref state, ref _15);
                        ProtoReader.EndSubItem(tok, reader, ref state);
                        obj.Lines.Add(_15);
                    } while (reader.TryReadFieldHeader(ref state, 1));
                    break;

                default:
                    reader.AppendExtensionData(ref state, obj);
                    break;
                }
            }
        }
Esempio n. 30
0
        public static DataTable ProtoRead(Stream stream)
        {
            DataTable table = new DataTable();

            object[]      array  = null;
            Func <object> item   = null;
            Func <object> func2  = null;
            Func <object> func3  = null;
            Func <object> func4  = null;
            Func <object> func5  = null;
            Func <object> func6  = null;
            Func <object> func7  = null;
            Func <object> func8  = null;
            Func <object> func9  = null;
            Func <object> func10 = null;
            Func <object> func11 = null;

            using (ProtoReader reader = new ProtoReader(stream, null, null))
            {
                int num;
                List <Func <object> > list = new List <Func <object> >();
                while ((num = reader.ReadFieldHeader()) != 0)
                {
                    SubItemToken token;
                    string       str;
                    string       str2;
                    MappedType   type;
                    Type         type2;
                    switch (num)
                    {
                    case 1:
                    {
                        table.TableName = reader.ReadString();
                        continue;
                    }

                    case 2:
                        str   = null;
                        str2  = string.Empty;
                        type  = ~MappedType.Boolean;
                        token = ProtoReader.StartSubItem(reader);
                        goto Label_00F1;

                    case 3:
                        if (array != null)
                        {
                            goto Label_0382;
                        }
                        array = new object[table.Columns.Count];
                        goto Label_038C;

                    default:
                        goto Label_03F3;
                    }
Label_009B:
                    switch (num)
                    {
                    case 1:
                        str = reader.ReadString();
                        break;

                    case 2:
                        type = (MappedType)reader.ReadInt32();
                        break;

                    case 3:
                        str2 = reader.ReadString();
                        break;

                    default:
                        reader.SkipField();
                        break;
                    }
Label_00F1:
                    if ((num = reader.ReadFieldHeader()) != 0)
                    {
                        goto Label_009B;
                    }
                    switch (type)
                    {
                    case MappedType.Boolean:
                        type2 = typeof(bool);
                        if (item == null)
                        {
                            item = () => reader.ReadBoolean();
                        }
                        list.Add(item);
                        break;

                    case MappedType.Byte:
                        type2 = typeof(byte[]);
                        if (func2 == null)
                        {
                            func2 = () => ReadBytes(reader);
                        }
                        list.Add(func2);
                        break;

                    case MappedType.Double:
                        type2 = typeof(double);
                        if (func3 == null)
                        {
                            func3 = () => reader.ReadDouble();
                        }
                        list.Add(func3);
                        break;

                    case MappedType.Int16:
                        type2 = typeof(short);
                        if (func6 == null)
                        {
                            func6 = () => reader.ReadInt16();
                        }
                        list.Add(func6);
                        break;

                    case MappedType.Int32:
                        type2 = typeof(int);
                        if (func5 == null)
                        {
                            func5 = () => reader.ReadInt32();
                        }
                        list.Add(func5);
                        break;

                    case MappedType.Int64:
                        type2 = typeof(long);
                        if (func4 == null)
                        {
                            func4 = () => reader.ReadInt64();
                        }
                        list.Add(func4);
                        break;

                    case MappedType.String:
                        type2 = typeof(string);
                        if (func8 == null)
                        {
                            func8 = () => reader.ReadString();
                        }
                        list.Add(func8);
                        break;

                    case MappedType.Decimal:
                        type2 = typeof(decimal);
                        if (func7 == null)
                        {
                            func7 = () => BclHelpers.ReadDecimal(reader);
                        }
                        list.Add(func7);
                        break;

                    case MappedType.Guid:
                        type2 = typeof(Guid);
                        if (func9 == null)
                        {
                            func9 = () => BclHelpers.ReadGuid(reader);
                        }
                        list.Add(func9);
                        break;

                    case MappedType.DateTime:
                        type2 = typeof(DateTime);
                        if (func10 == null)
                        {
                            func10 = () => BclHelpers.ReadDateTime(reader);
                        }
                        list.Add(func10);
                        break;

                    case MappedType.TimeSpan:
                        type2 = typeof(TimeSpan);
                        if (func11 == null)
                        {
                            func11 = () => BclHelpers.ReadTimeSpan(reader);
                        }
                        list.Add(func11);
                        break;

                    default:
                        throw new NotSupportedException(type.ToString());
                    }
                    ProtoReader.EndSubItem(token, reader);
                    table.Columns.Add(str, type2);
                    if (!string.IsNullOrEmpty(str2))
                    {
                        table.Columns[str].Caption = str2;
                    }
                    array = null;
                    continue;
Label_0382:
                    Array.Clear(array, 0, array.Length);
Label_038C:
                    token = ProtoReader.StartSubItem(reader);
                    while ((num = reader.ReadFieldHeader()) != 0)
                    {
                        if (num > array.Length)
                        {
                            reader.SkipField();
                        }
                        else
                        {
                            int index = num - 1;
                            array[index] = list[index]();
                        }
                    }
                    ProtoReader.EndSubItem(token, reader);
                    table.Rows.Add(array);
                    continue;
Label_03F3:
                    reader.SkipField();
                }
            }
            return(table);
        }
        /// <summary>
        /// The read.
        /// </summary>
        /// <param name="targetPlatform">
        /// The target platform.
        /// </param>
        /// <param name="protoReader">
        /// The proto reader.
        /// </param>
        /// <returns>
        /// The <see cref="TargetPlatform"/>.
        /// </returns>
        private static TargetPlatform Read(TargetPlatform targetPlatform, ProtoReader protoReader)
        {
            int num    = protoReader.ReadInt32();
            var result = TargetPlatform.Windows;

            if (num != 0)
            {
                if (num != 1)
                {
                    if (num != 2)
                    {
                        if (num != 3)
                        {
                            if (num != 4)
                            {
                                if (num != 5)
                                {
                                    if (num != 6)
                                    {
                                        if (num != 7)
                                        {
                                            if (num != 8)
                                            {
                                                if (num != 9)
                                                {
                                                    if (num != 10)
                                                    {
                                                        if (num != 11)
                                                        {
                                                            if (num != 12)
                                                            {
                                                                protoReader.ThrowEnumException(
                                                                    typeof(TargetPlatform),
                                                                    num);
                                                            }
                                                            else
                                                            {
                                                                result = TargetPlatform.RaspberryPi;
                                                            }
                                                        }
                                                        else
                                                        {
                                                            result = TargetPlatform.WindowsPhone8;
                                                        }
                                                    }
                                                    else
                                                    {
                                                        result = TargetPlatform.PlayStationMobile;
                                                    }
                                                }
                                                else
                                                {
                                                    result = TargetPlatform.Ouya;
                                                }
                                            }
                                            else
                                            {
                                                result = TargetPlatform.NativeClient;
                                            }
                                        }
                                        else
                                        {
                                            result = TargetPlatform.WindowsStoreApp;
                                        }
                                    }
                                    else
                                    {
                                        result = TargetPlatform.MacOSX;
                                    }
                                }
                                else
                                {
                                    result = TargetPlatform.Linux;
                                }
                            }
                            else
                            {
                                result = TargetPlatform.Android;
                            }
                        }
                        else
                        {
                            result = TargetPlatform.iOS;
                        }
                    }
                    else
                    {
                        result = TargetPlatform.WindowsPhone;
                    }
                }
                else
                {
                    result = TargetPlatform.Xbox360;
                }
            }
            else
            {
                result = TargetPlatform.Windows;
            }

            return(result);
        }
        /// <summary>
        /// The read.
        /// </summary>
        /// <param name="platformData">
        /// The platform data.
        /// </param>
        /// <param name="protoReader">
        /// The proto reader.
        /// </param>
        /// <returns>
        /// The <see cref="PlatformData"/>.
        /// </returns>
        private static PlatformData Read(PlatformData platformData, ProtoReader protoReader)
        {
            int num;

            while ((num = protoReader.ReadFieldHeader()) > 0)
            {
                if (num != 1)
                {
                    if (num != 2)
                    {
                        if (platformData == null)
                        {
                            var expr_164 = new PlatformData();
                            ProtoReader.NoteObject(expr_164, protoReader);
                            platformData = expr_164;
                        }

                        protoReader.SkipField();
                    }
                    else
                    {
                        if (platformData == null)
                        {
                            var expr_134 = new PlatformData();
                            ProtoReader.NoteObject(expr_134, protoReader);
                            platformData = expr_134;
                        }

                        byte[] array = ProtoReader.AppendBytes(platformData.Data, protoReader);
                        if (array != null)
                        {
                            platformData.Data = array;
                        }
                    }
                }
                else
                {
                    if (platformData == null)
                    {
                        var expr_19 = new PlatformData();
                        ProtoReader.NoteObject(expr_19, protoReader);
                        platformData = expr_19;
                    }

                    int num2           = protoReader.ReadInt32();
                    var targetPlatform = TargetPlatform.Windows;
                    if (num2 != 0)
                    {
                        if (num2 != 1)
                        {
                            if (num2 != 2)
                            {
                                if (num2 != 3)
                                {
                                    if (num2 != 4)
                                    {
                                        if (num2 != 5)
                                        {
                                            if (num2 != 6)
                                            {
                                                if (num2 != 7)
                                                {
                                                    if (num2 != 8)
                                                    {
                                                        if (num2 != 9)
                                                        {
                                                            if (num2 != 10)
                                                            {
                                                                if (num2 != 11)
                                                                {
                                                                    if (num2 != 12)
                                                                    {
                                                                        protoReader.ThrowEnumException(
                                                                            typeof(TargetPlatform),
                                                                            num2);
                                                                    }
                                                                    else
                                                                    {
                                                                        targetPlatform = TargetPlatform.RaspberryPi;
                                                                    }
                                                                }
                                                                else
                                                                {
                                                                    targetPlatform = TargetPlatform.WindowsPhone8;
                                                                }
                                                            }
                                                            else
                                                            {
                                                                targetPlatform = TargetPlatform.PlayStationMobile;
                                                            }
                                                        }
                                                        else
                                                        {
                                                            targetPlatform = TargetPlatform.Ouya;
                                                        }
                                                    }
                                                    else
                                                    {
                                                        targetPlatform = TargetPlatform.NativeClient;
                                                    }
                                                }
                                                else
                                                {
                                                    targetPlatform = TargetPlatform.WindowsStoreApp;
                                                }
                                            }
                                            else
                                            {
                                                targetPlatform = TargetPlatform.MacOSX;
                                            }
                                        }
                                        else
                                        {
                                            targetPlatform = TargetPlatform.Linux;
                                        }
                                    }
                                    else
                                    {
                                        targetPlatform = TargetPlatform.Android;
                                    }
                                }
                                else
                                {
                                    targetPlatform = TargetPlatform.iOS;
                                }
                            }
                            else
                            {
                                targetPlatform = TargetPlatform.WindowsPhone;
                            }
                        }
                        else
                        {
                            targetPlatform = TargetPlatform.Xbox360;
                        }
                    }
                    else
                    {
                        targetPlatform = TargetPlatform.Windows;
                    }

                    platformData.Platform = targetPlatform;
                }
            }

            if (platformData == null)
            {
                var expr_18C = new PlatformData();
                ProtoReader.NoteObject(expr_18C, protoReader);
                platformData = expr_18C;
            }

            return(platformData);
        }
        public override object Read(object value, ProtoReader source)
        {
			if (nested)
			{
				source.ReadFieldHeader();
			}

            int field = source.FieldNumber;
            BasicList list = new BasicList();

			if (packedWireType != WireType.None && source.WireType == WireType.String)
            {
                SubItemToken token = ProtoReader.StartSubItem(source);
                while (ProtoReader.HasSubValue(packedWireType, source))
                {
                    list.Add(Tail.Read(null, source));
                }
                ProtoReader.EndSubItem(token, source);

				int oldLen = AppendToCollection ? ((value == null ? 0 : ((Array)value).Length)) : 0;
				Array result = Array.CreateInstance(itemType, oldLen + list.Count);
				if (oldLen != 0) ((Array)value).CopyTo(result, 0);
				list.CopyTo(result, oldLen);

            	return result;
            }
            else
            {
				bool readObject = true;
            	int arrayKey = 0;

				value = value ?? Array.CreateInstance(itemType, 0);

				if (AsReference)
            	{
					int objectKey = source.ReadInt32();

					if (objectKey > 0)
					{
						value = source.NetCache.GetKeyedObject(objectKey);
						readObject = false;
					}
					else
					{
						bool dummy;
						arrayKey = source.NetCache.AddObjectKey(value, out dummy);
					}
            	}
				else
				{
					bool isEmpty = source.ReadInt32() == 1;
					if (isEmpty)
					{
						return value; 
					}
				}

				if (readObject)
				{
					while (source.TryReadFieldHeader(field)) 
					{
						list.Add(Tail.Read(null, source));
					}

					Array newArray = Array.CreateInstance(itemType, list.Count);
					list.CopyTo(newArray, 0);

					if (AsReference)
					{
						source.NetCache.UpdateKeyedObject(arrayKey, value, newArray);	
					}

					value = newArray;
				}
            }

            return value;
        }
        /// <summary>
        /// This is the more "complete" version of Deserialize, which handles single instances of mapped types.
        /// The value is read as a complete field, including field-header and (for sub-objects) a
        /// length-prefix..kmc  
        /// 
        /// In addition to that, this provides support for:
        ///  - basic values; individual int / string / Guid / etc
        ///  - IList sets of any type handled by TryDeserializeAuxiliaryType
        /// </summary>
        private bool TryDeserializeAuxiliaryType(ProtoReader reader, DataFormat format, int tag, Type type, ref object value, bool skipOtherFields, bool asListItem)
        {
            if (type == null) throw new ArgumentNullException("type");
            Type itemType = null;
            TypeCode typecode = Type.GetTypeCode(type);
            int modelKey;
            WireType wiretype = GetWireType(typecode, format, ref type, out modelKey);

            bool found = false;
            if (wiretype == WireType.None)
            {
                itemType = GetListItemType(type);

                if (itemType != null)
                {
                    return TryDeserializeList(reader, format, tag, type, itemType, ref value);                    
                }
                // otherwise, not a happy bunny...
                ThrowUnexpectedType(type);
            }
            
            // to treat correctly, should read all values

            while (true)
            {
                // for convenience (re complex exit conditions), additional exit test here:
                // if we've got the value, are only looking for one, and we aren't a list - then exit
                if (found && asListItem) break;

                // read the next item
                int fieldNumber = reader.ReadFieldHeader();
                if (fieldNumber <= 0) break;
                if (fieldNumber != tag)
                {
                    if (skipOtherFields)
                    {
                        reader.SkipField();
                        continue;
                    }
                    throw ProtoReader.AddErrorData(new InvalidOperationException(
                        "Expected field " + tag + ", but found " + fieldNumber), reader);
                }
                found = true;
                reader.Hint(wiretype); // handle signed data etc

                if (modelKey >= 0)
                {
                    switch (wiretype)
                    {
                        case WireType.String:
                        case WireType.StartGroup:
                            SubItemToken token = ProtoReader.StartSubItem(reader);
                            value = Deserialize(modelKey, value, reader);
                            ProtoReader.EndSubItem(token, reader);
                            continue;
                        default:
                            value = Deserialize(modelKey, value, reader);
                            continue;
                    }
                }
                switch (typecode)
                {
                    case TypeCode.Int16: value = reader.ReadInt16(); continue;
                    case TypeCode.Int32: value = reader.ReadInt32(); continue;
                    case TypeCode.Int64: value = reader.ReadInt64(); continue;
                    case TypeCode.UInt16: value = reader.ReadUInt16(); continue;
                    case TypeCode.UInt32: value = reader.ReadUInt32(); continue;
                    case TypeCode.UInt64: value = reader.ReadUInt64(); continue;
                    case TypeCode.Boolean: value = reader.ReadBoolean(); continue;
                    case TypeCode.SByte: value = reader.ReadSByte(); continue;
                    case TypeCode.Byte: value = reader.ReadByte(); continue;
                    case TypeCode.Char: value = (char)reader.ReadUInt16(); continue;
                    case TypeCode.Double: value = reader.ReadDouble(); continue;
                    case TypeCode.Single: value = reader.ReadSingle(); continue;
                    case TypeCode.DateTime: value = BclHelpers.ReadDateTime(reader); continue;
                    case TypeCode.Decimal: BclHelpers.ReadDecimal(reader); continue;
                    case TypeCode.String: value = reader.ReadString(); continue;
                }
                if (type == typeof(byte[])) { value = ProtoReader.AppendBytes((byte[])value, reader); continue; }
                if (type == typeof(TimeSpan)) { value = BclHelpers.ReadTimeSpan(reader); continue; }
                if (type == typeof(Guid)) { value = BclHelpers.ReadGuid(reader); continue; }
                if (type == typeof(Uri)) { value = new Uri(reader.ReadString()); continue; }

            }
            if (!found && !asListItem) { value = Activator.CreateInstance(type); }
            return found;
        }
Esempio n. 35
0
        private static long ReadTimeSpanTicks(ProtoReader source, out DateTimeKind kind)
        {
            kind = DateTimeKind.Unspecified;
            switch (source.WireType)
            {
            case WireType.String:
            case WireType.StartGroup:
                SubItemToken  token = ProtoReader.StartSubItem(source);
                int           fieldNumber;
                TimeSpanScale scale = TimeSpanScale.Days;
                long          value = 0;
                while ((fieldNumber = source.ReadFieldHeader()) > 0)
                {
                    switch (fieldNumber)
                    {
                    case FieldTimeSpanScale:
                        scale = (TimeSpanScale)source.ReadInt32();
                        break;

                    case FieldTimeSpanValue:
                        source.Assert(WireType.SignedVariant);
                        value = source.ReadInt64();
                        break;

                    case FieldTimeSpanKind:
                        kind = (DateTimeKind)source.ReadInt32();
                        switch (kind)
                        {
                        case DateTimeKind.Unspecified:
                        case DateTimeKind.Utc:
                        case DateTimeKind.Local:
                            break;             // fine

                        default:
                            throw new ProtoException("Invalid date/time kind: " + kind.ToString());
                        }
                        break;

                    default:
                        source.SkipField();
                        break;
                    }
                }
                ProtoReader.EndSubItem(token, source);
                switch (scale)
                {
                case TimeSpanScale.Days:
                    return(value * TimeSpan.TicksPerDay);

                case TimeSpanScale.Hours:
                    return(value * TimeSpan.TicksPerHour);

                case TimeSpanScale.Minutes:
                    return(value * TimeSpan.TicksPerMinute);

                case TimeSpanScale.Seconds:
                    return(value * TimeSpan.TicksPerSecond);

                case TimeSpanScale.Milliseconds:
                    return(value * TimeSpan.TicksPerMillisecond);

                case TimeSpanScale.Ticks:
                    return(value);

                case TimeSpanScale.MinMax:
                    switch (value)
                    {
                    case 1: return(long.MaxValue);

                    case -1: return(long.MinValue);

                    default: throw new ProtoException("Unknown min/max value: " + value.ToString());
                    }

                default:
                    throw new ProtoException("Unknown timescale: " + scale.ToString());
                }

            case WireType.Fixed64:
                return(source.ReadInt64());

            default:
                throw new ProtoException("Unexpected wire-type: " + source.WireType.ToString());
            }
        }
Esempio n. 36
0
        /// <summary>
        /// Reads an *implementation specific* bundled .NET object, including (as options) type-metadata, identity/re-use, etc.
        /// </summary>
        public static object ReadNetObject(object value, ProtoReader source, int key, Type type, NetObjectOptions options)
        {
            SubItemToken token = ProtoReader.StartSubItem(source);
            int          fieldNumber;
            int          newObjectKey = -1, newTypeKey = -1, tmp;

            while ((fieldNumber = source.ReadFieldHeader()) > 0)
            {
                switch (fieldNumber)
                {
                case FieldExistingObjectKey:
                    tmp   = source.ReadInt32();
                    value = source.NetCache.GetKeyedObject(tmp);
                    break;

                case FieldNewObjectKey:
                    newObjectKey = source.ReadInt32();
                    break;

                case FieldExistingTypeKey:
                    tmp  = source.ReadInt32();
                    type = (Type)source.NetCache.GetKeyedObject(tmp);
                    key  = source.GetTypeKey(ref type);
                    break;

                case FieldNewTypeKey:
                    newTypeKey = source.ReadInt32();
                    break;

                case FieldTypeName:
                    string typeName = source.ReadString();
                    type = source.DeserializeType(typeName);
                    if (type == null)
                    {
                        throw new ProtoException("Unable to resolve type: " + typeName + " (you can use the TypeModel.DynamicTypeFormatting event to provide a custom mapping)");
                    }
                    if (type == typeof(string))
                    {
                        key = -1;
                    }
                    else
                    {
                        key = source.GetTypeKey(ref type);
                        if (key < 0)
                        {
                            throw new InvalidOperationException("Dynamic type is not a contract-type: " + type.Name);
                        }
                    }
                    break;

                case FieldObject:
                    bool isString = type == typeof(string);
                    bool wasNull  = value == null;
                    bool lateSet  = wasNull && (isString || ((options & NetObjectOptions.LateSet) != 0));

                    if (newObjectKey >= 0 && !lateSet)
                    {
                        if (value == null)
                        {
                            source.TrapNextObject(newObjectKey);
                        }
                        else
                        {
                            source.NetCache.SetKeyedObject(newObjectKey, value);
                        }
                        if (newTypeKey >= 0)
                        {
                            source.NetCache.SetKeyedObject(newTypeKey, type);
                        }
                    }
                    object oldValue = value;
                    if (isString)
                    {
                        value = source.ReadString();
                    }
                    else
                    {
                        value = ProtoReader.ReadTypedObject(oldValue, key, source, type);
                    }

                    if (newObjectKey >= 0)
                    {
                        if (wasNull && !lateSet)
                        {     // this both ensures (via exception) that it *was* set, and makes sure we don't shout
                            // about changed references
                            oldValue = source.NetCache.GetKeyedObject(newObjectKey);
                        }
                        if (lateSet)
                        {
                            source.NetCache.SetKeyedObject(newObjectKey, value);
                            if (newTypeKey >= 0)
                            {
                                source.NetCache.SetKeyedObject(newTypeKey, type);
                            }
                        }
                    }
                    if (newObjectKey >= 0 && !lateSet && !ReferenceEquals(oldValue, value))
                    {
                        throw new ProtoException("A reference-tracked object changed reference during deserialization");
                    }
                    if (newObjectKey < 0 && newTypeKey >= 0)
                    {      // have a new type, but not a new object
                        source.NetCache.SetKeyedObject(newTypeKey, type);
                    }
                    break;

                default:
                    source.SkipField();
                    break;
                }
            }
            if (newObjectKey >= 0 && (options & NetObjectOptions.AsReference) == 0)
            {
                throw new ProtoException("Object key in input stream, but reference-tracking was not expected");
            }
            ProtoReader.EndSubItem(token, source);

            return(value);
        }