DotNext by Roman Sakno

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

 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, MemoryAllocator<T> allocator = null)

Initializes growable buffer.

public BufferWriterSlim(int initialCapacity, MemoryAllocator<T> allocator = null)

Initializes growable buffer.

public void Add(T item)

Adds single element to this builder.

public void Advance(int count)

Notifies this writer that count of data items were written.

public void Clear(bool reuseBuffer)

lears the data written to the underlying buffer.

public void Dispose()

Releases internal buffer used by this builder.

public Span<T> GetSpan(int sizeHint = 0)

Returns the memory to write to that is at least the requested size.

public bool TryDetachBuffer(out MemoryOwner owner)

Detaches the underlying buffer with written content from this writer.

public void Write(ReadOnlySpan<T> input)

Writes elements to this buffer.