Skip to main content

ChunkIter

Struct ChunkIter 

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

Walks a chunk stream until the terminating zero id or the end of the buffer.

This is not an Iterator: advancing needs a Ctx to report a malformed frame.

Implementations§

Source§

impl<'a> ChunkIter<'a>

Source

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

Frame the chunks in buf, whose first byte sits at file offset base.

Source

pub const fn from_cursor(cur: Cursor<'a>) -> Self

Frame the chunks in a cursor’s remaining bytes.

Source

pub const fn cursor(&self) -> &Cursor<'a>

The underlying cursor, positioned after the last chunk yielded.

Source

pub const fn into_cursor(self) -> Cursor<'a>

Recover the cursor, positioned just past the terminating zero id.

Needed by the indexed-list codec: a list’s elements are chunk streams laid end to end inside one payload with no length prefix of their own, so after reading an element the caller must resume from wherever that element’s terminator left off.

Source

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

Bytes left unread after the stream terminated.

Source

pub fn consume( cur: &mut Cursor<'a>, ctx: &mut Ctx<'_>, struct_name: &'static str, ) -> &'a [u8] ⓘ

Consume a whole chunk stream, returning the span it occupied.

A borrowed iterator would have to be driven to the end before moving on, and silently desynchronises if the caller stops early. Returning the span lets a caller re-walk the element any number of times, for the cost of a skim over the chunk headers.

Source

pub fn find( body: &'a [u8], base: u32, id: u32, ctx: &mut Ctx<'_>, struct_name: &'static str, ) -> Option<Chunk<'a>>

Find one chunk in a stream by id, without allocating.

O(chunks), which is the only option: a chunk stream has no index and its entries are variable-width. Fine for reaching one known field; walk the stream yourself if you want several.

Source

pub fn next( &mut self, ctx: &mut Ctx<'_>, struct_name: &'static str, ) -> Option<Chunk<'a>>

Yield the next chunk.

Returns None on the terminating zero id, at end of input, or once a frame has been found unrecoverable. A chunk whose declared length runs past the end of the buffer is truncated to what is actually there and reported as DiagKind::ChunkOverrun.

Trait Implementations§

Source§

impl<'a> Clone for ChunkIter<'a>

Source§

fn clone(&self) -> Self

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 ChunkIter<'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 ChunkIter<'a>

§

impl<'a> RefUnwindSafe for ChunkIter<'a>

§

impl<'a> Send for ChunkIter<'a>

§

impl<'a> Sync for ChunkIter<'a>

§

impl<'a> Unpin for ChunkIter<'a>

§

impl<'a> UnsafeUnpin for ChunkIter<'a>

§

impl<'a> UnwindSafe for ChunkIter<'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 = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

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.