pub struct ReadCtxt<'a> { /* private fields */ }
Implementations
sourceimpl<'a> ReadCtxt<'a>
impl<'a> ReadCtxt<'a>
pub fn check(&self, cond: bool) -> Result<(), ParseError>
sourcepub fn check_version(&self, cond: bool) -> Result<(), ParseError>
pub fn check_version(&self, cond: bool) -> Result<(), ParseError>
Check a condition, returning ParseError::BadVersion
if false
.
Intended for use in checking versions read from data. Example:
use allsorts::binary::read::ReadScope;
use allsorts::error::ParseError;
let scope = ReadScope::new(&[0, 2]);
let mut ctxt = scope.ctxt();
let major_version = ctxt.read_u16be().expect("unable to read version");
assert!(ctxt.check_version(major_version == 2).is_ok());
assert_eq!(ctxt.check_version(major_version == 1), Err(ParseError::BadVersion));
pub fn scope(&self) -> ReadScope<'a>
pub fn read<T: ReadBinaryDep<'a, Args = ()>>(
&mut self
) -> Result<T::HostType, ParseError>
pub fn read_dep<T: ReadBinaryDep<'a>>(
&mut self,
args: T::Args
) -> Result<T::HostType, ParseError>
pub fn bytes_available(&self) -> bool
pub fn read_u8(&mut self) -> Result<u8, ReadEof>
pub fn read_i8(&mut self) -> Result<i8, ReadEof>
pub fn read_u16be(&mut self) -> Result<u16, ReadEof>
pub fn read_i16be(&mut self) -> Result<i16, ReadEof>
pub fn read_u32be(&mut self) -> Result<u32, ReadEof>
pub fn read_i32be(&mut self) -> Result<i32, ReadEof>
pub fn read_u64be(&mut self) -> Result<u64, ReadEof>
pub fn read_i64be(&mut self) -> Result<i64, ReadEof>
pub fn read_array<T: ReadUnchecked<'a>>(
&mut self,
length: usize
) -> Result<ReadArray<'a, T>, ParseError>
pub fn read_array_upto_hack<T: ReadUnchecked<'a>>(
&mut self,
length: usize
) -> Result<ReadArray<'a, T>, ParseError>
sourcepub fn read_until_nibble(&mut self, nibble: u8) -> Result<&'a [u8], ReadEof>
pub fn read_until_nibble(&mut self, nibble: u8) -> Result<&'a [u8], ReadEof>
Read up to and including the supplied nibble.
pub fn read_array_dep<T: ReadFixedSizeDep<'a>>(
&mut self,
length: usize,
args: T::Args
) -> Result<ReadArray<'a, T>, ParseError>
pub fn read_scope(&mut self, length: usize) -> Result<ReadScope<'a>, ReadEof>
pub fn read_slice(&mut self, length: usize) -> Result<&'a [u8], ReadEof>
Trait Implementations
Auto Trait Implementations
impl<'a> RefUnwindSafe for ReadCtxt<'a>
impl<'a> Send for ReadCtxt<'a>
impl<'a> Sync for ReadCtxt<'a>
impl<'a> Unpin for ReadCtxt<'a>
impl<'a> UnwindSafe for ReadCtxt<'a>
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more