DotNext by Roman Sakno

<PackageReference Include="DotNext" Version="2.12.0" />

 BufferWriterSlim<T>

public struct BufferWriterSlim<T>
Represents stack-allocated buffer builder.
public int Capacity { get; }

Gets the total amount of space within the underlying memory.

public int FreeCapacity { get; }

Gets the amount of space available that can still be written into without forcing the underlying buffer to grow.

public ref T this[int index] { get; }

Gets the element at the specified zero-based index within this builder.

public int WrittenCount { get; }

Gets the amount of data written to the underlying memory so far.

public ReadOnlySpan<T> WrittenSpan { get; }

Gets span over constructed memory block.

public BufferWriterSlim(Span<T> buffer, bool copyOnOverflow, MemoryAllocator<T> allocator = null)

Initializes growable builder.

public void Add(T item)

Adds single element to this builder.

public void Clear(bool reuseBuffer)

lears the data written to the underlying buffer.

public void CopyTo(IBufferWriter<T> output)

Copies written content to the specified buffer writer.

public void CopyTo<TArg>(ReadOnlySpanAction<T, TArg> action, TArg arg)

Transfers written content to the specified callback.

public int CopyTo(ref SpanWriter output)

Copies written content.

public int CopyTo(Span<T> output)

Copies written content to the specified span.

public void Dispose()

Releases internal buffer used by this builder.

public void Write(ReadOnlySpan<T> input)

Writes elements to this buffer.