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>
.
Consumes this BlobReader
, returning its inner Read
value.
Methods from Deref<Target = BlobBuffer>
Provide additional data to the internal buffer.
Consume the given amount of data from the internal buffer.
Trait Implementations
type Target = BlobBuffer
type Target = BlobBuffer
The resulting type after dereferencing.
fn deref(&self) -> &BlobBufferⓘNotable traits for BlobBufferimpl Read for BlobBufferimpl Write for BlobBuffer
fn deref(&self) -> &BlobBufferⓘNotable traits for BlobBufferimpl Read for BlobBufferimpl Write for BlobBuffer
Notable traits for BlobBuffer
impl Read for BlobBufferimpl Write for BlobBuffer
Dereferences the value.
fn deref_mut(&mut self) -> &mut BlobBufferⓘNotable traits for BlobBufferimpl Read for BlobBufferimpl Write for BlobBuffer
fn deref_mut(&mut self) -> &mut BlobBufferⓘNotable traits for BlobBufferimpl Read for BlobBufferimpl Write for BlobBuffer
Notable traits for BlobBuffer
impl Read for BlobBufferimpl Write for BlobBuffer
Mutably dereferences the value.