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>
impl<'a> CdrReader<'a>
Sourcepub fn new_at(buf: &'a [u8], pos: usize) -> Result<CdrReader<'a>, DeserError>
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.
Sourcepub fn new_with_header(buf: &'a [u8]) -> Result<CdrReader<'a>, DeserError>
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.
Sourcepub fn align(&mut self, alignment: usize) -> Result<(), DeserError>
pub fn align(&mut self, alignment: usize) -> Result<(), DeserError>
Align to the given boundary (relative to origin)
Sourcepub fn read_u8(&mut self) -> Result<u8, DeserError>
pub fn read_u8(&mut self) -> Result<u8, DeserError>
Read a single byte without alignment
Sourcepub fn read_bool(&mut self) -> Result<bool, DeserError>
pub fn read_bool(&mut self) -> Result<bool, DeserError>
Read a boolean (deserialized from a single byte: 0 = false, non-zero = true)
Sourcepub fn read_i8(&mut self) -> Result<i8, DeserError>
pub fn read_i8(&mut self) -> Result<i8, DeserError>
Read i8 without alignment
Sourcepub fn read_bytes(&mut self, len: usize) -> Result<&'a [u8], DeserError>
pub fn read_bytes(&mut self, len: usize) -> Result<&'a [u8], DeserError>
Read bytes without alignment
Sourcepub fn read_u16(&mut self) -> Result<u16, DeserError>
pub fn read_u16(&mut self) -> Result<u16, DeserError>
Read u16 with alignment (little-endian)
Sourcepub fn read_u32(&mut self) -> Result<u32, DeserError>
pub fn read_u32(&mut self) -> Result<u32, DeserError>
Read u32 with alignment (little-endian)
Sourcepub fn read_u64(&mut self) -> Result<u64, DeserError>
pub fn read_u64(&mut self) -> Result<u64, DeserError>
Read u64 with alignment (little-endian)
Sourcepub fn read_i16(&mut self) -> Result<i16, DeserError>
pub fn read_i16(&mut self) -> Result<i16, DeserError>
Read i16 with alignment (little-endian)
Sourcepub fn read_i32(&mut self) -> Result<i32, DeserError>
pub fn read_i32(&mut self) -> Result<i32, DeserError>
Read i32 with alignment (little-endian)
Sourcepub fn read_i64(&mut self) -> Result<i64, DeserError>
pub fn read_i64(&mut self) -> Result<i64, DeserError>
Read i64 with alignment (little-endian)
Sourcepub fn read_f32(&mut self) -> Result<f32, DeserError>
pub fn read_f32(&mut self) -> Result<f32, DeserError>
Read f32 with alignment (little-endian)
Sourcepub fn read_f64(&mut self) -> Result<f64, DeserError>
pub fn read_f64(&mut self) -> Result<f64, DeserError>
Read f64 with alignment (little-endian)
Sourcepub fn read_string(&mut self) -> Result<&'a str, DeserError>
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).
Sourcepub fn read_sequence_len(&mut self) -> Result<usize, DeserError>
pub fn read_sequence_len(&mut self) -> Result<usize, DeserError>
Read a sequence length (4-byte count)
Sourcepub fn read_slice_u8(&mut self) -> Result<&'a [u8], DeserError>
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.
Sourcepub fn read_slice_i8(&mut self) -> Result<&'a [u8], DeserError>
pub fn read_slice_i8(&mut self) -> Result<&'a [u8], DeserError>
Read an int8[] sequence as a borrowed slice.
Sourcepub fn read_slice_bool(&mut self) -> Result<&'a [u8], DeserError>
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.
Sourcepub fn read_slice_u16_raw(&mut self) -> Result<(&'a [u8], usize), DeserError>
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.
Sourcepub fn read_slice_u32_raw(&mut self) -> Result<(&'a [u8], usize), DeserError>
pub fn read_slice_u32_raw(&mut self) -> Result<(&'a [u8], usize), DeserError>
Read a uint32[] sequence, returning raw bytes and element count.
Sourcepub fn read_slice_f32_raw(&mut self) -> Result<(&'a [u8], usize), DeserError>
pub fn read_slice_f32_raw(&mut self) -> Result<(&'a [u8], usize), DeserError>
Read a float32[] sequence, returning raw bytes and element count.
Sourcepub fn read_slice_f64_raw(&mut self) -> Result<(&'a [u8], usize), DeserError>
pub fn read_slice_f64_raw(&mut self) -> Result<(&'a [u8], usize), DeserError>
Read a float64[] sequence, returning raw bytes and element count.
Sourcepub fn read_slice_u64_raw(&mut self) -> Result<(&'a [u8], usize), DeserError>
pub fn read_slice_u64_raw(&mut self) -> Result<(&'a [u8], usize), DeserError>
Read a uint64[] sequence, returning raw bytes and element count.
Sourcepub fn read_le_slice<T>(&mut self) -> Result<LeSliceView<'a, T>, DeserError>where
T: LeDecode,
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.