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::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"); println!("Found {} foos and {} bars", foobar.foos.len(), foobar.bars.len()); }
Methods
impl BytesReader
[src]
fn from_bytes(bytes: &[u8]) -> BytesReader
Creates a new reader from chunks of data
fn next_tag(&mut self, bytes: &[u8]) -> Result<u32>
Reads next tag, None
if all bytes have been read
fn read_varint32(&mut self, bytes: &[u8]) -> Result<u32>
Reads the next varint encoded u64
fn read_varint64(&mut self, bytes: &[u8]) -> Result<u64>
Reads the next varint encoded u64
fn read_int32(&mut self, bytes: &[u8]) -> Result<i32>
Reads int32 (varint)
fn read_int64(&mut self, bytes: &[u8]) -> Result<i64>
Reads int64 (varint)
fn read_uint32(&mut self, bytes: &[u8]) -> Result<u32>
Reads uint32 (varint)
fn read_uint64(&mut self, bytes: &[u8]) -> Result<u64>
Reads uint64 (varint)
fn read_sint32(&mut self, bytes: &[u8]) -> Result<i32>
Reads sint32 (varint)
fn read_sint64(&mut self, bytes: &[u8]) -> Result<i64>
Reads sint64 (varint)
fn read_fixed64(&mut self, bytes: &[u8]) -> Result<u64>
Reads fixed64 (little endian u64)
fn read_fixed32(&mut self, bytes: &[u8]) -> Result<u32>
Reads fixed32 (little endian u32)
fn read_sfixed64(&mut self, bytes: &[u8]) -> Result<i64>
Reads sfixed64 (little endian i64)
fn read_sfixed32(&mut self, bytes: &[u8]) -> Result<i32>
Reads sfixed32 (little endian i32)
fn read_float(&mut self, bytes: &[u8]) -> Result<f32>
Reads float (little endian f32)
fn read_double(&mut self, bytes: &[u8]) -> Result<f64>
Reads double (little endian f64)
fn read_bool(&mut self, bytes: &[u8]) -> Result<bool>
Reads bool (varint, check if == 0)
fn read_enum<E: From<i32>>(&mut self, bytes: &[u8]) -> Result<E>
Reads enum, encoded as i32
fn read_bytes<'a>(&mut self, bytes: &'a [u8]) -> Result<&'a [u8]>
Reads bytes (Vec
fn read_string<'a>(&mut self, bytes: &'a [u8]) -> Result<&'a str>
Reads string (String)
fn read_packed<'a, M, F>(&mut self, bytes: &'a [u8], read: F) -> Result<Vec<M>> where F: FnMut(&mut BytesReader, &'a [u8]) -> Result<M>
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
fn read_message<'a, M, F>(&mut self, bytes: &'a [u8], read: F) -> Result<M> where F: FnMut(&mut BytesReader, &'a [u8]) -> Result<M>
Reads a nested message
fn read_map<'a, K, V, F, G>(&mut self,
bytes: &'a [u8],
read_key: F,
read_val: G)
-> Result<(K, V)> where F: FnMut(&mut BytesReader, &'a [u8]) -> Result<K>,
G: FnMut(&mut BytesReader, &'a [u8]) -> Result<V>,
K: Debug + Default,
V: Debug + Default
bytes: &'a [u8],
read_key: F,
read_val: G)
-> Result<(K, V)> where F: FnMut(&mut BytesReader, &'a [u8]) -> Result<K>,
G: FnMut(&mut BytesReader, &'a [u8]) -> Result<V>,
K: Debug + Default,
V: Debug + Default
Reads a map item: (key, value)
fn read_unknown(&mut self, bytes: &[u8], tag_value: u32) -> Result<()>
Reads unknown data, based on its tag value (which itself gives us the wire_type value)
fn len(&self) -> usize
Gets the remaining length of bytes not read yet
fn is_eof(&self) -> bool
Checks if self.len == 0
Trait Implementations
impl Debug for BytesReader
[src]
impl Clone for BytesReader
[src]
fn clone(&self) -> BytesReader
Returns a copy of the value. Read more
fn clone_from(&mut self, source: &Self)
1.0.0
Performs copy-assignment from source
. Read more
impl PartialEq for BytesReader
[src]
fn eq(&self, __arg_0: &BytesReader) -> bool
This method tests for self
and other
values to be equal, and is used by ==
. Read more
fn ne(&self, __arg_0: &BytesReader) -> bool
This method tests for !=
.