Esempio n. 1
0
        private static void WriterSystemJsonBasic(bool formatted, bool skipValidation, ArrayFormatterWrapper output, ReadOnlySpan <int> data)
        {
            var state = new JsonWriterState(options: new JsonWriterOptions {
                Indented = formatted, SkipValidation = skipValidation
            });

            var json = new Utf8JsonWriter2(output, state);

            json.WriteStartObject();
            json.WriteNumber("age", 42);
            json.WriteString("first", "John");
            json.WriteString("last", "Smith");
            json.WriteStartArray("phoneNumbers");
            json.WriteStringValue("425-000-1212");
            json.WriteStringValue("425-000-1213");
            json.WriteEndArray();
            json.WriteStartObject("address");
            json.WriteString("street", "1 Microsoft Way");
            json.WriteString("city", "Redmond");
            json.WriteNumber("zip", 98052);
            json.WriteEndObject();

            json.WriteStartArray("ExtraArray");
            for (var i = 0; i < data.Length; i++)
            {
                json.WriteNumberValue(data[i]);
            }
            json.WriteEndArray();

            json.WriteEndObject();

            json.Flush();
        }
        public static bool TrySerialize(ConfigurationSetting setting, byte[] buffer, out int written)
        {
            var json = new Utf8JsonWriter2(buffer);

            json.WriteStartObject();
            json.WriteString("value", setting.Value);
            json.WriteString("content_type", setting.ContentType);
            json.WriteEndObject();
            json.Flush();
            written = (int)json.BytesWritten;
            return(true);
        }
Esempio n. 3
0
        //[Benchmark]
        public void WriterSystemTextJsonBasicUtf8NoDefault()
        {
            _arrayFormatterWrapper.Clear();

            var state = new JsonWriterState(options: new JsonWriterOptions {
                Indented = Formatted, SkipValidation = SkipValidation
            });

            var json = new Utf8JsonWriter2(_arrayFormatterWrapper, state);

            json.WriteStartObject();
            for (int i = 0; i < 100; i++)
            {
                json.WriteString(First, John);
            }
            json.WriteEndObject();
            json.Flush();
        }
Esempio n. 4
0
        //[Benchmark]
        public void WriteDateTimeUnescapedOverheadUtf16()
        {
            _arrayFormatterWrapper.Clear();

            var state = new JsonWriterState(options: new JsonWriterOptions {
                Indented = Formatted, SkipValidation = SkipValidation
            });

            var json = new Utf8JsonWriter2(_arrayFormatterWrapper, state);

            json.WriteStartObject();
            for (int i = 0; i < 100; i++)
            {
                json.WriteString("first", MyDate, suppressEscaping: false);
            }
            json.WriteEndObject();
            json.Flush();
        }
Esempio n. 5
0
        //[Benchmark]
        public void WritePropertyValueEscapingRequired()
        {
            _arrayFormatterWrapper.Clear();

            var state = new JsonWriterState(options: new JsonWriterOptions {
                Indented = Formatted, SkipValidation = SkipValidation
            });

            var json = new Utf8JsonWriter2(_arrayFormatterWrapper, state);

            json.WriteStartObject();
            for (int i = 0; i < 100; i++)
            {
                json.WriteString("fir\nst", "Joh\nn");
            }
            json.WriteEndObject();
            json.Flush();
        }
Esempio n. 6
0
        //[Benchmark]
        public void WritePropertyValueEscapeUnnecessarily()
        {
            _arrayFormatterWrapper.Clear();

            var state = new JsonWriterState(options: new JsonWriterOptions {
                Indented = Formatted, SkipValidation = SkipValidation
            });

            var json = new Utf8JsonWriter2(_arrayFormatterWrapper, state);

            json.WriteStartObject();
            for (int i = 0; i < 100; i++)
            {
                json.WriteString("first", "John", suppressEscaping: false);
            }
            json.WriteEndObject();
            json.Flush();
        }