Struct ttf_parser::parser::Stream
source · pub struct Stream<'a> {
data: &'a [u8],
offset: usize,
}
Expand description
A streaming binary parser.
Fields§
§data: &'a [u8]
§offset: usize
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.
pub fn read_at_offset16(&mut self, data: &'a [u8]) -> Option<&'a [u8]>
Trait Implementations§
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