TupleReader
Namespace: SnowBank.Data.Tuples.Binary · struct
Reads bytes from a contiguous region of arbitrary memory
Constructors
TupleReader
TupleReader(ReadOnlySpan<byte> input, int depth = 0, int cursor = 0)
Properties
HasMore
bool HasMore { get; }
Tests if there is more data remaining in the buffer
Remaining
int Remaining { get; }
Number of bytes remaining in the input buffer
Methods
Advance
void Advance(int bytes)
Advance the cursor by the specified amount of bytes
bytes— Number of bytes to skip
Peek
int Peek()
Peek the next byte in the buffer, without advancing the cursor
Returns: Value of the next byte in the buffer.
PeekAt
int PeekAt(int offset)
Peek at a byte further away in the buffer, without advancing the cursor
offset— Offset (from the cursor) of the byte to return
Returns: Value of the byte at the specified offset from the cursor.
TryReadByteString
bool TryReadByteString(out Range token, out Exception error)
Tries to read an encoded null-terminated byte string (which contains escaped NUL-bytes)
token— Receives the range that starts from the current cursor up until the end of the stringerror— Receives an exception if the string is incomplete
Returns: true if the string was successfully read, or false if the string was truncated, or if there was no more data in the buffer
TryReadBytes
bool TryReadBytes(int count, out Range token, out Exception error)
Tries to read the specified amount of bytes from the buffer
count— Number of bytes to readtoken— Receives the corresponding range in the original buffer, if there was enough byteserror— Receives an exception if there was not enough bytes
Returns: true if the read was successful, in which case token receives the corresponding range and the cursor is advanced by count bytes, or false if there was not enough bytes remaining and error receives an exception that can be re-thrown by the caller.
TryReadNegativeBigInteger
bool TryReadNegativeBigInteger(out Range token, out Exception error)
Tries to read a positive Big Integer
token— Receives the range that starts from the current cursor up until the end of the stringerror— Receives an exception if the string is incomplete
Returns: true if the big integer was successfully read, or false if the string was truncated, or if there was no more data in the buffer
TryReadPositiveBigInteger
bool TryReadPositiveBigInteger(out Range token, out Exception error)
Tries to read a positive Big Integer
token— Receives the range that starts from the current cursor up until the end of the stringerror— Receives an exception if the string is incomplete
Returns: true if the big integer was successfully read, or false if the string was truncated, or if there was no more data in the buffer
UnpackEmbeddedTuple
static TupleReader UnpackEmbeddedTuple(ReadOnlySpan<byte> packed)
Unpack the content of an embedded tuple
packed— Packed tuple (starts with0x02and ends with0x00
Fields
Cursor
int Cursor
Cursor of the next bytes that will be read from Input
Depth
int Depth
Current decoding depth (0 = top level, 1+ = embedded tuple)
Input
readonly ReadOnlySpan<byte> Input
Input buffer containing a packed tuple