Example #1
0
        /// <summary>
        /// Constructs a JSON writer with a specified <paramref name="bufferWriter"/>.
        /// </summary>
        /// <param name="bufferWriter">An instance of <see cref="ITextBufferWriter" /> used for writing bytes to an output channel.</param>
        /// <param name="prettyPrint">Specifies whether to add whitespace to the output text for user readability.</param>
        public Utf8JsonWriter2(IBufferWriter <byte> bufferWriter, JsonWriterState state = default)
        {
            _output        = bufferWriter ?? throw new ArgumentNullException(nameof(bufferWriter));
            _buffered      = 0;
            BytesCommitted = 0;
            _buffer        = _output.GetSpan();

            _inObject       = state._inObject;
            _isNotPrimitive = state._isNotPrimitive;
            _tokenType      = state._tokenType;
            _writerOptions  = state._writerOptions;
            _bitStack       = state._bitStack;

            _currentDepth = 0;
        }
Example #2
0
        public Utf8JsonWriter2(Span <byte> outputSpan, JsonWriterState state = default)
        {
            _output        = null;
            _buffered      = 0;
            BytesCommitted = 0;
            _buffer        = outputSpan;

            _inObject       = state._inObject;
            _isNotPrimitive = state._isNotPrimitive;
            _tokenType      = state._tokenType;
            _writerOptions  = state._writerOptions;
            _bitStack       = state._bitStack;

            _currentDepth = 0;
        }
Example #3
0
        /// <summary>
        /// Constructs a JSON writer with a specified <paramref name="bufferWriter"/>.
        /// </summary>
        /// <param name="bufferWriter">An instance of <see cref="ITextBufferWriter" /> used for writing bytes to an output channel.</param>
        /// <param name="prettyPrint">Specifies whether to add whitespace to the output text for user readability.</param>
        public Utf8JsonWriter2(TBufferWriter bufferWriter, JsonWriterState state = default)
        {
            _output        = bufferWriter;
            _buffered      = 0;
            BytesCommitted = 0;
            _buffer        = _output.GetSpan();

            _maxDepth       = state._maxDepth == 0 ? JsonWriterState.DefaultMaxDepth : state._maxDepth; // If max depth is not set, revert to the default depth.
            _inObject       = state._inObject;
            _isNotPrimitive = state._isNotPrimitive;
            _tokenType      = state._tokenType;
            _writerOptions  = state._writerOptions;
            _bitStack       = state._bitStack;

            _currentDepth = 0;
        }