Struct quick_protobuf::reader::Reader
[−]
[src]
pub struct Reader { /* fields omitted */ }
A struct to read protobuf data
Contrary to BytesReader
, this struct will own a buffer
Examples
// FooBar is a message generated from a proto file // in parcicular it contains a `from_reader` function use foo_bar::FooBar; use quick_protobuf::Reader; fn main() { // read an entire file into memory let mut reader = Reader::from_file("/myproject/resources/my_file.bin") .expect("Cannot read binary encoded file"); // now using the generated module decoding is as easy as: let foobar = reader.read(FooBar::from_reader).expect("Cannot read FooBar"); println!("Found {} foos and {} bars", foobar.foos.len(), foobar.bars.len()); }
Methods
impl Reader
[src]
fn from_reader<R: Read>(r: R, capacity: usize) -> Result<Reader>
Creates a new Reader
fn from_file<P: AsRef<Path>>(src: P) -> Result<Reader>
Creates a new Reader
out of a file path
fn read<'a, M, F>(&'a mut self, read: F) -> Result<M> where F: FnMut(&mut BytesReader, &'a [u8]) -> Result<M>
Run a BytesReader
dependent function