Struct resol_vbus::BlobReader[][src]

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

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;
            }
        }
    }
}

Implementations

Constructs a new BlobReader<T>.

Get a reference to the underlying reader.

Get a mutable reference to the underlying reader.

Consumes this BlobReader, returning its inner Read value.

Reads additional data to the internal buffer.

Methods from Deref<Target = BlobBuffer>

Provide additional data to the internal buffer.

Consume the given amount of data from the internal buffer.

Returns the unconsumed byte length of the internal buffer.

Returns whether the internal buffer is empty.

Get amount of already consumed bytes.

Trait Implementations

Formats the value using the given formatter. Read more

The resulting type after dereferencing.

Dereferences the value.

Mutably dereferences the value.

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Performs the conversion.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.