<PackageReference Include="System.ClientModel" Version="1.1.0-beta.7" />

UnsafeBufferSequence

This class is a helper to write to a IBufferWriter<T> in a thread safe manner. It uses the shared pool to allocate buffers and returns them to the pool when disposed. Since there is no way to ensure someone didn't keep a reference to one of the buffers it must be disposed of in the same context it was created and its referenced should not be stored or shared.
public UnsafeBufferSequence(int segmentSize = 16384)

Initializes a new instance of UnsafeBufferSequence.

public void Advance(int bytesWritten)

Notifies the UnsafeBufferSequence that bytes bytes were written to the output Span<T> or Memory<T>. You must request a new buffer after calling Advance to continue writing more data; you cannot write to a previously acquired buffer.

public void Dispose()

Disposes the SequenceWriter and returns the underlying buffers to the pool.

public Memory<byte> GetMemory(int sizeHint = 0)

Returns a Memory<T> to write to that is at least the requested size, as specified by the sizeHint parameter.

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

Returns a Span<T> to write to that is at least the requested size, as specified by the sizeHint parameter.