pub struct Reader { /* private fields */ }
Expand description

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

Creates a new Reader

Creates a new Reader out of a file path

Creates a new reader consuming the bytes

Run a BytesReader dependent function

Gets the inner BytesReader

Gets the buffer used internally

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

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

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.