Struct quick_protobuf::reader::BytesReader[][src]

pub struct BytesReader { /* fields omitted */ }

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());
}

Methods

impl BytesReader
[src]

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

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

impl Debug for BytesReader
[src]

Formats the value using the given formatter. Read more

impl Clone for BytesReader
[src]

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

impl PartialEq for BytesReader
[src]

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

Auto Trait Implementations

impl Send for BytesReader

impl Sync for BytesReader