public static void WriteTo(
                IObjectWriter writer,
                ProtoBufNetTestObject obj)
            {
                if (null == obj)
                {
                    writer.WriteNullValue();
                    return;
                }

                writer.WriteStartObject();

                writer.WriteStartMember(1);
                writer.WriteValue(obj.Foo);
                writer.WriteEndMember();

                writer.WriteStartMember(2);
                writer.WriteValue(obj.Bar);
                writer.WriteEndMember();

                writer.WriteStartMember(3);
                writer.WriteValue(obj.Blip);
                writer.WriteEndMember();

                writer.WriteStartMember(4);
                writer.WriteValue(obj.Blop);
                writer.WriteEndMember();

                writer.WriteEndObject();
            }
Example #2
0
        public static void WriteTo(
            IObjectWriter writer,
            EmptyObject emptyObject)
        {
            if (null == emptyObject)
            {
                writer.WriteNullValue();
                return;
            }

            writer.WriteStartObject();

            writer.WriteEndObject();
        }
        public static void SerializePerson(Person person, IObjectWriter writer)
        {
            if (person == null)
            {
                writer.WriteNullValue();
            }
            else
            {
                writer.WriteStartObject();

                writer.WriteMember(1, person.Id);
                writer.WriteMember(2, person.Name);
                writer.WriteMember(3, person.Scores);

                writer.WriteEndObject();
            }
        }
            public static void WriteTo(
                IObjectWriter writer,
                JsonNetSimpleObject obj)
            {
                if (null == obj)
                {
                    writer.WriteNullValue();
                    return;
                }

                writer.WriteStartObject();

                writer.WriteMember(1, obj.Id);

                writer.WriteMember(2, obj.Name);

                writer.WriteMember(3, obj.Address);

                writer.WriteMember(4, obj.Scores);

                writer.WriteEndObject();
            }
Example #5
0
 private static void WriteMember(
     IObjectWriter writer,
     int memberKey,
     SimpleObject[][] array)
 {
     writer.WriteStartMember(memberKey);
     if (array == null)
     {
         writer.WriteNullValue();
     }
     else
     {
         writer.WriteStartArray();
         foreach (var nestedArray in array)
         {
             if (null == nestedArray)
             {
                 writer.WriteNullValue();
             }
             else
             {
                 writer.WriteStartArray();
                 foreach (var value in nestedArray)
                 {
                     SimpleObject.WriteTo(writer, value);
                 }
                 writer.WriteEndArray();
             }
         }
         writer.WriteEndArray();
     }
     writer.WriteEndMember();
 }
Example #6
0
        private static void WriteMember(
            IObjectWriter writer,
            int memberKey,
            SimpleObject[] array)
        {
            writer.WriteStartMember(memberKey);

            if (null == array)
            {
                writer.WriteNullValue();
            }
            else
            {
                writer.WriteStartArray();
                foreach (SimpleObject simpleObject in array)
                {
                    SimpleObject.WriteTo(writer, simpleObject);
                }
                writer.WriteEndArray();
            }
            writer.WriteEndMember();
        }
