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_at_xcdr2( buf: &'a [u8], pos: usize, ) -> Result<CdrReader<'a>, DeserError>

Like new_at but XCDR2 (DELIMITED_CDR2) — the align cap + begin_dheader read the DHEADER. For the C FFI rx path, which strips the encapsulation header itself (phase-303 W4).

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 is_at_origin(&self) -> bool

Whether nothing has been read yet — the reader still sits on its alignment origin.

CDR alignment is computed as pos - origin, so a caller that re-reads a request by taking the remaining bytes and building a fresh reader over them only gets identical alignment when the slice STARTS at the origin. That is a real precondition with no visible symptom when broken — the padding silently shifts — and origin is private, so this is how a caller checks it. See parameter_services::rewind (phase-382 W1’).

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). Under XCDR2 the alignment is capped at 4 (mirrors CdrWriter::align).

Source

pub fn version(&self) -> EncodingVersion

The CDR encoding version parsed from the header.

Source

pub fn begin_dheader(&mut self) -> Result<DHeaderScope, DeserError>

Begin reading a DHEADER-delimited struct. Under XCDR2, aligns to 4, reads the 4-byte DHEADER size, and returns the absolute buffer position of the struct’s END (so trailing unknown members can be skipped for forward compat). Under XCDR1 this is a NO-OP (returns None) — generated deserialize bodies wrap every struct unconditionally.

Source

pub fn end_dheader(&mut self, scope: DHeaderScope) -> Result<(), DeserError>

Finish a DHEADER-delimited struct: skip any trailing bytes the writer included beyond the members we read (unknown appended members — XCDR2 forward compatibility). No-op under XCDR1. Errors if we OVER-read past the declared end (a corrupt/mismatched stream).

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_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.