Skip to main content

CdrReader

Struct CdrReader 

Source
pub struct CdrReader<'a> { /* private fields */ }
Expand description

CDR reader for deserialization

Handles alignment and endianness for CDR decoding.

Implementations§

Source§

impl<'a> CdrReader<'a>

Source

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

Create a new CDR reader

Source

pub fn new_at(buf: &'a [u8], pos: usize) -> Result<CdrReader<'a>, DeserError>

Create a CDR reader 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 [u8]) -> Result<CdrReader<'a>, DeserError>

Create a new CDR reader, parsing and validating the encapsulation header

Expects a 4-byte CDR header at the start of the buffer.

Source

pub fn position(&self) -> usize

Get current position in buffer

Source

pub fn remaining(&self) -> usize

Get remaining bytes

Source

pub fn is_empty(&self) -> bool

Check if reader is at end of buffer

Source

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

Align to the given boundary (relative to origin)

Source

pub fn read_u8(&mut self) -> Result<u8, DeserError>

Read a single byte without alignment

Source

pub fn read_bool(&mut self) -> Result<bool, DeserError>

Read a boolean (deserialized from a single byte: 0 = false, non-zero = true)

Source

pub fn read_i8(&mut self) -> Result<i8, DeserError>

Read i8 without alignment

Source

pub fn read_bytes(&mut self, len: usize) -> Result<&'a [u8], DeserError>

Read bytes without alignment

Source

pub fn read_u16(&mut self) -> Result<u16, DeserError>

Read u16 with alignment (little-endian)

Source

pub fn read_u32(&mut self) -> Result<u32, DeserError>

Read u32 with alignment (little-endian)

Source

pub fn read_u64(&mut self) -> Result<u64, DeserError>

Read u64 with alignment (little-endian)

Source

pub fn read_i16(&mut self) -> Result<i16, DeserError>

Read i16 with alignment (little-endian)

Source

pub fn read_i32(&mut self) -> Result<i32, DeserError>

Read i32 with alignment (little-endian)

Source

pub fn read_i64(&mut self) -> Result<i64, DeserError>

Read i64 with alignment (little-endian)

Source

pub fn read_f32(&mut self) -> Result<f32, DeserError>

Read f32 with alignment (little-endian)

Source

pub fn read_f64(&mut self) -> Result<f64, DeserError>

Read f64 with alignment (little-endian)

Source

pub fn read_string(&mut self) -> Result<&'a str, DeserError>

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

Returns a string slice pointing into the buffer (zero-copy).

Source

pub fn read_sequence_len(&mut self) -> Result<usize, DeserError>

Read a sequence length (4-byte count)

Source

pub fn read_slice_u8(&mut self) -> Result<&'a [u8], DeserError>

Read a uint8[] / byte[] sequence as a borrowed slice.

Returns &'a [u8] pointing directly into the CDR buffer. Zero-copy. Reads the 4-byte length prefix, then returns a slice of that length.

Source

pub fn read_slice_i8(&mut self) -> Result<&'a [u8], DeserError>

Read an int8[] sequence as a borrowed slice.

Source

pub fn read_slice_bool(&mut self) -> Result<&'a [u8], DeserError>

Read a bool[] sequence as a borrowed &[u8] slice.

CDR encodes booleans as single bytes (0/1). The returned slice contains raw bytes; the caller interprets 0 as false, non-zero as true.

Source

pub fn read_slice_u16_raw(&mut self) -> Result<(&'a [u8], usize), DeserError>

Read a uint16[] sequence, returning raw bytes and element count.

Returns (byte_slice, element_count). The caller must handle endianness (CDR uses little-endian). For zero-copy on little-endian platforms, the bytes can be cast to &[u16] if properly aligned.

Source

pub fn read_slice_u32_raw(&mut self) -> Result<(&'a [u8], usize), DeserError>

Read a uint32[] sequence, returning raw bytes and element count.

Source

pub fn read_slice_f32_raw(&mut self) -> Result<(&'a [u8], usize), DeserError>

Read a float32[] sequence, returning raw bytes and element count.

Source

pub fn read_slice_f64_raw(&mut self) -> Result<(&'a [u8], usize), DeserError>

Read a float64[] sequence, returning raw bytes and element count.

Source

pub fn read_slice_u64_raw(&mut self) -> Result<(&'a [u8], usize), DeserError>

Read a uint64[] sequence, returning raw bytes and element count.

Source

pub fn read_le_slice<T>(&mut self) -> Result<LeSliceView<'a, T>, DeserError>
where T: LeDecode,

Read a multi-byte numeric sequence (float32[], uint16[], …) as a borrowed LeSliceView — the alignment-agnostic borrowed reader for RFC-0033 borrowed mode (Phase 229.6, issue 0007).

Unlike a &'a [T] cast, this never requires the source buffer to be T-aligned: the view borrows the raw little-endian bytes zero-copy and decodes each element on access via from_le_bytes. Reads the 4-byte length prefix, aligns the reader to T within the CDR stream, then returns a view over len * size_of::<T>() bytes.

Auto Trait Implementations§

§

impl<'a> Freeze for CdrReader<'a>

§

impl<'a> RefUnwindSafe for CdrReader<'a>

§

impl<'a> Send for CdrReader<'a>

§

impl<'a> Sync for CdrReader<'a>

§

impl<'a> Unpin for CdrReader<'a>

§

impl<'a> UnsafeUnpin for CdrReader<'a>

§

impl<'a> UnwindSafe for CdrReader<'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.