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
 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 #3
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 #4
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();
        }