pub struct Stream<'a> { /* private fields */ }
Expand description
A streaming binary parser.
Implementations§
Source§impl<'a> Stream<'a>
impl<'a> Stream<'a>
Sourcepub fn new_at(data: &'a [u8], offset: usize) -> Option<Self>
pub fn new_at(data: &'a [u8], offset: usize) -> Option<Self>
Creates a new Stream
parser at offset.
Returns None
when offset
is out of bounds.
Sourcepub fn jump_to_end(&mut self)
pub fn jump_to_end(&mut self)
Jumps to the end of the stream.
Useful to indicate that we parsed all the data.
Sourcepub fn tail(&self) -> Option<&'a [u8]>
pub fn tail(&self) -> Option<&'a [u8]>
Returns the trailing data.
Returns None
when Stream
is reached the end.
Sourcepub fn advance_checked(&mut self, len: usize) -> Option<()>
pub fn advance_checked(&mut self, len: usize) -> Option<()>
Advances by the specified len
and checks for bounds.
Sourcepub fn read<T: FromData>(&mut self) -> Option<T>
pub fn read<T: FromData>(&mut self) -> Option<T>
Parses the type from the steam.
Returns None
when there is not enough data left in the stream
or the type parsing failed.
Sourcepub fn read_at<T: FromData>(data: &[u8], offset: usize) -> Option<T>
pub fn read_at<T: FromData>(data: &[u8], offset: usize) -> Option<T>
Parses the type from the steam at offset.
Sourcepub fn read_bytes(&mut self, len: usize) -> Option<&'a [u8]>
pub fn read_bytes(&mut self, len: usize) -> Option<&'a [u8]>
Reads N bytes from the stream.
Sourcepub fn read_array16<T: FromData>(
&mut self,
count: u16,
) -> Option<LazyArray16<'a, T>>
pub fn read_array16<T: FromData>( &mut self, count: u16, ) -> Option<LazyArray16<'a, T>>
Reads the next count
types as a slice.
Sourcepub fn read_array32<T: FromData>(
&mut self,
count: u32,
) -> Option<LazyArray32<'a, T>>
pub fn read_array32<T: FromData>( &mut self, count: u32, ) -> Option<LazyArray32<'a, T>>
Reads the next count
types as a slice.
Trait Implementations§
impl<'a> Copy for Stream<'a>
Auto Trait Implementations§
impl<'a> Freeze for Stream<'a>
impl<'a> RefUnwindSafe for Stream<'a>
impl<'a> Send for Stream<'a>
impl<'a> Sync for Stream<'a>
impl<'a> Unpin for Stream<'a>
impl<'a> UnwindSafe for Stream<'a>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§unsafe fn clone_to_uninit(&self, dst: *mut T)
unsafe fn clone_to_uninit(&self, dst: *mut T)
🔬This is a nightly-only experimental API. (
clone_to_uninit
)