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

A struct to read protocol binary files

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::{MessageRead, BytesReader};

fn main() {
    // bytes is a buffer on the data we want to deserialize
    // typically bytes is read from a `Read`:
    // r.read_to_end(&mut bytes).expect("cannot read bytes");
    let mut bytes: Vec<u8>;

    // we can build a bytes reader directly out of the bytes
    let mut reader = BytesReader::from_bytes(&bytes);

    // now using the generated module decoding is as easy as:
    let foobar = FooBar::from_reader(&mut reader, &bytes).expect("Cannot read FooBar");

    // if instead the buffer contains a length delimited stream of message we could use:
    // while !r.is_eof() {
    //     let foobar: FooBar = r.read_message(&bytes).expect(...);
    //     ...
    // }
    println!("Found {} foos and {} bars", foobar.foos.len(), foobar.bars.len());
}

Implementations

Creates a new reader from chunks of data

Reads next tag, None if all bytes have been read

Reads the next byte

Reads the next varint encoded u64

Reads the next varint encoded u64

Reads int32 (varint)

Reads int64 (varint)

Reads uint32 (varint)

Reads uint64 (varint)

Reads sint32 (varint)

Reads sint64 (varint)

Reads fixed64 (little endian u64)

Reads fixed32 (little endian u32)

Reads sfixed64 (little endian i64)

Reads sfixed32 (little endian i32)

Reads float (little endian f32)

Reads double (little endian f64)

Reads bool (varint, check if == 0)

Reads enum, encoded as i32

Reads bytes (Vec)

Reads string (String)

Reads packed repeated field (Vec)

Note: packed field are stored as a variable length chunk of data, while regular repeated fields behaves like an iterator, yielding their tag everytime

Reads packed repeated field where M can directly be transmutted from raw bytes

Note: packed field are stored as a variable length chunk of data, while regular repeated fields behaves like an iterator, yielding their tag everytime

Reads a nested message

First reads a varint and interprets it as the length of the message

Reads a nested message

Reads just the message and does not try to read it’s size first.

  • ‘len’ - The length of the message to be read.

Reads a map item: (key, value)

Reads unknown data, based on its tag value (which itself gives us the wire_type value)

Gets the remaining length of bytes not read yet

Checks if self.len == 0

Advance inner cursor to the end

Trait Implementations

Returns a copy of the value. Read more
Performs copy-assignment from source. Read more
Formats the value using the given formatter. Read more
This method tests for self and other values to be equal, and is used by ==. Read more
This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason. Read more

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 resulting type after obtaining ownership.
Creates owned data from borrowed data, usually by cloning. Read more
Uses borrowed data to replace owned data, usually by cloning. Read more
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.