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_at_xcdr2(
buf: &'a [u8],
pos: usize,
) -> Result<CdrReader<'a>, DeserError>
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).
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 is_at_origin(&self) -> bool
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’).
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). Under XCDR2 the
alignment is capped at 4 (mirrors CdrWriter::align).
Sourcepub fn version(&self) -> EncodingVersion
pub fn version(&self) -> EncodingVersion
The CDR encoding version parsed from the header.
Sourcepub fn begin_dheader(&mut self) -> Result<DHeaderScope, DeserError>
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.
Sourcepub fn end_dheader(&mut self, scope: DHeaderScope) -> Result<(), DeserError>
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).
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_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.