TupleSpanWriter
Namespace: SnowBank.Data.Tuples.Binary · struct
Buffer for writing tuples into a Span<byte>
Constructors
TupleSpanWriter
TupleSpanWriter(Span<byte> buffer, int depth)
Methods
AdvanceUnsafe
void AdvanceUnsafe(int offset)
Advance the cursor by the given offset
offset— Number of bytes consumed after a previous call to TryGetSpan or TryGetTail
The caller MUST already have validated the size, otherwise the state of the writer could become corrupted!
GetWrittenSpan
ReadOnlySpan<byte> GetWrittenSpan()
Returns a view of the bytes that have been written so far
ToString
string ToString()
TryAdvance
bool TryAdvance(int offset)
Advance the cursor by the given offset, if the buffer is large enough
offset— Number of bytes consumed after a previous call to TryGetSpan or TryGetTail
Returns: true if the buffer was large enough
TryAllocateSpan
bool TryAllocateSpan(int size, out Span<byte> span)
Allocates a span with an exact size
size— Requested sizespan— Span of that size
Returns: true if the buffer was large enough
The cursor will be advanced by exactly bytes
TryGetSpan
bool TryGetSpan(int size, out Span<byte> span)
Gets a span that can fit at least the given minimum capacity
size— Minimum size requestedspan— Receives the remaining space in the buffer, which should be at least of lengthsize
Returns: true if the buffer has enough remaining capacity
This does not advance the cursor. You must call or to "commit" the bytes
TryGetTail
bool TryGetTail(out Span<byte> span)
Gets a span of all the remaining space in the buffer, if it is not full
This does not advance the cursor. You must call or to "commit" the bytes
TryWriteLiteral
bool TryWriteLiteral(byte byte1)
Writes a single-byte literal, and advance the cursor
bool TryWriteLiteral(ReadOnlySpan<byte> bytes)
Writes a bytes literal, and advance the cursor
bool TryWriteLiteral(byte byte1, byte byte2)
Writes a two-bytes literal, and advance the cursor
TryWriteNil
bool TryWriteNil()
Writes a Null element, and advance the cursor
Fields
Buffer
readonly Span<byte> Buffer
Fixed-size buffer
BytesWritten
int BytesWritten
Number of bytes written so far
The next free byte is at BufferBytesWritten
Depth
int Depth
Current depth of the tuple (0 = top)