Skip to content

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 ​

cpp
explicit BufferReader(const std::vector<char> &data)

Construct a reader over an existing byte buffer.

Parameters

ParameterDescription
dataMessage payload.
cpp
explicit BufferReader(std::vector<char> &&) = delete

Rejected: 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 ​

cpp
size_t offset() const

Current offset from the start of the buffer.

Returns Offset in bytes.

size ​

cpp
size_t size() const

Total size of the buffer.

Returns Size in bytes.

remaining ​

cpp
size_t remaining() const

Remaining unread bytes.

Returns Remaining byte count.

canReadBytes ​

cpp
bool canReadBytes(size_t count) const

Check if a byte range can be consumed from the current cursor.

Parameters

ParameterDescription
countByte count.

Returns True if the range is fully inside the unread payload.

read ​

cpp
template <typename T>
T read()

Read a trivially copyable value from the buffer (native byte order).

Template parameters

ParameterDescription
TValue type.

Returns Parsed value or default-constructed value on failure.

peek ​

cpp
template <typename T>
bool peek(size_t offset, T &out) const

Peek a value at a byte offset without advancing the cursor.

Template parameters

ParameterDescription
TValue type.

Parameters

ParameterDescription
offsetByte offset from current cursor.
outOutput value.

Returns True if the value could be read.

readBool ​

cpp
bool readBool()

Read a boolean encoded as one byte (non-zero is true).

Returns Boolean value (false on failure).

readString ​

cpp
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 ​

cpp
glm::vec3 readVec3f()

Read a vec3 of floats.

Returns Vector value.

readVec4f ​

cpp
glm::vec4 readVec4f()

Read a vec4 of floats.

Returns Vector value.

readQuatWxyz ​

cpp
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 ​

cpp
std::vector<float> readFloatVector()

Read a vector of floats with a 32-bit length prefix.

Returns Parsed float vector.

readIntVector ​

cpp
std::vector<int32_t> readIntVector()

Read a vector of int32 with a 32-bit length prefix.

Returns Parsed int vector.

readByteVector ​

cpp
std::vector<uint8_t> readByteVector()

Read a vector of bytes with a 32-bit length prefix.

Returns Parsed byte vector.

skipBytes ​

cpp
void skipBytes(size_t count)

Skip a number of bytes; clears ok if fewer remain.

Parameters

ParameterDescription
countNumber of bytes to skip.

readColorMap ​

cpp
std::vector<raisim::ColorRGB> readColorMap()

Read a color map (length-prefixed array of raisim::ColorRGB).

Returns Parsed color map.

skipColorMap ​

cpp
void skipColorMap()

Skip a color map payload (length-prefixed).

Public attributes ​

begin ​

cpp
const char *begin

First byte of the viewed buffer.

ptr ​

cpp
const char *ptr

Read cursor.

end ​

cpp
const char *end

One past the last byte.

ok ​

cpp
bool ok

Sticky error flag; cleared by the first out-of-bounds or malformed read.

RaiSim — physics for robotics and AI.