raisin::tcp_viewer::BufferReader
struct · #include <rayrai/TcpProtocolReader.hpp>
Lightweight reader for binary message buffers.
The reader maintains a cursor into a byte buffer and provides helpers for reading typed values, strings, and vectors.
Constructors & destructor
BufferReader
explicit BufferReader(const std::vector<char> &data)Construct a reader over an existing byte buffer.
Parameters
| Parameter | Description |
|---|---|
data | Message payload. |
explicit BufferReader(std::vector<char> &&) = deleteRejected: the reader is a non-owning view over data.
Binding a temporary would leave every cursor dangling the moment the constructor returned, and the resulting reads are undefined behaviour that usually "works" because the freed bytes are still intact. Deleting this overload turns that into a compile error; give the buffer a name whose lifetime outlives the reader.
Public member functions
offset
size_t offset() constCurrent offset from the start of the buffer.
Returns Offset in bytes.
size
size_t size() constTotal size of the buffer.
Returns Size in bytes.
remaining
size_t remaining() constRemaining unread bytes.
Returns Remaining byte count.
canReadBytes
bool canReadBytes(size_t count) constCheck if a byte range can be consumed from the current cursor.
Parameters
| Parameter | Description |
|---|---|
count | Byte count. |
Returns True if the range is fully inside the unread payload.
read
template <typename T>
T read()Read a trivially copyable value from the buffer (native byte order).
Template parameters
| Parameter | Description |
|---|---|
T | Value type. |
Returns Parsed value or default-constructed value on failure.
peek
template <typename T>
bool peek(size_t offset, T &out) constPeek a value at a byte offset without advancing the cursor.
Template parameters
| Parameter | Description |
|---|---|
T | Value type. |
Parameters
| Parameter | Description |
|---|---|
offset | Byte offset from current cursor. |
out | Output value. |
Returns True if the value could be read.
readBool
bool readBool()Read a boolean encoded as one byte (non-zero is true).
Returns Boolean value (false on failure).
readString
std::string readString()Read a string prefixed by an int32_t byte length.
A negative or out-of-range length clears ok.
Returns Parsed string (empty on failure).
readVec3f
glm::vec3 readVec3f()Read a vec3 of floats.
Returns Vector value.
readVec4f
glm::vec4 readVec4f()Read a vec4 of floats.
Returns Vector value.
readQuatWxyz
glm::vec4 readQuatWxyz()Read a quaternion encoded as wxyz floats.
Returns Quaternion vector in wxyz order: x holds w, y holds x, z holds y and w holds z, the layout Visuals::setOrientation(const glm::vec4&) takes.
readFloatVector
std::vector<float> readFloatVector()Read a vector of floats with a 32-bit length prefix.
Returns Parsed float vector.
readIntVector
std::vector<int32_t> readIntVector()Read a vector of int32 with a 32-bit length prefix.
Returns Parsed int vector.
readByteVector
std::vector<uint8_t> readByteVector()Read a vector of bytes with a 32-bit length prefix.
Returns Parsed byte vector.
skipBytes
void skipBytes(size_t count)Skip a number of bytes; clears ok if fewer remain.
Parameters
| Parameter | Description |
|---|---|
count | Number of bytes to skip. |
readColorMap
std::vector<raisim::ColorRGB> readColorMap()Read a color map (length-prefixed array of raisim::ColorRGB).
Returns Parsed color map.
skipColorMap
void skipColorMap()Skip a color map payload (length-prefixed).
Public attributes
begin
const char *beginFirst byte of the viewed buffer.
ptr
const char *ptrRead cursor.
end
const char *endOne past the last byte.
ok
bool okSticky error flag; cleared by the first out-of-bounds or malformed read.