Skip to main content

LeReader

Struct LeReader 

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

Cursor that reads little-endian primitives from a byte slice.

Length is validated once by the caller (via LeReader::require); the typed readers then advance without returning per-field errors. This keeps fixed-layout parsers concise while making the initial size check explicit.

Implementations§

Source§

impl<'a> LeReader<'a>

Source

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

Create a reader over buf, starting at offset 0.

Prefer Self::require when parsing untrusted input.

Source

pub fn require( buf: &'a [u8], structure: &'static str, need: usize, ) -> Result<Self, BufferTooShort>

Ensure buf holds at least need bytes for structure.

§Errors

Returns BufferTooShort when buf.len() < need.

Source

pub fn position(&self) -> usize

Current read offset.

Source

pub fn remaining(&self) -> &'a [u8]

Return the remaining unread bytes without advancing the cursor.

Source

pub fn take_4(&mut self) -> [u8; 4]

Read a fixed 4-byte array (for example, a magic tag).

§Panics

Panics if fewer than 4 bytes remain.

Source

pub fn take_16(&mut self) -> [u8; 16]

Read a fixed 16-byte array (for example, a UUID).

§Panics

Panics if fewer than 16 bytes remain.

Source

pub fn take_u16(&mut self) -> u16

Read a little-endian u16.

§Panics

Panics if fewer than 2 bytes remain.

Source

pub fn take_u32(&mut self) -> u32

Read a little-endian u32.

§Panics

Panics if fewer than 4 bytes remain.

Source

pub fn take_u64(&mut self) -> u64

Read a little-endian u64.

§Panics

Panics if fewer than 8 bytes remain.

Source

pub fn skip(&mut self, count: usize)

Advance over count bytes, typically reserved fields.

The bounds failure is observed by the next method that slices the buffer, or immediately by Self::remaining.

§Panics

Addition overflows only for unrealistically large count values.

Trait Implementations§

Source§

impl<'a> Debug for LeReader<'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 LeReader<'a>

§

impl<'a> RefUnwindSafe for LeReader<'a>

§

impl<'a> Send for LeReader<'a>

§

impl<'a> Sync for LeReader<'a>

§

impl<'a> Unpin for LeReader<'a>

§

impl<'a> UnsafeUnpin for LeReader<'a>

§

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