pub struct ChunkIter<'a> { /* private fields */ }Expand description
Implementations§
Source§impl<'a> ChunkIter<'a>
impl<'a> ChunkIter<'a>
Sourcepub const fn new(buf: &'a [u8], base: u32) -> Self
pub const fn new(buf: &'a [u8], base: u32) -> Self
Frame the chunks in buf, whose first byte sits at file offset base.
Sourcepub const fn from_cursor(cur: Cursor<'a>) -> Self
pub const fn from_cursor(cur: Cursor<'a>) -> Self
Frame the chunks in a cursor’s remaining bytes.
Sourcepub const fn cursor(&self) -> &Cursor<'a>
pub const fn cursor(&self) -> &Cursor<'a>
The underlying cursor, positioned after the last chunk yielded.
Sourcepub const fn into_cursor(self) -> Cursor<'a>
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.
Sourcepub fn consume(
cur: &mut Cursor<'a>,
ctx: &mut Ctx<'_>,
struct_name: &'static str,
) -> &'a [u8] ⓘ
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.
Sourcepub fn find(
body: &'a [u8],
base: u32,
id: u32,
ctx: &mut Ctx<'_>,
struct_name: &'static str,
) -> Option<Chunk<'a>>
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.
Sourcepub fn next(
&mut self,
ctx: &mut Ctx<'_>,
struct_name: &'static str,
) -> Option<Chunk<'a>>
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.