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>
impl<'a> LeReader<'a>
Sourcepub fn new(buf: &'a [u8]) -> Self
pub fn new(buf: &'a [u8]) -> Self
Create a reader over buf, starting at offset 0.
Prefer Self::require when parsing untrusted input.
Sourcepub fn require(
buf: &'a [u8],
structure: &'static str,
need: usize,
) -> Result<Self, BufferTooShort>
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.
Sourcepub fn remaining(&self) -> &'a [u8] ⓘ
pub fn remaining(&self) -> &'a [u8] ⓘ
Return the remaining unread bytes without advancing the cursor.
Sourcepub fn skip(&mut self, count: usize)
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.