DotNext by Roman Sakno

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

 MemoryWriter<T>

public abstract class MemoryWriter<T> : Disposable, IBufferWriter<T>, IConvertible<ReadOnlyMemory<T>>
Represents memory-backed output sink which T data can be written.
public abstract 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 int WrittenCount { get; }

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

public abstract ReadOnlyMemory<T> WrittenMemory { get; }

Gets the data written to the underlying buffer so far.

public void Advance(int count)

Notifies this writer that count of data items were written.

public abstract void Clear()

Clears the data written to the underlying memory.

public abstract Memory<T> GetMemory(int sizeHint = 0)

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

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

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