chrono::ros::core::CdrWriter Class Reference

Description

Appends CDR-encoded data to a caller-owned byte vector.

The writer appends starting at the vector's current size; existing contents are preserved (this lets a frame header or other prefix precede the body).

#include <ChROSCdr.h>

Public Member Functions

 CdrWriter (std::vector< uint8_t > &out, bool with_encapsulation=true)
 
void WriteBool (bool v)
 
void WriteUInt8 (uint8_t v)
 
void WriteInt8 (int8_t v)
 
void WriteUInt16 (uint16_t v)
 
void WriteInt16 (int16_t v)
 
void WriteUInt32 (uint32_t v)
 
void WriteInt32 (int32_t v)
 
void WriteUInt64 (uint64_t v)
 
void WriteInt64 (int64_t v)
 
void WriteFloat32 (float v)
 
void WriteFloat64 (double v)
 
void WriteString (const std::string &v)
 CDR string: aligned uint32 length (strlen + 1 for NUL) + bytes + NUL. More...
 
void WriteBytes (const void *data, size_t size)
 Raw bytes, no alignment, no length prefix. More...
 
void WriteBlob (const void *data, size_t size)
 Length-prefixed byte blob (uint32 size + raw bytes). More...
 
void Align (size_t alignment)
 Insert zero padding so the next write lands on the given alignment (1, 2, 4 or 8) relative to the encapsulation origin.
 
size_t BytesWritten () const
 Bytes written by this writer so far (excluding pre-existing contents).
 

Constructor & Destructor Documentation

◆ CdrWriter()

chrono::ros::core::CdrWriter::CdrWriter ( std::vector< uint8_t > &  out,
bool  with_encapsulation = true 
)
explicit
Parameters
outbuffer to append to (not owned; must outlive the writer)
with_encapsulationif true, the 4-byte CDR_LE encapsulation header is written first and alignment is computed after it (the ROS 2 wire format). If false, alignment starts at the writer's first byte (used for the bridge's internal control payloads).

Member Function Documentation

◆ WriteBlob()

void chrono::ros::core::CdrWriter::WriteBlob ( const void *  data,
size_t  size 
)

Length-prefixed byte blob (uint32 size + raw bytes).

Convenience for control payloads carrying opaque data (schema blobs, CDR samples).

◆ WriteBytes()

void chrono::ros::core::CdrWriter::WriteBytes ( const void *  data,
size_t  size 
)

Raw bytes, no alignment, no length prefix.

Used for pre-packed little-endian primitive arrays (bulk sensor payloads) after the caller has aligned for the element type, and for nested pre-encoded blobs.

◆ WriteString()

void chrono::ros::core::CdrWriter::WriteString ( const std::string &  v)

CDR string: aligned uint32 length (strlen + 1 for NUL) + bytes + NUL.

Embedded NUL characters are rejected (ROS strings are NUL-terminated on the wire; embedded NULs would be silently truncated by consumers).


The documentation for this class was generated from the following files:
  • /builds/uwsbel/chrono/src/chrono_ros/core/ChROSCdr.h
  • /builds/uwsbel/chrono/src/chrono_ros/core/ChROSCdr.cpp