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;
            }
Exemplo n.º 3
0
        private static int[][] ReadNestedArrayOfInts(
            IObjectReader reader)
        {
            int[][] array = null;

            if (reader.ReadStartArray())
            {
                List<int[]> list = new List<int[]>();

                while (reader.MoveToNextArrayValue())
                {
                    if (reader.ReadStartArray())
                    {
                        List<int> innerList = new List<int>();

                        while (reader.MoveToNextArrayValue())
                        {
                            innerList.Add(reader.ReadValueAsInt32());
                        }

                        reader.ReadEndArray();

                        list.Add(innerList.ToArray());
                    }
                    else
                    {
                        list.Add(null);
                    }
                }

                reader.ReadEndArray();

                array = list.ToArray();
            }

            return array;
        }
Exemplo n.º 4
0
        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;
        }
Exemplo n.º 5
0
        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;
        }