[−][src]Struct async_resol_vbus::BlobReader
A buffering reader that allows to borrow the internal buffer.
The BlobReader
behaves like a std::io::BufReader
with the addition that the internal buffer
grows if necessary.
Examples
use std::fs::File; use resol_vbus::{BlobReader, StreamBlobLength}; use resol_vbus::recording_decoder::{length_from_bytes}; let file = File::open("20161202_packets.vbus").unwrap(); let mut br = BlobReader::new(file); loop { match length_from_bytes(&br) { StreamBlobLength::BlobLength(size) => { // do something with the data // afterwards consume it br.consume(size); } StreamBlobLength::Malformed => { // just consume the current starting byte, perhaps a valid blob is hidden behind it br.consume(1); } StreamBlobLength::Partial => { // internal buffer is either empty or contains the valid start of a blob, read more // data if br.read().unwrap() == 0 { break; } } } }
Methods
impl<R> BlobReader<R> where
R: Read,
[src]
R: Read,
pub fn new(reader: R) -> BlobReader<R>
[src]
Constructs a new BlobReader<T>
.
pub fn into_inner(self) -> R
[src]
Consumes this BlobReader
, returning its inner Read
value.
pub fn read(&mut self) -> Result<usize, Error>
[src]
Reads additional data to the internal buffer.
Methods from Deref<Target = BlobBuffer>
pub fn extend_from_slice(&mut self, data: &[u8])
[src]
Provide additional data to the internal buffer.
pub fn consume(&mut self, length: usize)
[src]
Consume the given amount of data from the internal buffer.
pub fn len(&self) -> usize
[src]
Returns the unconsumed byte length of the internal buffer.
pub fn is_empty(&self) -> bool
[src]
Returns whether the internal buffer is empty.
pub fn offset(&self) -> usize
[src]
Get amount of already consumed bytes.
Trait Implementations
impl<R> Debug for BlobReader<R> where
R: Read + Debug,
[src]
R: Read + Debug,
impl<R> Deref for BlobReader<R> where
R: Read,
[src]
R: Read,
impl<R> DerefMut for BlobReader<R> where
R: Read,
[src]
R: Read,
fn deref_mut(&mut self) -> &mut BlobBuffer
[src]
Auto Trait Implementations
impl<R> RefUnwindSafe for BlobReader<R> where
R: RefUnwindSafe,
R: RefUnwindSafe,
impl<R> Send for BlobReader<R> where
R: Send,
R: Send,
impl<R> Sync for BlobReader<R> where
R: Sync,
R: Sync,
impl<R> Unpin for BlobReader<R> where
R: Unpin,
R: Unpin,
impl<R> UnwindSafe for BlobReader<R> where
R: UnwindSafe,
R: UnwindSafe,
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,
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.
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>,