pub struct View<'a> { /* private fields */ }Expand description
A bounded window over one address space.
The readable bytes are held as the slice itself, so View::window is a
field read with no range to recompute, and the bytes the cursor has not
passed are held as a suffix of that slice, so View::unread,
View::remaining and View::take are slice operations with no offset
to recompute. start and end place the window in the space:
end - start == window.len(), and unread is a suffix of window for
every view. The two constructors are the only places those bounds are
proven — over_space takes a whole buffer, and child carves the
sub-slice with the same get that bounds the child.
end restates start + window.len(). This file denies
clippy::arithmetic_side_effects and usize states no total addition, so
every spelling of View::end that derives the bound is either that
denied + or a checked_add whose None no view can reach. The bound is
therefore stored, and over_space and child are the only places it is
proven.
Implementations§
Source§impl<'a> View<'a>
impl<'a> View<'a>
Sourcepub fn over_retained(bytes: &'a [u8]) -> View<'a>
pub fn over_retained(bytes: &'a [u8]) -> View<'a>
Bounded window over retained bytes that left the live space chain.
Prefer views returned by DecodeContext. This
constructor exists for opportunistic scanners over owned payloads that
were copied out of the arena; locations report SpaceId::ROOT.
Sourcepub fn read_len(self) -> usize
pub fn read_len(self) -> usize
Returns the window offset of the current position.
Every view holds the unread bytes as a suffix of the window, so the
bytes already read are the rest of it. abs_diff is total at that
count: unread is never longer than window.
Sourcepub fn unread(self) -> &'a [u8] ⓘ
pub fn unread(self) -> &'a [u8] ⓘ
Returns the unread bytes of the window.
The cursor is the split of the window, so this is a field read.
Sourcepub fn location(self) -> SourceLocation
pub fn location(self) -> SourceLocation
Returns this view’s current source location.
Sourcepub fn location_at(self, offset: usize) -> SourceLocation
pub fn location_at(self, offset: usize) -> SourceLocation
Returns a source location at an absolute offset in this view’s space.
Sourcepub fn take(&mut self, count: usize) -> Option<&'a [u8]>
pub fn take(&mut self, count: usize) -> Option<&'a [u8]>
Takes count bytes, advancing only on success.
The unread slice is the upper bound: split_at_checked refuses a count
the unread bytes cannot serve, so no separate end test stands beside
it, and the cursor moves only when the split holds.
Sourcepub fn array<const N: usize>(&mut self) -> Option<[u8; N]>
pub fn array<const N: usize>(&mut self) -> Option<[u8; N]>
Takes a fixed-size byte array, advancing only on success.
Sourcepub fn seek(&mut self, position: usize) -> Option<()>
pub fn seek(&mut self, position: usize) -> Option<()>
Moves to an absolute offset, honoring the stored lower bound.
The window states both bounds: offset_of refuses a position under the
window’s own start, and get refuses one past its end.
Sourcepub fn seek_to_end(&mut self)
pub fn seek_to_end(&mut self)
Moves the cursor to the window’s exclusive upper bound.
This is the one seek the window proves at construction. seek(end)
reads offset_of(end), which is the window length, and the suffix of a
slice at its own length is the empty slice, so neither bound of seek
can refuse it. The suffix is taken from window itself: split_at is
total for every mid <= len by its own contract, and the mid here is
that length, so the invariant that unread is a suffix of window
holds by derivation and the move states no refusal to thread.
remaining is then 0, read_len the whole window, and position the
stored end.
Sourcepub fn child(self, start: usize, end: usize) -> Option<View<'a>>
pub fn child(self, start: usize, end: usize) -> Option<View<'a>>
Returns an exactly contained child window.
The containment test is the sub-slice itself: offset_of refuses a
lower bound under this window’s own, and get refuses an inverted
range or an upper bound past this window’s end.
Sourcepub fn counted(
self,
count: u64,
min_element_size: usize,
) -> Option<BoundedCount>
pub fn counted( self, count: u64, min_element_size: usize, ) -> Option<BoundedCount>
Proves a declared element count could fit in the unread bytes.
Sourcepub fn req_take(&mut self, count: usize) -> Result<&'a [u8], ParseError>
pub fn req_take(&mut self, count: usize) -> Result<&'a [u8], ParseError>
Required-read mirror of View::take.
Sourcepub fn req_take_child(&mut self, count: usize) -> Result<View<'a>, ParseError>
pub fn req_take_child(&mut self, count: usize) -> Result<View<'a>, ParseError>
Takes count bytes as a bounded child window, or states the truncation.
The child window carries the same bounds and space as the optional take
this mirrors: View::start of the result is the position the take
began at and View::end is the position it reached. The view states
the same located truncation as View::req_take for the same count,
and leaves the view unmoved when it does.
Source§impl View<'_>
impl View<'_>
Sourcepub fn req_u16_le(&mut self) -> Result<u16, ParseError>
pub fn req_u16_le(&mut self) -> Result<u16, ParseError>
Required-read mirror of View::u16_le.
Sourcepub fn u16_le_at(bytes: &[u8], offset: usize) -> Option<u16>
pub fn u16_le_at(bytes: &[u8], offset: usize) -> Option<u16>
Offset probe of a u16 over retained bytes. Sequential readers should keep a live View and call View::u16_le instead.
Sourcepub fn req_i16_le(&mut self) -> Result<i16, ParseError>
pub fn req_i16_le(&mut self) -> Result<i16, ParseError>
Required-read mirror of View::i16_le.
Sourcepub fn i16_le_at(bytes: &[u8], offset: usize) -> Option<i16>
pub fn i16_le_at(bytes: &[u8], offset: usize) -> Option<i16>
Offset probe of a i16 over retained bytes. Sequential readers should keep a live View and call View::i16_le instead.
Sourcepub fn req_u32_le(&mut self) -> Result<u32, ParseError>
pub fn req_u32_le(&mut self) -> Result<u32, ParseError>
Required-read mirror of View::u32_le.
Sourcepub fn u32_le_at(bytes: &[u8], offset: usize) -> Option<u32>
pub fn u32_le_at(bytes: &[u8], offset: usize) -> Option<u32>
Offset probe of a u32 over retained bytes. Sequential readers should keep a live View and call View::u32_le instead.
Sourcepub fn req_i32_le(&mut self) -> Result<i32, ParseError>
pub fn req_i32_le(&mut self) -> Result<i32, ParseError>
Required-read mirror of View::i32_le.
Sourcepub fn i32_le_at(bytes: &[u8], offset: usize) -> Option<i32>
pub fn i32_le_at(bytes: &[u8], offset: usize) -> Option<i32>
Offset probe of a i32 over retained bytes. Sequential readers should keep a live View and call View::i32_le instead.
Sourcepub fn req_u64_le(&mut self) -> Result<u64, ParseError>
pub fn req_u64_le(&mut self) -> Result<u64, ParseError>
Required-read mirror of View::u64_le.
Sourcepub fn u64_le_at(bytes: &[u8], offset: usize) -> Option<u64>
pub fn u64_le_at(bytes: &[u8], offset: usize) -> Option<u64>
Offset probe of a u64 over retained bytes. Sequential readers should keep a live View and call View::u64_le instead.
Sourcepub fn req_i64_le(&mut self) -> Result<i64, ParseError>
pub fn req_i64_le(&mut self) -> Result<i64, ParseError>
Required-read mirror of View::i64_le.
Sourcepub fn i64_le_at(bytes: &[u8], offset: usize) -> Option<i64>
pub fn i64_le_at(bytes: &[u8], offset: usize) -> Option<i64>
Offset probe of a i64 over retained bytes. Sequential readers should keep a live View and call View::i64_le instead.
Sourcepub fn req_f32_le(&mut self) -> Result<f32, ParseError>
pub fn req_f32_le(&mut self) -> Result<f32, ParseError>
Required-read mirror of View::f32_le.
Sourcepub fn f32_le_at(bytes: &[u8], offset: usize) -> Option<f32>
pub fn f32_le_at(bytes: &[u8], offset: usize) -> Option<f32>
Offset probe of a f32 over retained bytes. Sequential readers should keep a live View and call View::f32_le instead.
Sourcepub fn req_f64_le(&mut self) -> Result<f64, ParseError>
pub fn req_f64_le(&mut self) -> Result<f64, ParseError>
Required-read mirror of View::f64_le.
Sourcepub fn f64_le_at(bytes: &[u8], offset: usize) -> Option<f64>
pub fn f64_le_at(bytes: &[u8], offset: usize) -> Option<f64>
Offset probe of a f64 over retained bytes. Sequential readers should keep a live View and call View::f64_le instead.
Sourcepub fn u16_be_at(bytes: &[u8], offset: usize) -> Option<u16>
pub fn u16_be_at(bytes: &[u8], offset: usize) -> Option<u16>
Offset probe of a u16 over retained bytes. Sequential readers should keep a live View and call View::u16_be instead.
Sourcepub fn i16_be_at(bytes: &[u8], offset: usize) -> Option<i16>
pub fn i16_be_at(bytes: &[u8], offset: usize) -> Option<i16>
Offset probe of a i16 over retained bytes. Sequential readers should keep a live View and call View::i16_be instead.
Sourcepub fn req_u32_be(&mut self) -> Result<u32, ParseError>
pub fn req_u32_be(&mut self) -> Result<u32, ParseError>
Required-read mirror of View::u32_be.
Sourcepub fn u32_be_at(bytes: &[u8], offset: usize) -> Option<u32>
pub fn u32_be_at(bytes: &[u8], offset: usize) -> Option<u32>
Offset probe of a u32 over retained bytes. Sequential readers should keep a live View and call View::u32_be instead.
Sourcepub fn u64_be_at(bytes: &[u8], offset: usize) -> Option<u64>
pub fn u64_be_at(bytes: &[u8], offset: usize) -> Option<u64>
Offset probe of a u64 over retained bytes. Sequential readers should keep a live View and call View::u64_be instead.
Sourcepub fn req_f32_be(&mut self) -> Result<f32, ParseError>
pub fn req_f32_be(&mut self) -> Result<f32, ParseError>
Required-read mirror of View::f32_be.