pub struct CdrWriter<'a> { /* private fields */ }Expand description
CDR writer for serialization.
Handles alignment and endianness for ROS 2 CDR encoding.
Alignment is computed relative to origin — when a 4-byte CDR
header is present, origin = 4 so that fields align correctly
within the payload portion of the buffer.
Implementations§
Source§impl<'a> CdrWriter<'a>
impl<'a> CdrWriter<'a>
Sourcepub fn new_at(buf: &'a mut [u8], pos: usize) -> Result<Self, SerError>
pub fn new_at(buf: &'a mut [u8], pos: usize) -> Result<Self, SerError>
Create a CDR writer positioned at pos bytes into buf.
origin stays at 0, so alignment is computed relative to the start
of buf. Used by FFI bridges that hand us a (origin, cursor, end)
triple where buf = origin..end and the caller’s cursor is pos.
Sourcepub fn new_with_header(buf: &'a mut [u8]) -> Result<Self, SerError>
pub fn new_with_header(buf: &'a mut [u8]) -> Result<Self, SerError>
Create a new CDR writer with the 4-byte encapsulation header.
Writes [0x00, 0x01, 0x00, 0x00] (CDR little-endian) at the start
and sets origin = 4 so subsequent alignment is relative to the
payload, not the header. This is the normal entry point for
serialising ROS 2 messages.
Sourcepub fn align(&mut self, alignment: usize) -> Result<(), SerError>
pub fn align(&mut self, alignment: usize) -> Result<(), SerError>
Align to the given boundary (relative to origin)
Sourcepub fn write_u8(&mut self, value: u8) -> Result<(), SerError>
pub fn write_u8(&mut self, value: u8) -> Result<(), SerError>
Write a single byte without alignment
Sourcepub fn write_bool(&mut self, value: bool) -> Result<(), SerError>
pub fn write_bool(&mut self, value: bool) -> Result<(), SerError>
Write a boolean (serialized as a single byte: 0 = false, 1 = true)
Sourcepub fn write_bytes(&mut self, bytes: &[u8]) -> Result<(), SerError>
pub fn write_bytes(&mut self, bytes: &[u8]) -> Result<(), SerError>
Write bytes without alignment
Sourcepub fn write_u16(&mut self, value: u16) -> Result<(), SerError>
pub fn write_u16(&mut self, value: u16) -> Result<(), SerError>
Write u16 with alignment (little-endian)
Sourcepub fn write_u32(&mut self, value: u32) -> Result<(), SerError>
pub fn write_u32(&mut self, value: u32) -> Result<(), SerError>
Write u32 with alignment (little-endian)
Sourcepub fn write_u64(&mut self, value: u64) -> Result<(), SerError>
pub fn write_u64(&mut self, value: u64) -> Result<(), SerError>
Write u64 with alignment (little-endian)
Sourcepub fn write_i16(&mut self, value: i16) -> Result<(), SerError>
pub fn write_i16(&mut self, value: i16) -> Result<(), SerError>
Write i16 with alignment (little-endian)
Sourcepub fn write_i32(&mut self, value: i32) -> Result<(), SerError>
pub fn write_i32(&mut self, value: i32) -> Result<(), SerError>
Write i32 with alignment (little-endian)
Sourcepub fn write_i64(&mut self, value: i64) -> Result<(), SerError>
pub fn write_i64(&mut self, value: i64) -> Result<(), SerError>
Write i64 with alignment (little-endian)
Sourcepub fn write_f32(&mut self, value: f32) -> Result<(), SerError>
pub fn write_f32(&mut self, value: f32) -> Result<(), SerError>
Write f32 with alignment (little-endian)
Sourcepub fn write_f64(&mut self, value: f64) -> Result<(), SerError>
pub fn write_f64(&mut self, value: f64) -> Result<(), SerError>
Write f64 with alignment (little-endian)