/// the <see cref="Utf8JsonWriter"/> which indicates whether to format the output
/// while writing and whether to skip structural JSON validation or not.
/// </summary>
- public JsonWriterOptions Options
- {
- get
- {
- return _options;
- }
- }
+ public JsonWriterOptions Options => _options;
private int Indentation => CurrentDepth * JsonConstants.SpacesPerIndent;
public Utf8JsonWriter(IBufferWriter<byte> bufferWriter, JsonWriterOptions options = default)
{
_output = bufferWriter ?? throw new ArgumentNullException(nameof(bufferWriter));
- _stream = default;
- _arrayBufferWriter = default;
-
- BytesPending = default;
- BytesCommitted = default;
- _memory = default;
-
- _inObject = default;
- _tokenType = default;
- _currentDepth = default;
_options = options;
-
- // Only allocate if the user writes a JSON payload beyond the depth that the _allocationFreeContainer can handle.
- // This way we avoid allocations in the common, default cases, and allocate lazily.
- _bitStack = default;
}
/// <summary>
throw new ArgumentException(SR.StreamNotWritable);
_stream = utf8Json;
- _arrayBufferWriter = new ArrayBufferWriter<byte>();
- _output = default;
-
- BytesPending = default;
- BytesCommitted = default;
- _memory = default;
-
- _inObject = default;
- _tokenType = default;
- _currentDepth = default;
_options = options;
-
- // Only allocate if the user writes a JSON payload beyond the depth that the _allocationFreeContainer can handle.
- // This way we avoid allocations in the common, default cases, and allocate lazily.
- _bitStack = default;
+ _arrayBufferWriter = new ArrayBufferWriter<byte>();
}
/// <summary>
_tokenType = default;
_currentDepth = default;
- // Only allocate if the user writes a JSON payload beyond the depth that the _allocationFreeContainer can handle.
- // This way we avoid allocations in the common, default cases, and allocate lazily.
_bitStack = default;
}