[−][src]Struct cjdns_bytes::Reader
Buffer reader
Implementations
impl<'a> Reader<'a>
[src]
pub fn new(data: &'a [u8]) -> Self
[src]
Instantiates Reader
.
pub fn read<R, F: FnOnce(&mut Self) -> Result<R, InsufficientBuffer>>(
&mut self,
expected_size: ExpectedSize,
job: F
) -> Result<R, ReadError>
[src]
&mut self,
expected_size: ExpectedSize,
job: F
) -> Result<R, ReadError>
Reads bytes in accordance to logic implemented in job
.
If expected_size
check fails (i.e. readers size does not apply to expected condition), ReaderError
is returned.
Panics
job
closure is used to encapsulate multiple reads from Reader
. Data reads in job
must be infallible: they should coordinate with the
expected size. So if too much than could be or less than stated in expected_size
was read, it finishes with panic.
pub fn read_u8(&mut self) -> Result<u8, InsufficientBuffer>
[src]
Reads u8
pub fn read_u16_be(&mut self) -> Result<u16, InsufficientBuffer>
[src]
Reads big endian u16
pub fn read_u32_be(&mut self) -> Result<u32, InsufficientBuffer>
[src]
Reads big endian u32
pub fn read_u64_be(&mut self) -> Result<u64, InsufficientBuffer>
[src]
Reads big endian u64
pub fn read_array_32(&mut self) -> Result<[u8; 32], InsufficientBuffer>
[src]
Reads [u8; 32]
array.
pub fn peek_remainder(&self) -> &'a [u8]
[src]
Peeks remainder without mutating readers state
pub fn read_remainder(&mut self) -> &'a [u8]
[src]
Returns remainder mutating readers state.
pub fn skip(&mut self, count: usize) -> Result<(), InsufficientBuffer>
[src]
Skips count
amount of data.
pub fn read_slice(
&mut self,
count: usize
) -> Result<&'a [u8], InsufficientBuffer>
[src]
&mut self,
count: usize
) -> Result<&'a [u8], InsufficientBuffer>
Reads count
values.
pub fn is_empty(&self) -> bool
[src]
Auto Trait Implementations
impl<'a> RefUnwindSafe for Reader<'a>
impl<'a> Send for Reader<'a>
impl<'a> Sync for Reader<'a>
impl<'a> Unpin for Reader<'a>
impl<'a> UnwindSafe for Reader<'a>
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
pub fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
pub fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,