public override object Read(object value, ProtoReader source) { SubItemToken token = ProtoReader.StartSubItem(source); int num; while ((num = source.ReadFieldHeader()) > 0) { if (num == 1) { value = this.Tail.Read(value, source); } else { source.SkipField(); } } ProtoReader.EndSubItem(token, source); return value; }
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 .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); }
/// <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); }
/// <summary> /// The read. /// </summary> /// <param name="compiledAsset"> /// The compiled asset. /// </param> /// <param name="protoReader"> /// The proto reader. /// </param> /// <returns> /// The <see cref="CompiledAsset"/>. /// </returns> private static CompiledAsset Read(CompiledAsset compiledAsset, ProtoReader protoReader) { int num; while ((num = protoReader.ReadFieldHeader()) > 0) { if (num != 1) { if (num != 3) { if (compiledAsset == null) { var expr_8A = new CompiledAsset(); ProtoReader.NoteObject(expr_8A, protoReader); compiledAsset = expr_8A; } protoReader.SkipField(); } else { if (compiledAsset == null) { var expr_4C = new CompiledAsset(); ProtoReader.NoteObject(expr_4C, protoReader); compiledAsset = expr_4C; } PlatformData arg_63_0 = compiledAsset.PlatformData; SubItemToken token = ProtoReader.StartSubItem(protoReader); PlatformData arg_6F_0 = Read(arg_63_0, protoReader); ProtoReader.EndSubItem(token, protoReader); PlatformData platformData = arg_6F_0; if (platformData != null) { compiledAsset.PlatformData = platformData; } } } else { if (compiledAsset == null) { var expr_19 = new CompiledAsset(); ProtoReader.NoteObject(expr_19, protoReader); compiledAsset = expr_19; } string text = protoReader.ReadString(); if (text != null) { compiledAsset.Loader = text; } } } if (compiledAsset == null) { var expr_B2 = new CompiledAsset(); ProtoReader.NoteObject(expr_B2, protoReader); compiledAsset = expr_B2; } return(compiledAsset); }
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); }
private static DataTable ProtoReadTable(DataSet ds, ProtoReader reader) { int num; 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; DataTable table = new DataTable(); bool flag = false; object[] array = null; List <Func <object> > list = new List <Func <object> >(); while ((num = reader.ReadFieldHeader()) != 0) { SubItemToken token; string str; string str2; string str3; MappedType type; Type type2; switch (num) { case 1: { str = reader.ReadString(); if (!ds.Tables.Contains(str)) { break; } table = ds.Tables[str]; flag = true; continue; } case 2: str2 = null; str3 = string.Empty; type = ~MappedType.Boolean; token = ProtoReader.StartSubItem(reader); goto Label_0115; case 3: if (array != null) { goto Label_03C0; } array = new object[table.Columns.Count]; goto Label_03CA; default: goto Label_0432; } table.TableName = str; continue; Label_00BF: switch (num) { case 1: str2 = reader.ReadString(); break; case 2: type = (MappedType)reader.ReadInt32(); break; case 3: str3 = reader.ReadString(); break; default: reader.SkipField(); break; } Label_0115: if ((num = reader.ReadFieldHeader()) != 0) { goto Label_00BF; } 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); if (!table.Columns.Contains(str2)) { table.Columns.Add(str2, type2); } if (!string.IsNullOrEmpty(str3)) { table.Columns[str2].Caption = str3; } array = null; continue; Label_03C0: Array.Clear(array, 0, array.Length); Label_03CA: 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_0432: reader.SkipField(); } if (!flag) { ds.Tables.Add(table); } return(table); }
public override object Read(object value, ProtoReader source) { SubItemToken tok = ProtoReader.StartSubItem(source); int field; while((field = source.ReadFieldHeader()) > 0) { if(field == Tag) { value = Tail.Read(value, source); } else { source.SkipField(); } } ProtoReader.EndSubItem(tok, source); return value; }
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()); if (value == null && ser.ExpectedType == forType) value = 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); if (isExtensible) { source.AppendExtensionData((IExtensible)value); } else { source.SkipField(); } } } //Helpers.DebugWriteLine("<< Reading fields for " + forType.FullName); if(value == null) value = CreateInstance(source); if (isRootType) { Callback(value, TypeModel.CallbackType.AfterDeserialize, source.Context); } return value; }
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); }
public object Read(object value, ProtoReader source) { if (this.isRootType && value != null) { this.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) { num2 = (num = 0); } for (int i = num2; i < this.fieldNumbers.Length; i++) { if (this.fieldNumbers[i] == num3) { IProtoSerializer protoSerializer = this.serializers[i]; 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) { value = protoSerializer.Read(value, source); } else { protoSerializer.Read(value, source); } num2 = i; num = num3; flag = true; break; } } if (!flag) { if (value == null) { value = this.CreateInstance(source, true); } if (this.isExtensible) { source.AppendExtensionData((IExtensible)value); } else { source.SkipField(); } } } if (value == null) { value = this.CreateInstance(source, true); } if (this.isRootType) { this.Callback(value, TypeModel.CallbackType.AfterDeserialize, source.Context); } return value; }
public Soyo.Proto.ProtoTestBase Merge(ProtoReader input, Soyo.Proto.ProtoTestBase value) { int oldLimit = input.ReadClassBegin(); while (input.HasField) { switch (input.FieldId) { case 1: value.byteValue = input.Merge(value.byteValue); break; case 2: value.sbyteValue = input.Merge(value.sbyteValue); break; case 3: value.shortValue = input.Merge(value.shortValue); break; case 4: value.ushortValue = input.Merge(value.ushortValue); break; case 5: value.intValue = input.MergeSign(value.intValue); break; case 6: value.uintValue = input.MergeFixed(value.uintValue); break; case 7: value.longValue = input.MergeSign(value.longValue); break; case 8: value.ulongValue = input.MergeFixed(value.ulongValue); break; case 9: value.floatValue = input.Merge(value.floatValue); break; case 10: value.doubleValue = input.Merge(value.doubleValue); break; case 11: value.enumValue = (Soyo.Proto.EnumTest)input.Merge((int)value.enumValue); break; case 12: value.stringValue = input.Merge(value.stringValue); break; case 13: value.bufferValue = input.Merge(value.bufferValue); break; case 14: value.byteArrayValue = input.Merge(value.byteArrayValue); break; case 15: value.byteNullValue = input.Merge(value.byteNullValue); break; case 16: value.sbyteNullValue = input.Merge(value.sbyteNullValue); break; case 17: value.shortNullValue = input.Merge(value.shortNullValue); break; case 18: value.ushortNullValue = input.Merge(value.ushortNullValue); break; case 19: value.intNullValue = input.Merge(value.intNullValue); break; case 20: value.uintNullValue = input.Merge(value.uintNullValue); break; case 21: value.longNullValue = input.Merge(value.longNullValue); break; case 22: value.ulongNullValue = input.Merge(value.ulongNullValue); break; case 23: value.floatNullValue = input.Merge(value.floatNullValue); break; case 24: value.doubleNullValue = input.Merge(value.doubleNullValue); break; case 25: value.bufferNullValue = input.Merge(value.bufferNullValue); break; case 26: value.boolListValue = input.Merge(value.boolListValue); break; case 27: value.byteListValue = input.Merge(value.byteListValue); break; case 28: value.sbyteListValue = input.Merge(value.sbyteListValue); break; case 29: value.shortListValue = input.Merge(value.shortListValue); break; case 30: value.ushortListValue = input.Merge(value.ushortListValue); break; case 31: value.intListValue = input.Merge(value.intListValue); break; case 32: value.uintListValue = input.Merge(value.uintListValue); break; case 33: value.longListValue = input.Merge(value.longListValue); break; case 34: value.ulongListValue = input.Merge(value.ulongListValue); break; case 35: value.floatListValue = input.Merge(value.floatListValue); break; case 36: value.doubleListValue = input.Merge(value.doubleListValue); break; case 37: value.stringListValue = input.Merge(value.stringListValue); break; case 38: value.bufferListValue = input.Merge(value.bufferListValue); break; case 39: value.byteArrayListValue = input.Merge(value.byteArrayListValue); break; case 40: value.boolValue = input.Merge(value.boolValue); break; case 41: value.boolNullValue = input.Merge(value.boolNullValue); break; case 42: value.uintUintDictionary = input.Merge(value.uintUintDictionary); break; default: input.SkipField(); break; } } input.ReadClassEnd(oldLimit); return(value); }
internal bool TryDeserializeAuxiliaryType(ProtoReader reader, DataFormat format, int tag, Type type, ref object value, bool skipOtherFields, bool asListItem, bool autoCreate, bool insideList) { int num; if (type == null) { throw new ArgumentNullException("type"); } Type itemType = null; ProtoTypeCode typeCode = Helpers.GetTypeCode(type); WireType wireType = this.GetWireType(typeCode, format, ref type, out num); bool flag = false; if (wireType == WireType.None) { itemType = GetListItemType(this, type); if (((itemType == null) && type.IsArray) && ((type.GetArrayRank() == 1) && (type != typeof(byte[])))) { itemType = type.GetElementType(); } if (itemType != null) { if (insideList) { throw CreateNestedListsNotSupported(); } flag = this.TryDeserializeList(this, reader, format, tag, type, itemType, ref value); if (!flag && autoCreate) { value = CreateListInstance(type, itemType); } return(flag); } ThrowUnexpectedType(type); } Label_00B7: if (!flag || !asListItem) { int num2 = reader.ReadFieldHeader(); if (num2 > 0) { if (num2 != tag) { if (!skipOtherFields) { throw ProtoReader.AddErrorData(new InvalidOperationException("Expected field " + tag.ToString() + ", but found " + num2.ToString()), reader); } reader.SkipField(); } else { flag = true; reader.Hint(wireType); if (num >= 0) { switch (wireType) { case WireType.String: case WireType.StartGroup: { SubItemToken token = ProtoReader.StartSubItem(reader); value = this.Deserialize(num, value, reader); ProtoReader.EndSubItem(token, reader); goto Label_00B7; } } value = this.Deserialize(num, value, reader); } else { switch (typeCode) { case ProtoTypeCode.Boolean: value = reader.ReadBoolean(); break; case ProtoTypeCode.Char: value = (char)reader.ReadUInt16(); break; case ProtoTypeCode.SByte: value = reader.ReadSByte(); break; case ProtoTypeCode.Byte: value = reader.ReadByte(); break; case ProtoTypeCode.Int16: value = reader.ReadInt16(); break; case ProtoTypeCode.UInt16: value = reader.ReadUInt16(); break; case ProtoTypeCode.Int32: value = reader.ReadInt32(); break; case ProtoTypeCode.UInt32: value = reader.ReadUInt32(); break; case ProtoTypeCode.Int64: value = reader.ReadInt64(); break; case ProtoTypeCode.UInt64: value = reader.ReadUInt64(); break; case ProtoTypeCode.Single: value = reader.ReadSingle(); break; case ProtoTypeCode.Double: value = reader.ReadDouble(); break; case ProtoTypeCode.Decimal: value = BclHelpers.ReadDecimal(reader); break; case ProtoTypeCode.DateTime: value = BclHelpers.ReadDateTime(reader); break; case ProtoTypeCode.String: value = reader.ReadString(); break; case ProtoTypeCode.TimeSpan: value = BclHelpers.ReadTimeSpan(reader); break; case ProtoTypeCode.ByteArray: value = ProtoReader.AppendBytes((byte[])value, reader); break; case ProtoTypeCode.Guid: value = BclHelpers.ReadGuid(reader); break; case ProtoTypeCode.Uri: value = new Uri(reader.ReadString()); break; } } } goto Label_00B7; } } if ((!flag && !asListItem) && (autoCreate && (type != typeof(string)))) { value = Activator.CreateInstance(type); } return(flag); }
/// <summary> /// Reads an *implementation specific* bundled .NET object, including (as options) type-metadata, identity/re-use, etc. /// </summary> public static SubItemToken ReadNetObject_Start(ref object value, ProtoReader source, ref Type type, BclHelpers.NetObjectOptions options, out bool isDynamic, out bool isLateReference, ref int typeKey, out int newObjectKey, out int newTypeRefKey, out bool shouldEnd) { #if FEAT_IKVM throw new NotSupportedException(); #else shouldEnd = false; newObjectKey = -1; newTypeRefKey = -1; isDynamic = false; isLateReference = false; SubItemToken token = ProtoReader.StartSubItem(source); int fieldNumber; if ((fieldNumber = source.ReadFieldHeader()) == 0) { // null handling value = null; return(token); } do { int tmp; 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); typeKey = source.GetTypeKey(ref type); break; case FieldNewTypeKey: newTypeRefKey = 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)"); } typeKey = source.GetTypeKey(ref type); isDynamic = true; break; case FieldLateReferenceObject: case FieldObject: if (fieldNumber == FieldLateReferenceObject) { isLateReference = true; } shouldEnd = true; bool wasNull = value == null; bool lateSet = wasNull && ((options & BclHelpers.NetObjectOptions.LateSet) != 0); if (newObjectKey >= 0 && !lateSet) { if (value == null) { source.TrapNextObject(newObjectKey); } else { source.NetCache.SetKeyedObject(newObjectKey, value); } if (newTypeRefKey >= 0) { source.NetCache.SetKeyedObject(newTypeRefKey, type); } } return(token); default: source.SkipField(); break; } } while ((fieldNumber = source.ReadFieldHeader()) > 0); return(token); #endif }
private static void ProtoReadRelation(DataSet ds, ProtoReader reader) { int num; string relationName = null; string name = null; string str3 = null; string str4 = null; string str5 = null; while ((num = reader.ReadFieldHeader()) != 0) { switch (num) { case 1: { relationName = reader.ReadString(); continue; } case 2: { name = reader.ReadString(); continue; } case 3: { str3 = reader.ReadString(); continue; } case 4: { str4 = reader.ReadString(); continue; } case 5: { str5 = reader.ReadString(); continue; } } reader.SkipField(); } if (ds.Tables.Contains(name) && ds.Tables.Contains(str4)) { DataTable table = ds.Tables[name]; DataTable table2 = ds.Tables[str4]; string[] strArray = str5.Split(new char[] { ',' }); string[] strArray2 = str3.Split(new char[] { ',' }); List <DataColumn> list = new List <DataColumn>(); List <DataColumn> list2 = new List <DataColumn>(); foreach (string str6 in strArray) { if (table2.Columns.Contains(str6)) { list.Add(table2.Columns[str6]); } } foreach (string str7 in strArray2) { if (table.Columns.Contains(str7)) { list2.Add(table.Columns[str7]); } } DataRelation relation = new DataRelation(relationName, list2.ToArray(), list.ToArray(), false); ds.Relations.Add(relation); } }
public object Read(object value, ProtoReader source) { object[] values = new object[members.Length]; int tupleKey = 0; object oldTuple = null; bool issueReferenceDirectives = !baseTupleAsReference && asReference; if (issueReferenceDirectives) { tupleKey = (int)source.ReadUInt32(); if (tupleKey > 0) { return source.NetCache.GetKeyedObject(tupleKey); } else { bool dummy; oldTuple = new object(); tupleKey = source.NetCache.AddObjectKey(oldTuple, out dummy); } } bool invokeCtor = false; if (value == null) { invokeCtor = true; } for (int i = 0; i < values.Length; i++) values[i] = GetValue(value, i); int j = 0; int field; while (j++ < values.Length && source.ReadNextFieldHack() > 0) { field = source.ReadFieldHeader(); invokeCtor = true; if(field <= tails.Length) { IProtoSerializer tail = tails[field - 1]; values[field - 1] = tails[field - 1].Read(tail.RequiresOldValue ? values[field - 1] : null, source); } else { source.SkipField(); } } object result = invokeCtor ? ctor.Invoke(values) : value; if (issueReferenceDirectives) { source.NetCache.UpdateKeyedObject(tupleKey, oldTuple, result); } if (forceIssueFakeHeader) { source.ReadEndGroupFieldHeaderHack(); } return result; }
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()); } }
/// <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; }
/// <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) { #if FEAT_IKVM throw new NotSupportedException(); #else 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); #endif }
public object Read(object value, ProtoReader source) { object[] array = new object[this.members.Length]; bool flag = false; if (value == null) { flag = true; } for (int i = 0; i < array.Length; i++) { array[i] = this.GetValue(value, i); } int num; while ((num = source.ReadFieldHeader()) > 0) { flag = true; if (num <= this.tails.Length) { IProtoSerializer protoSerializer = this.tails[num - 1]; array[num - 1] = this.tails[num - 1].Read((!protoSerializer.RequiresOldValue) ? null : array[num - 1], source); } else { source.SkipField(); } } return (!flag) ? value : this.ctor.Invoke(array); }
public object Read(object value, ProtoReader source) { if (this.isRootType && value != null) { this.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) { num2 = (num = 0); } for (int i = num2; i < this.fieldNumbers.Length; i++) { if (this.fieldNumbers[i] == num3) { IProtoSerializer protoSerializer = this.serializers[i]; 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) { value = protoSerializer.Read(value, source); } else { protoSerializer.Read(value, source); } num2 = i; num = num3; flag = true; break; } } if (!flag) { if (value == null) { value = this.CreateInstance(source, true); } if (this.isExtensible) { source.AppendExtensionData((IExtensible)value); } else { source.SkipField(); } } } if (value == null) { value = this.CreateInstance(source, true); } if (this.isRootType) { this.Callback(value, TypeModel.CallbackType.AfterDeserialize, source.Context); } return(value); }
public object Read(object value, ProtoReader source) { object[] values = new object[members.Length]; bool invokeCtor = false; if (value == null) { invokeCtor = true; } for (int i = 0; i < values.Length; i++) values[i] = GetValue(value, i); int field; while ((field = source.ReadFieldHeader()) > 0) { invokeCtor = true; if (field <= tails.Length) { IProtoSerializer tail = tails[field - 1]; values[field - 1] = tails[field - 1].Read(tail.RequiresOldValue ? values[field - 1] : null, source); } else { source.SkipField(); } } return invokeCtor ? ctor.Invoke(values) : value; }
internal bool TryDeserializeAuxiliaryType(ProtoReader reader, DataFormat format, int tag, Type type, ref object value, bool skipOtherFields, bool asListItem, bool autoCreate, bool insideList) { if (type == null) { throw new ArgumentNullException("type"); } Type type2 = null; ProtoTypeCode typeCode = Helpers.GetTypeCode(type); int modelKey; WireType wireType = GetWireType(typeCode, format, ref type, out modelKey); bool flag = false; if (wireType == WireType.None) { type2 = GetListItemType(this, type); if (type2 == null && type.IsArray && type.GetArrayRank() == 1 && type != typeof(byte[])) { type2 = type.GetElementType(); } if (type2 != null) { if (insideList) { throw CreateNestedListsNotSupported(); } flag = TryDeserializeList(this, reader, format, tag, type, type2, ref value); if (!flag && autoCreate) { value = CreateListInstance(type, type2); } return(flag); } ThrowUnexpectedType(type); } while (!(flag && asListItem)) { int num = reader.ReadFieldHeader(); if (num <= 0) { break; } if (num != tag) { if (skipOtherFields) { reader.SkipField(); continue; } throw ProtoReader.AddErrorData(new InvalidOperationException("Expected field " + tag + ", but found " + num), reader); } flag = true; reader.Hint(wireType); if (modelKey >= 0) { if ((uint)(wireType - 2) <= 1u) { SubItemToken token = ProtoReader.StartSubItem(reader); value = Deserialize(modelKey, value, reader); ProtoReader.EndSubItem(token, reader); } else { value = Deserialize(modelKey, value, reader); } continue; } switch (typeCode) { case ProtoTypeCode.Int16: value = reader.ReadInt16(); break; case ProtoTypeCode.Int32: value = reader.ReadInt32(); break; case ProtoTypeCode.Int64: value = reader.ReadInt64(); break; case ProtoTypeCode.UInt16: value = reader.ReadUInt16(); break; case ProtoTypeCode.UInt32: value = reader.ReadUInt32(); break; case ProtoTypeCode.UInt64: value = reader.ReadUInt64(); break; case ProtoTypeCode.Boolean: value = reader.ReadBoolean(); break; case ProtoTypeCode.SByte: value = reader.ReadSByte(); break; case ProtoTypeCode.Byte: value = reader.ReadByte(); break; case ProtoTypeCode.Char: value = (char)reader.ReadUInt16(); break; case ProtoTypeCode.Double: value = reader.ReadDouble(); break; case ProtoTypeCode.Single: value = reader.ReadSingle(); break; case ProtoTypeCode.DateTime: value = BclHelpers.ReadDateTime(reader); break; case ProtoTypeCode.Decimal: value = BclHelpers.ReadDecimal(reader); break; case ProtoTypeCode.String: value = reader.ReadString(); break; case ProtoTypeCode.ByteArray: value = ProtoReader.AppendBytes((byte[])value, reader); break; case ProtoTypeCode.TimeSpan: value = BclHelpers.ReadTimeSpan(reader); break; case ProtoTypeCode.Guid: value = BclHelpers.ReadGuid(reader); break; case ProtoTypeCode.Uri: value = new Uri(reader.ReadString()); break; } } if (!flag && !asListItem && autoCreate && type != typeof(string)) { value = Activator.CreateInstance(type); } return(flag); }