[−][src]Struct quick_protobuf::reader::Reader
A struct to read protobuf data
Contrary to BytesReader
, this struct will own a buffer
Examples
ⓘThis example panics
// FooBar is a message generated from a proto file // In particular it implements the `MessageRead` trait, containing a `from_reader` function. use foo_bar::FooBar; use quick_protobuf::Reader; fn main() { // create a reader, which will parse the protobuf binary file and pop events // this reader will read the entire file into an internal buffer let mut reader = Reader::from_file("/path/to/binary/protobuf.bin") .expect("Cannot read input file"); // Use the generated module fns with the reader to convert your data into rust structs. // // Depending on your input file, the message can or not be prefixed with the encoded length // for instance, a *stream* which contains several messages generally split them using this // technique (see https://developers.google.com/protocol-buffers/docs/techniques#streaming) // // To read a message without a length prefix you can directly call `FooBar::from_reader`: // let foobar = reader.read(FooBar::from_reader).expect("Cannot read FooBar message"); // // Else to read a length then a message, you can use: let foobar: FooBar = reader.read(|r, b| r.read_message(b)) .expect("Cannot read FooBar message"); // Reader::read_message uses `FooBar::from_reader` internally through the `MessageRead` // trait. println!("Found {} foos and {} bars!", foobar.foos.len(), foobar.bars.len()); }
Implementations
impl Reader
[src]
pub fn from_reader<R: Read>(r: R, capacity: usize) -> Result<Reader>
[src]
Creates a new Reader
pub fn from_file<P: AsRef<Path>>(src: P) -> Result<Reader>
[src]
Creates a new Reader
out of a file path
pub fn from_bytes(bytes: Vec<u8>) -> Reader
[src]
Creates a new reader consuming the bytes
pub fn read<'a, M, F>(&'a mut self, read: F) -> Result<M> where
F: FnMut(&mut BytesReader, &'a [u8]) -> Result<M>,
[src]
F: FnMut(&mut BytesReader, &'a [u8]) -> Result<M>,
Run a BytesReader
dependent function
pub fn inner(&mut self) -> &mut BytesReader
[src]
Gets the inner BytesReader
pub fn buffer(&self) -> &[u8]
[src]
Gets the buffer used internally
Auto Trait Implementations
impl RefUnwindSafe for Reader
impl Send for Reader
impl Sync for Reader
impl Unpin for Reader
impl UnwindSafe for Reader
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>,