Example #7
0
        public static void WriteTo(
            IObjectWriter writer,
            ComplexObject complexObject)
        {
            if (null == complexObject)
            {
                writer.WriteNullValue();
                return;
            }

            writer.WriteStartObject();

            // Nested object
            writer.WriteStartMember(MemberKey.NestedObject);
            SimpleObject.WriteTo(writer, complexObject.NestedObject);
            writer.WriteEndMember();

            // Nested object (write-only)
            writer.WriteStartMember(MemberKey.WriteOnlyNestedObject);
            SimpleObject.WriteTo(writer, complexObject.NestedObject);
            writer.WriteEndMember();

            // Nested empty object
            writer.WriteStartMember(MemberKey.NestedEmptyObject);
            EmptyObject.WriteTo(writer, complexObject.NestedEmptyObject);
            writer.WriteEndMember();

            // Nested empty object (write-only)
            writer.WriteStartMember(MemberKey.WriteOnlyNestedEmptyObject);
            SimpleObject.WriteTo(writer, complexObject.NestedNullObject);
            writer.WriteEndMember();

            // Nested null object
            writer.WriteStartMember(MemberKey.NestedNullObject);
            SimpleObject.WriteTo(writer, complexObject.NestedNullObject);
            writer.WriteEndMember();

            // Nested null object (write-only)
            writer.WriteStartMember(MemberKey.WriteOnlyNestedNullObject);
            SimpleObject.WriteTo(writer, complexObject.NestedNullObject);
            writer.WriteEndMember();

            // Array of objects
            WriteMember(writer, MemberKey.ArrayOfObjects, complexObject.ArrayOfObjects);
            WriteMember(writer, MemberKey.WriteOnlyArrayOfObjects, complexObject.ArrayOfObjects);

            // Empty array of objects
            WriteMember(writer, MemberKey.EmptyArrayOfObjects, complexObject.EmptyArrayOfObjects);
            WriteMember(writer, MemberKey.WriteOnlyEmptyArrayOfObjects, complexObject.EmptyArrayOfObjects);

            // Null array of objects
            WriteMember(writer, MemberKey.NullArrayOfObjects, complexObject.NullArrayOfObjects);
            WriteMember(writer, MemberKey.WriteOnlyNullArrayOfObjects, complexObject.NullArrayOfObjects);

            // Nested array of ints
            WriteMember(writer, MemberKey.NestedArrayOfInts, complexObject.NestedArrayOfInts);
            WriteMember(writer, MemberKey.WriteOnlyNestedArrayOfInts, complexObject.NestedArrayOfInts);

            // Empty nested array of ints
            WriteMember(writer, MemberKey.NestedEmptyArrayOfInts, complexObject.NestedEmptyArrayOfInts);
            WriteMember(writer, MemberKey.WriteOnlyNestedEmptyArrayOfInts, complexObject.NestedEmptyArrayOfInts);

            // Null nested array of ints
            WriteMember(writer, MemberKey.NestedNullArrayOfInts, complexObject.NestedNullArrayOfInts);
            WriteMember(writer, MemberKey.WriteOnlyNestedNullArrayOfInts, complexObject.NestedNullArrayOfInts);

            // Nested array of strings
            WriteMember(writer, MemberKey.NestedArrayOfStrings, complexObject.NestedArrayOfStrings);
            WriteMember(writer, MemberKey.WriteOnlyNestedArrayOfStrings, complexObject.NestedArrayOfStrings);

            // Empty nested array of strings
            WriteMember(writer, MemberKey.NestedEmptyArrayOfStrings, complexObject.NestedEmptyArrayOfStrings);
            WriteMember(writer, MemberKey.WriteOnlyNestedEmptyArrayOfStrings, complexObject.NestedEmptyArrayOfStrings);

            // Null nested array of strings
            WriteMember(writer, MemberKey.NestedNullArrayOfStrings, complexObject.NestedNullArrayOfStrings);
            WriteMember(writer, MemberKey.WriteOnlyNestedNullArrayOfStrings, complexObject.NestedNullArrayOfStrings);

            // Nested array of objects
            WriteMember(writer, MemberKey.NestedArrayOfObjects, complexObject.NestedArrayOfObjects);
            WriteMember(writer, MemberKey.WriteOnlyNestedArrayOfObjects, complexObject.NestedArrayOfObjects);

            // Empty nested array of objects
            WriteMember(writer, MemberKey.NestedEmptyArrayOfObjects, complexObject.NestedEmptyArrayOfObjects);
            WriteMember(writer, MemberKey.WriteOnlyNestedEmptyArrayOfObjects, complexObject.NestedEmptyArrayOfObjects);

            // Null nested array of objects
            WriteMember(writer, MemberKey.NestedNullArrayOfObjects, complexObject.NestedNullArrayOfObjects);
            WriteMember(writer, MemberKey.WriteOnlyNestedNullArrayOfObjects, complexObject.NestedNullArrayOfObjects);

            writer.WriteEndObject();
        }
