Skip to main content

CdrWriter

Struct CdrWriter 

Source
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>

Source

pub fn new(buf: &'a mut [u8]) -> CdrWriter<'a>

Create a new CDR writer

Source

pub fn new_at(buf: &'a mut [u8], pos: usize) -> Result<CdrWriter<'a>, 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.

Source

pub fn new_with_header(buf: &'a mut [u8]) -> Result<CdrWriter<'a>, 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.

Source

pub fn position(&self) -> usize

Get current position in buffer

Source

pub fn remaining(&self) -> usize

Get remaining capacity

Source

pub fn as_slice(&self) -> &[u8]

Get the written bytes

Source

pub fn align(&mut self, alignment: usize) -> Result<(), SerError>

Align to the given boundary (relative to origin)

Source

pub fn write_u8(&mut self, value: u8) -> Result<(), SerError>

Write a single byte without alignment

Source

pub fn write_bool(&mut self, value: bool) -> Result<(), SerError>

Write a boolean (serialized as a single byte: 0 = false, 1 = true)

Source

pub fn write_i8(&mut self, value: i8) -> Result<(), SerError>

Write i8 without alignment

Source

pub fn write_bytes(&mut self, bytes: &[u8]) -> Result<(), SerError>

Write bytes without alignment

Source

pub fn write_u16(&mut self, value: u16) -> Result<(), SerError>

Write u16 with alignment (little-endian)

Source

pub fn write_u32(&mut self, value: u32) -> Result<(), SerError>

Write u32 with alignment (little-endian)

Source

pub fn write_u64(&mut self, value: u64) -> Result<(), SerError>

Write u64 with alignment (little-endian)

Source

pub fn write_i16(&mut self, value: i16) -> Result<(), SerError>

Write i16 with alignment (little-endian)

Source

pub fn write_i32(&mut self, value: i32) -> Result<(), SerError>

Write i32 with alignment (little-endian)

Source

pub fn write_i64(&mut self, value: i64) -> Result<(), SerError>

Write i64 with alignment (little-endian)

Source

pub fn write_f32(&mut self, value: f32) -> Result<(), SerError>

Write f32 with alignment (little-endian)

Source

pub fn write_f64(&mut self, value: f64) -> Result<(), SerError>

Write f64 with alignment (little-endian)

Source

pub fn write_string(&mut self, s: &str) -> Result<(), SerError>

Write a CDR string (4-byte length including null + data + null terminator)

Source

pub fn write_sequence_len(&mut self, len: usize) -> Result<(), SerError>

Write a sequence length (4-byte count)

Auto Trait Implementations§

§

impl<'a> Freeze for CdrWriter<'a>

§

impl<'a> RefUnwindSafe for CdrWriter<'a>

§

impl<'a> Send for CdrWriter<'a>

§

impl<'a> Sync for CdrWriter<'a>

§

impl<'a> Unpin for CdrWriter<'a>

§

impl<'a> UnsafeUnpin for CdrWriter<'a>

§

impl<'a> !UnwindSafe for CdrWriter<'a>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.