Esempio n. 1
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();
 }
Esempio n. 2
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();
        }
Esempio n. 3
0
        public void VerifyIsEqual(
            SimpleObject other)
        {
            if (this.StringValue != other.StringValue)
            {
                throw new Exception("StringValue does not match.");
            }

            if (this.StringEmptyValue != other.StringEmptyValue)
            {
                throw new Exception("StringEmptyValue does not match.");
            }

            if (this.StringNullValue != other.StringNullValue)
            {
                throw new Exception("StringNullValue does not match.");
            }

            if (!ArrayComparer<byte>.Equals(this.ByteArrayValue, other.ByteArrayValue))
            {
                throw new Exception("ByteArrayValue does not match.");
            }

            if (!ArrayComparer<byte>.Equals(this.ByteArrayEmptyValue, other.ByteArrayEmptyValue))
            {
                throw new Exception("ByteArrayEmptyValue does not match.");
            }

            if (!ArrayComparer<byte>.Equals(this.ByteArrayNullValue, other.ByteArrayNullValue))
            {
                throw new Exception("ByteArrayNullValue does not match.");
            }

            if (this.Int32ZeroValue != other.Int32ZeroValue)
            {
                throw new Exception("Int32ZeroValue does not match.");
            }

            if (this.Int32MinValue != other.Int32MinValue)
            {
                throw new Exception("Int32MinValue does not match.");
            }

            if (this.Int32MaxValue != other.Int32MaxValue)
            {
                throw new Exception("Int32MaxValue does not match.");
            }

            if (this.UInt32MinValue != other.UInt32MinValue)
            {
                throw new Exception("UInt32MinValue does not match.");
            }

            if (this.UInt32MaxValue != other.UInt32MaxValue)
            {
                throw new Exception("UInt32MaxValue does not match.");
            }

            if (this.SingleValue != other.SingleValue)
            {
                throw new Exception("SingleValue does not match.");
            }

            if (this.SingleMinValue != other.SingleMinValue)
            {
                throw new Exception("SingleMinValue does not match.");
            }

            if (this.SingleMaxValue != other.SingleMaxValue)
            {
                throw new Exception("SingleMaxValue does not match.");
            }

            if (!ArrayComparer<int>.Equals(this.Int32ArrayValue, other.Int32ArrayValue))
            {
                throw new Exception("Int32ArrayValue does not match.");
            }

            if (!ArrayComparer<int>.Equals(this.Int32ArrayEmptyValue, other.Int32ArrayEmptyValue))
            {
                throw new Exception("Int32ArrayEmptyValue does not match.");
            }

            if (!ArrayComparer<int>.Equals(this.Int32ArrayNullValue, other.Int32ArrayNullValue))
            {
                throw new Exception("Int32ArrayNullValue does not match.");
            }

            if (!ArrayComparer<string>.Equals(this.StringArrayValue, other.StringArrayValue))
            {
                throw new Exception("StringArrayValue does not match.");
            }

            if (!ArrayComparer<string>.Equals(this.StringArrayEmptyValue, other.StringArrayEmptyValue))
            {
                throw new Exception("StringArrayEmptyValue does not match.");
            }

            if (!ArrayComparer<string>.Equals(this.StringArrayNullValue, other.StringArrayNullValue))
            {
                throw new Exception("StringArrayNullValue does not match.");
            }

            if (this.StringWithEscapesValue != other.StringWithEscapesValue)
            {
                throw new Exception("StringWithEscapesValue does not match.");
            }

            if (this.StringWithSurrogatePairsValue != other.StringWithSurrogatePairsValue)
            {
                throw new Exception("StringWithSurrogatePairsValue does not match.");
            }

            if (this.DoubleValue != other.DoubleValue)
            {
                throw new Exception("DoubleValue does not match.");
            }

            if (this.DoubleMinValue != other.DoubleMinValue)
            {
                throw new Exception("DoubleMinValue does not match.");
            }

            if (this.DoubleMaxValue != other.DoubleMaxValue)
            {
                throw new Exception("DoubleMaxValue does not match.");
            }

            if (this.Int64ZeroValue != other.Int64ZeroValue)
            {
                throw new Exception("Int64ZeroValue does not match.");
            }

            if (this.Int64MinValue != other.Int64MinValue)
            {
                throw new Exception("Int64MinValue does not match.");
            }

            if (this.Int64MaxValue != other.Int64MaxValue)
            {
                throw new Exception("Int64MaxValue does not match.");
            }

            if (this.UInt64ZeroValue != other.UInt64ZeroValue)
            {
                throw new Exception("UInt64ZeroValue does not match.");
            }

            if (this.UInt64MinValue != other.UInt64MinValue)
            {
                throw new Exception("UInt64MinValue does not match.");
            }

            if (this.UInt64MaxValue != other.UInt64MaxValue)
            {
                throw new Exception("UInt64MaxValue does not match.");
            }

            if (this.BooleanTrueValue != other.BooleanTrueValue)
            {
                throw new Exception("BooleanTrueValue does not match.");
            }

            if (this.BooleanFalseValue != other.BooleanFalseValue)
            {
                throw new Exception("BooleanFalseValue does not match.");
            }

            if (!ArrayComparer<bool>.Equals(this.BooleanArrayValue, other.BooleanArrayValue))
            {
                throw new Exception("BooleanArrayValue does not match.");
            }
        }
Esempio n. 4
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;
        }
Esempio n. 5
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();
        }
Esempio n. 6
0
        public static SimpleObject Create()
        {
            SimpleObject simpleObject = new SimpleObject()
            {
                StringValue = "String",
                StringEmptyValue = String.Empty,
                StringNullValue = null,
                ByteArrayValue = new byte[] { 1, 2, 3 },
                ByteArrayEmptyValue = new byte[] { },
                ByteArrayNullValue = null,
                Int32ZeroValue = 0,
                Int32MinValue = Int32.MinValue,
                Int32MaxValue = Int32.MaxValue,
                UInt32MinValue = UInt32.MinValue,
                UInt32MaxValue = UInt32.MaxValue,
                SingleValue = 3.14159265359f,
                SingleMinValue = Single.MinValue,
                SingleMaxValue = Single.MaxValue,
                Int32ArrayValue = new int[] { 1, 2, 3 },
                Int32ArrayEmptyValue = new int[] { },
                Int32ArrayNullValue = null,
                StringArrayValue = new string[] { "One", null, String.Empty, "Four" },
                StringArrayEmptyValue = new string[] { },
                StringArrayNullValue = null,
                StringWithEscapesValue = "\"\\\b\f\n\r\t\u0000\u0001><][}{",
                StringWithSurrogatePairsValue = "\U0001f680\U0001f60a",
                DoubleValue = 3.14159265359,
                DoubleMinValue = Double.MinValue,
                DoubleMaxValue = Double.MaxValue,
                Int64ZeroValue = 0,
                Int64MinValue = Int64.MinValue,
                Int64MaxValue = Int64.MaxValue,
                UInt64ZeroValue = 0,
                UInt64MinValue = UInt64.MinValue,
                UInt64MaxValue = UInt64.MaxValue,
                BooleanTrueValue = true,
                BooleanFalseValue = false,
                BooleanArrayValue = new bool[] { true, false, true },
            };

            return simpleObject;
        }