Example #8
0
        public static void WriteTo(
            IObjectWriter writer,
            SimpleObject simpleObject)
        {
            if (null == simpleObject)
            {
                writer.WriteNullValue();
                return;
            }

            writer.WriteStartObject();

            // String
            writer.WriteMember(MemberKey.StringValue, simpleObject.StringValue);
            writer.WriteMember(MemberKey.WriteOnlyStringValue, simpleObject.StringValue);

            // Empty String
            writer.WriteMember(MemberKey.StringEmptyValue, simpleObject.StringEmptyValue);
            writer.WriteMember(MemberKey.WriteOnlyStringEmptyValue, simpleObject.StringEmptyValue);

            // Null String
            writer.WriteMember(MemberKey.StringNullValue, simpleObject.StringNullValue);
            writer.WriteMember(MemberKey.WriteOnlyStringNullValue, simpleObject.StringNullValue);

            // Byte[]
            writer.WriteMember(MemberKey.ByteArrayValue, simpleObject.ByteArrayValue);
            writer.WriteMember(MemberKey.WriteOnlyByteArrayValue, simpleObject.ByteArrayValue);

            // Empty Byte[]
            writer.WriteMember(MemberKey.ByteArrayEmptyValue, simpleObject.ByteArrayEmptyValue);
            writer.WriteMember(MemberKey.WriteOnlyByteArrayEmptyValue, simpleObject.ByteArrayEmptyValue);

            // Null Byte[]
            writer.WriteMember(MemberKey.ByteArrayNullValue, simpleObject.ByteArrayNullValue);
            writer.WriteMember(MemberKey.WriteOnlyByteArrayNullValue, simpleObject.ByteArrayNullValue);

            // 0 Int
            writer.WriteMember(MemberKey.Int32ZeroValue, simpleObject.Int32ZeroValue);
            writer.WriteMember(MemberKey.WriteOnlyInt32ZeroValue, simpleObject.Int32ZeroValue);

            // Min Int
            writer.WriteMember(MemberKey.Int32MinValue, simpleObject.Int32MinValue);
            writer.WriteMember(MemberKey.WriteOnlyInt32MinValue, simpleObject.Int32MinValue);

            // Max Int
            writer.WriteMember(MemberKey.Int32MaxValue, simpleObject.Int32MaxValue);
            writer.WriteMember(MemberKey.WriteOnlyInt32MaxValue, simpleObject.Int32MaxValue);

            // Min UInt32
            writer.WriteMember(MemberKey.UInt32MinValue, simpleObject.UInt32MinValue);
            writer.WriteMember(MemberKey.WriteOnlyUInt32MinValue, simpleObject.UInt32MinValue);

            // Max UInt32
            writer.WriteMember(MemberKey.UInt32MaxValue, simpleObject.UInt32MaxValue);
            writer.WriteMember(MemberKey.WriteOnlyUInt32MaxValue, simpleObject.UInt32MaxValue);

            // Single
            writer.WriteMember(MemberKey.SingleValue, simpleObject.SingleValue);
            writer.WriteMember(MemberKey.WriteOnlySingleValue, simpleObject.SingleValue);

            // Min Single
            writer.WriteMember(MemberKey.SingleMinValue, simpleObject.SingleMinValue);
            writer.WriteMember(MemberKey.WriteOnlySingleMinValue, simpleObject.SingleMinValue);

            // Max Single
            writer.WriteMember(MemberKey.SingleMaxValue, simpleObject.SingleMaxValue);
            writer.WriteMember(MemberKey.WriteOnlySingleMaxValue, simpleObject.SingleMaxValue);

            // Int32 Array
            writer.WriteMember(MemberKey.Int32ArrayValue, simpleObject.Int32ArrayValue);
            writer.WriteMember(MemberKey.WriteOnlyInt32ArrayValue, simpleObject.Int32ArrayValue);

            // Empty Int32 Array
            writer.WriteMember(MemberKey.Int32ArrayEmptyValue, simpleObject.Int32ArrayEmptyValue);
            writer.WriteMember(MemberKey.WriteOnlyInt32ArrayEmptyValue, simpleObject.Int32ArrayEmptyValue);

            // Null Int32 Array
            writer.WriteMember(MemberKey.Int32ArrayNullValue, simpleObject.Int32ArrayNullValue);
            writer.WriteMember(MemberKey.WriteOnlyInt32ArrayNullValue, simpleObject.Int32ArrayNullValue);

            // String Array
            writer.WriteMember(MemberKey.StringArrayValue, simpleObject.StringArrayValue);
            writer.WriteMember(MemberKey.WriteOnlyStringArrayValue, simpleObject.StringArrayValue);

            // Empty String Array
            writer.WriteMember(MemberKey.StringArrayEmptyValue, simpleObject.StringArrayEmptyValue);
            writer.WriteMember(MemberKey.WriteOnlyStringArrayEmptyValue, simpleObject.StringArrayEmptyValue);

            // Null String Array
            writer.WriteMember(MemberKey.StringArrayNullValue, simpleObject.StringArrayNullValue);
            writer.WriteMember(MemberKey.WriteOnlyStringArrayNullValue, simpleObject.StringArrayNullValue);

            // String with escapes
            writer.WriteMember(MemberKey.StringWithEscapesValue, simpleObject.StringWithEscapesValue);
            writer.WriteMember(MemberKey.WriteOnlyStringWithEscapesValue, simpleObject.StringWithEscapesValue);

            // String with surrogate pairs
            writer.WriteMember(MemberKey.StringWithSurrogatePairsValue, simpleObject.StringWithSurrogatePairsValue);
            writer.WriteMember(MemberKey.WriteOnlyStringWithSurrogatePairsValue, simpleObject.StringWithSurrogatePairsValue);

            // Double
            writer.WriteMember(MemberKey.DoubleValue, simpleObject.DoubleValue);
            writer.WriteMember(MemberKey.WriteOnlyDoubleValue, simpleObject.DoubleValue);

            // Min double
            writer.WriteMember(MemberKey.DoubleMinValue, simpleObject.DoubleMinValue);
            writer.WriteMember(MemberKey.WriteOnlyDoubleMinValue, simpleObject.DoubleMinValue);

            // Max double
            writer.WriteMember(MemberKey.DoubleMaxValue, simpleObject.DoubleMaxValue);
            writer.WriteMember(MemberKey.WriteOnlyDoubleMaxValue, simpleObject.DoubleMaxValue);

            // Int64
            writer.WriteMember(MemberKey.Int64ZeroValue, simpleObject.Int64ZeroValue);
            writer.WriteMember(MemberKey.WriteOnlyInt64ZeroValue, simpleObject.Int64ZeroValue);

            // Min Int64
            writer.WriteMember(MemberKey.Int64MinValue, simpleObject.Int64MinValue);
            writer.WriteMember(MemberKey.WriteOnlyInt64MinValue, simpleObject.Int64MinValue);

            // Max Int64
            writer.WriteMember(MemberKey.Int64MaxValue, simpleObject.Int64MaxValue);
            writer.WriteMember(MemberKey.WriteOnlyInt64MaxValue, simpleObject.Int64MaxValue);

            // UInt64
            writer.WriteMember(MemberKey.UInt64ZeroValue, simpleObject.UInt64ZeroValue);
            writer.WriteMember(MemberKey.WriteOnlyUInt64ZeroValue, simpleObject.UInt64ZeroValue);

            // Min UInt64
            writer.WriteMember(MemberKey.UInt64MinValue, simpleObject.UInt64MinValue);
            writer.WriteMember(MemberKey.WriteOnlyUInt64MinValue, simpleObject.UInt64MinValue);

            // Max UInt64
            writer.WriteMember(MemberKey.UInt64MaxValue, simpleObject.UInt64MaxValue);
            writer.WriteMember(MemberKey.WriteOnlyUInt64MaxValue, simpleObject.UInt64MaxValue);

            // Boolean true
            writer.WriteMember(MemberKey.BooleanTrueValue, simpleObject.BooleanTrueValue);
            writer.WriteMember(MemberKey.WriteOnlyBooleanTrueValue, simpleObject.BooleanTrueValue);

            // Boolean false
            writer.WriteMember(MemberKey.BooleanFalseValue, simpleObject.BooleanFalseValue);
            writer.WriteMember(MemberKey.WriteOnlyBooleanFalseValue, simpleObject.BooleanFalseValue);

            // Boolean array
            writer.WriteMember(MemberKey.BooleanArrayValue, simpleObject.BooleanArrayValue);
            writer.WriteMember(MemberKey.WriteOnlyBooleanArrayValue, simpleObject.BooleanArrayValue);

            writer.WriteEndObject();
        }