BufferFormatter
Namespace: SnowBank.Buffers · struct
Implements: ISpanBufferWriter<byte>
Helper type for writing binary data into a IBufferWriter of bytes
Constructors
BufferFormatter
BufferFormatter(IBufferWriter<byte> writer)
Constructs a BufferFormatter that will output to the specified IBufferWriter
Methods
Advance
void Advance(int count)
EnsureBytes
Span<byte> EnsureBytes(int count)
Ensures that the buffer can store count additional bytes
count— Number of bytes expected to be written soon.
Returns: Span that maps the corresponding free space in the buffer. The length of the span will be equal to count, even if there are more space available in the buffer.
This does not advance the cursor.
Flush
void Flush()
Flush all pending bytes to the writer
GetSpan
Span<byte> GetSpan(int count)
GetSpanWriter
SpanWriter GetSpanWriter(int count)
Returns a SpanWriter that can be used to populate the next chunk of bytes
WriteByte
void WriteByte(byte value)
Writes a byte to the buffer
void WriteByte(int value)
Writes a byte to the buffer
void WriteByte(char value)
Writes a byte to the buffer
WriteBytes
void WriteBytes(in ReadOnlySpan<byte> bytes)
Writes a span of bytes to the buffer
WriteUInt16
void WriteUInt16(ushort value)
Writes a 16-bit little-endian integer to the buffer
static void WriteUInt16(in Span<byte> span, ushort value)
Writes a 16-bit little-endian integer to the buffer
WriteUInt16BE
void WriteUInt16BE(ushort value)
Writes a 16-bit big-endian integer to the buffer
static void WriteUInt16BE(in Span<byte> span, ushort value)
Writes a 16-bit big-endian integer to the buffer
WriteUInt32
void WriteUInt32(uint value)
Writes a 32-bit little-endian integer to the buffer
static void WriteUInt32(in Span<byte> span, uint value)
Writes a 32-bit little-endian integer to the buffer
WriteUInt32BE
void WriteUInt32BE(uint value)
Writes a 32-bit big-endian integer to the buffer
static void WriteUInt32BE(in Span<byte> span, uint value)
Writes a 32-bit big-endian integer to the buffer
WriteUtf8Text
void WriteUtf8Text(in ReadOnlySpan<char> text)
Writes a string encoded as UTF-8 to the buffer
Fields
Writer
readonly IBufferWriter<byte> Writer
Destination writer