[][src]Struct async_resol_vbus::BlobReader

pub struct BlobReader<R> where
    R: Read
{ /* fields omitted */ }

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]

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]

impl<R> Deref for BlobReader<R> where
    R: Read
[src]

type Target = BlobBuffer

The resulting type after dereferencing.

impl<R> DerefMut for BlobReader<R> where
    R: Read
[src]

Auto Trait Implementations

impl<R> RefUnwindSafe for BlobReader<R> where
    R: RefUnwindSafe

impl<R> Send for BlobReader<R> where
    R: Send

impl<R> Sync for BlobReader<R> where
    R: Sync

impl<R> Unpin for BlobReader<R> where
    R: Unpin

impl<R> UnwindSafe for BlobReader<R> where
    R: UnwindSafe

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.