<PackageReference Include="System.Memory" Version="4.6.2" />

IBufferWriter<T>

public interface IBufferWriter<T>
Represents a sink
void Advance(int count)

Notifies IBufferWriter<T> that count amount of data was written to Span<T>/ Memory<T>

Memory<T> GetMemory(int sizeHint = 0)

Requests the Memory<T> that is at least sizeHint in size if possible, otherwise returns maximum available memory. If sizeHint is equal to 0, currently available memory would get returned.

Span<T> GetSpan(int sizeHint = 0)

Requests the Span<T> that is at least sizeHint in size if possible, otherwise returns maximum available memory. If sizeHint is equal to 0, currently available memory would get returned.