Skip to main content

BufferReader

Struct BufferReader 

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

Read buffer with alignment tracking.

Implementations§

Source§

impl<'a> BufferReader<'a>

Source

pub fn new(bytes: &'a [u8], endianness: Endianness) -> Self

Constructs a reader over the given slice (XCDR1 cap 8).

Source

pub fn with_align_origin(self, origin: usize) -> Self

Builder: sets the virtual Self::align origin (default 0). For GIOP 1.2 = 12 (header size), MUST match the encode side.

Source

pub fn with_max_alignment(self, max_alignment: usize) -> Self

Builder: sets the alignment cap (XCDR1=8, XCDR2=4). Inherited by nested member readers.

Source

pub fn xcdr2(self) -> Self

Builder: switches to XCDR2 alignment (cap 4, §7.4.1.1.1).

Source

pub fn max_alignment(&self) -> usize

The current alignment cap (8 = XCDR1, 4 = XCDR2).

Source

pub fn endianness(&self) -> Endianness

Current endianness.

Source

pub fn position(&self) -> usize

Current position in the stream.

Source

pub fn remaining(&self) -> usize

Remaining bytes until the end.

Source

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

Skips padding until the next alignment boundary.

§Errors

UnexpectedEof when not enough bytes remain for the padding.

Source

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

Reads exactly n bytes as a slice (without alignment).

§Errors

UnexpectedEof.

Source

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

Reads a single byte.

§Errors

UnexpectedEof.

Source

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

Aligns + reads u16.

§Errors

UnexpectedEof.

Source

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

Aligns + reads u32.

§Errors

UnexpectedEof.

Source

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

Aligns + reads u64.

§Errors

UnexpectedEof.

Source

pub fn read_string(&mut self) -> Result<String, DecodeError>

Reads a CDR string (§9.3.2.7): 4-byte length (incl. null terminator) + UTF-8 bytes + 1 null byte. Returns the string without the terminator.

§Errors

UnexpectedEof for too-short data; InvalidData for non-UTF-8 bytes, a missing null terminator, or length == 0.

Trait Implementations§

Source§

impl<'a> Clone for BufferReader<'a>

Source§

fn clone(&self) -> BufferReader<'a>

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<'a> Debug for BufferReader<'a>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<'a> Freeze for BufferReader<'a>

§

impl<'a> RefUnwindSafe for BufferReader<'a>

§

impl<'a> Send for BufferReader<'a>

§

impl<'a> Sync for BufferReader<'a>

§

impl<'a> Unpin for BufferReader<'a>

§

impl<'a> UnsafeUnpin for BufferReader<'a>

§

impl<'a> UnwindSafe for BufferReader<'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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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.