public static EmptyObject ReadFrom( IObjectReader reader) { EmptyObject emptyObject = null; if (reader.ReadStartObject()) { emptyObject = new EmptyObject(); int memberKey; while (reader.ReadNextMemberKey()) { memberKey = reader.MemberKey; Debug.WriteLine("Skipping member key {0}", memberKey); } // TODO: Should ReadEndObject skip any remaining members? reader.ReadEndObject(); } return emptyObject; }
public static ComplexObject ReadFrom( IObjectReader reader) { ComplexObject complexObject = null; if (reader.ReadStartObject()) { complexObject = new ComplexObject(); int memberKey; while (reader.ReadNextMemberKey()) { memberKey = reader.MemberKey; if (memberKey == MemberKey.NestedObject) { complexObject.NestedObject = SimpleObject.ReadFrom(reader); } if (memberKey == MemberKey.NestedEmptyObject) { complexObject.NestedEmptyObject = EmptyObject.ReadFrom(reader); } if (memberKey == MemberKey.NestedNullObject) { complexObject.NestedNullObject = SimpleObject.ReadFrom(reader); } else if (memberKey == MemberKey.ArrayOfObjects) { complexObject.ArrayOfObjects = ReadArrayOfSimpleObjects(reader); } else if (memberKey == MemberKey.EmptyArrayOfObjects) { complexObject.EmptyArrayOfObjects = ReadArrayOfSimpleObjects(reader); } else if (memberKey == MemberKey.NullArrayOfObjects) { complexObject.NullArrayOfObjects = ReadArrayOfSimpleObjects(reader); } else if (memberKey == MemberKey.NestedArrayOfInts) { complexObject.NestedArrayOfInts = ReadNestedArrayOfInts(reader); } else if (memberKey == MemberKey.NestedEmptyArrayOfInts) { complexObject.NestedEmptyArrayOfInts = ReadNestedArrayOfInts(reader); } else if (memberKey == MemberKey.NestedNullArrayOfInts) { complexObject.NestedNullArrayOfInts = ReadNestedArrayOfInts(reader); } else if (memberKey == MemberKey.NestedArrayOfStrings) { complexObject.NestedArrayOfStrings = ReadNestedArrayOfStrings(reader); } else if (memberKey == MemberKey.NestedEmptyArrayOfStrings) { complexObject.NestedEmptyArrayOfStrings = ReadNestedArrayOfStrings(reader); } else if (memberKey == MemberKey.NestedNullArrayOfStrings) { complexObject.NestedNullArrayOfStrings = ReadNestedArrayOfStrings(reader); } else if (memberKey == MemberKey.NestedArrayOfObjects) { complexObject.NestedArrayOfObjects = ReadNestedArrayOfSimpleObjects(reader); } else if (memberKey == MemberKey.NestedEmptyArrayOfObjects) { complexObject.NestedEmptyArrayOfObjects = ReadNestedArrayOfSimpleObjects(reader); } else if (memberKey == MemberKey.NestedNullArrayOfObjects) { complexObject.NestedNullArrayOfObjects = ReadNestedArrayOfSimpleObjects(reader); } //else //{ // Debug.WriteLine("Skipping member key {0}", memberKey); //} } reader.ReadEndObject(); } return complexObject; }
public static Person DeserializePerson1(IObjectReader reader) { if (!reader.ReadStartObject()) { return null; } Person person = new Person(); while (reader.ReadNextMemberKey()) { if (reader.MemberKey == 1) { person.Id = reader.ReadValueAsInt32(); } else if (reader.MemberKey == 2) { person.Name = reader.ReadValueAsString(250); } else if (reader.MemberKey == 3) { person.Scores = reader.ReadValueAsInt32Array(); } } reader.ReadEndObject(); return person; }
public static SimpleObject ReadFrom( IObjectReader reader) { SimpleObject simpleObject = null; if (reader.ReadStartObject()) { simpleObject = new SimpleObject(); int memberKey; while (reader.ReadNextMemberKey()) { memberKey = reader.MemberKey; if (memberKey == MemberKey.StringValue) { simpleObject.StringValue = reader.ReadValueAsString(StringQuotaInBytes); } else if (memberKey == MemberKey.StringEmptyValue) { simpleObject.StringEmptyValue = reader.ReadValueAsString(StringQuotaInBytes); } else if (memberKey == MemberKey.StringNullValue) { simpleObject.StringNullValue = reader.ReadValueAsString(StringQuotaInBytes); } else if (memberKey == MemberKey.ByteArrayValue) { simpleObject.ByteArrayValue = reader.ReadValueAsBytes(StringQuotaInBytes); } else if (memberKey == MemberKey.ByteArrayEmptyValue) { simpleObject.ByteArrayEmptyValue = reader.ReadValueAsBytes(StringQuotaInBytes); } else if (memberKey == MemberKey.ByteArrayNullValue) { simpleObject.ByteArrayNullValue = reader.ReadValueAsBytes(StringQuotaInBytes); } else if (memberKey == MemberKey.Int32ZeroValue) { simpleObject.Int32ZeroValue = reader.ReadValueAsInt32(); } else if (memberKey == MemberKey.Int32MinValue) { simpleObject.Int32MinValue = reader.ReadValueAsInt32(); } else if (memberKey == MemberKey.Int32MaxValue) { simpleObject.Int32MaxValue = reader.ReadValueAsInt32(); } else if (memberKey == MemberKey.UInt32MinValue) { simpleObject.UInt32MinValue = reader.ReadValueAsUInt32(); } else if (memberKey == MemberKey.UInt32MaxValue) { simpleObject.UInt32MaxValue = reader.ReadValueAsUInt32(); } else if (memberKey == MemberKey.SingleValue) { simpleObject.SingleValue = reader.ReadValueAsSingle(); } else if (memberKey == MemberKey.SingleMinValue) { simpleObject.SingleMinValue = reader.ReadValueAsSingle(); } else if (memberKey == MemberKey.SingleMaxValue) { simpleObject.SingleMaxValue = reader.ReadValueAsSingle(); } else if (memberKey == MemberKey.Int32ArrayValue) { simpleObject.Int32ArrayValue = reader.ReadValueAsInt32Array(); } else if (memberKey == MemberKey.Int32ArrayEmptyValue) { simpleObject.Int32ArrayEmptyValue = reader.ReadValueAsInt32Array(); } else if (memberKey == MemberKey.Int32ArrayNullValue) { simpleObject.Int32ArrayNullValue = reader.ReadValueAsInt32Array(); } else if (memberKey == MemberKey.StringArrayValue) { simpleObject.StringArrayValue = reader.ReadValueAsStringArray(StringQuotaInBytes); } else if (memberKey == MemberKey.StringArrayEmptyValue) { simpleObject.StringArrayEmptyValue = reader.ReadValueAsStringArray(StringQuotaInBytes); } else if (memberKey == MemberKey.StringArrayNullValue) { simpleObject.StringArrayNullValue = reader.ReadValueAsStringArray(StringQuotaInBytes); } else if (memberKey == MemberKey.StringWithEscapesValue) { simpleObject.StringWithEscapesValue = reader.ReadValueAsString(StringQuotaInBytes); } else if (memberKey == MemberKey.StringWithSurrogatePairsValue) { simpleObject.StringWithSurrogatePairsValue = reader.ReadValueAsString(StringQuotaInBytes); } else if (memberKey == MemberKey.DoubleValue) { simpleObject.DoubleValue = reader.ReadValueAsDouble(); } else if (memberKey == MemberKey.DoubleMinValue) { simpleObject.DoubleMinValue = reader.ReadValueAsDouble(); } else if (memberKey == MemberKey.DoubleMaxValue) { simpleObject.DoubleMaxValue = reader.ReadValueAsDouble(); } else if (memberKey == MemberKey.Int64ZeroValue) { simpleObject.Int64ZeroValue = reader.ReadValueAsInt64(); } else if (memberKey == MemberKey.Int64MinValue) { simpleObject.Int64MinValue = reader.ReadValueAsInt64(); } else if (memberKey == MemberKey.Int64MaxValue) { simpleObject.Int64MaxValue = reader.ReadValueAsInt64(); } else if (memberKey == MemberKey.UInt64ZeroValue) { simpleObject.UInt64ZeroValue = reader.ReadValueAsUInt64(); } else if (memberKey == MemberKey.UInt64MinValue) { simpleObject.UInt64MinValue = reader.ReadValueAsUInt64(); } else if (memberKey == MemberKey.UInt64MaxValue) { simpleObject.UInt64MaxValue = reader.ReadValueAsUInt64(); } else if (memberKey == MemberKey.BooleanTrueValue) { simpleObject.BooleanTrueValue = reader.ReadValueAsBoolean(); } else if (memberKey == MemberKey.BooleanFalseValue) { simpleObject.BooleanFalseValue = reader.ReadValueAsBoolean(); } else if (memberKey == MemberKey.BooleanArrayValue) { simpleObject.BooleanArrayValue = reader.ReadValueAsBooleanArray(); } //else //{ // Debug.WriteLine("Skipping member key {0}", memberKey); //} } reader.ReadEndObject(); } return simpleObject; }
public static JsonNetSimpleObject ReadFrom( IObjectReader reader) { JsonNetSimpleObject obj = null; if (reader.ReadStartObject()) { obj = new JsonNetSimpleObject(); int memberKey; while (reader.ReadNextMemberKey()) { memberKey = reader.MemberKey; if (memberKey == 1) { obj.Id = reader.ReadValueAsInt32(); } else if (memberKey == 2) { obj.Name = reader.ReadValueAsString(StringQuotaInBytes); } else if (memberKey == 3) { obj.Address = reader.ReadValueAsString(StringQuotaInBytes); } else if (memberKey == 4) { obj.Scores = null; if (reader.ReadStartArray()) { List<int> list = new List<int>(); while (reader.MoveToNextArrayValue()) { list.Add(reader.ReadValueAsInt32()); } reader.ReadEndArray(); obj.Scores = list.ToArray(); } } } reader.ReadEndObject(); } return obj; }
public static ProtoBufNetTestObject ReadFrom( IObjectReader reader) { ProtoBufNetTestObject obj = null; if (reader.ReadStartObject()) { obj = new ProtoBufNetTestObject(); int memberKey; while (reader.ReadNextMemberKey()) { memberKey = reader.MemberKey; if (memberKey == 1) { obj.Foo = reader.ReadValueAsInt32(); } else if (memberKey == 2) { obj.Bar = reader.ReadValueAsString(StringQuotaInBytes); } else if (memberKey == 3) { obj.Blip = reader.ReadValueAsSingle(); } else if (memberKey == 4) { obj.Blop = reader.ReadValueAsDouble(); } } reader.ReadEndObject(); } return obj; }