[−][src]Struct quick_protobuf::reader::BytesReader
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
impl BytesReader
[src]
pub fn from_bytes(bytes: &[u8]) -> BytesReader
[src]
Creates a new reader from chunks of data
pub fn next_tag(&mut self, bytes: &[u8]) -> Result<u32>
[src]
Reads next tag, None
if all bytes have been read
pub fn read_u8(&mut self, bytes: &[u8]) -> Result<u8>
[src]
Reads the next byte
pub fn read_varint32(&mut self, bytes: &[u8]) -> Result<u32>
[src]
Reads the next varint encoded u64
pub fn read_varint64(&mut self, bytes: &[u8]) -> Result<u64>
[src]
Reads the next varint encoded u64
pub fn read_int32(&mut self, bytes: &[u8]) -> Result<i32>
[src]
Reads int32 (varint)
pub fn read_int64(&mut self, bytes: &[u8]) -> Result<i64>
[src]
Reads int64 (varint)
pub fn read_uint32(&mut self, bytes: &[u8]) -> Result<u32>
[src]
Reads uint32 (varint)
pub fn read_uint64(&mut self, bytes: &[u8]) -> Result<u64>
[src]
Reads uint64 (varint)
pub fn read_sint32(&mut self, bytes: &[u8]) -> Result<i32>
[src]
Reads sint32 (varint)
pub fn read_sint64(&mut self, bytes: &[u8]) -> Result<i64>
[src]
Reads sint64 (varint)
pub fn read_fixed64(&mut self, bytes: &[u8]) -> Result<u64>
[src]
Reads fixed64 (little endian u64)
pub fn read_fixed32(&mut self, bytes: &[u8]) -> Result<u32>
[src]
Reads fixed32 (little endian u32)
pub fn read_sfixed64(&mut self, bytes: &[u8]) -> Result<i64>
[src]
Reads sfixed64 (little endian i64)
pub fn read_sfixed32(&mut self, bytes: &[u8]) -> Result<i32>
[src]
Reads sfixed32 (little endian i32)
pub fn read_float(&mut self, bytes: &[u8]) -> Result<f32>
[src]
Reads float (little endian f32)
pub fn read_double(&mut self, bytes: &[u8]) -> Result<f64>
[src]
Reads double (little endian f64)
pub fn read_bool(&mut self, bytes: &[u8]) -> Result<bool>
[src]
Reads bool (varint, check if == 0)
pub fn read_enum<E: From<i32>>(&mut self, bytes: &[u8]) -> Result<E>
[src]
Reads enum, encoded as i32
pub fn read_bytes<'a>(&mut self, bytes: &'a [u8]) -> Result<&'a [u8]>
[src]
Reads bytes (Vec
pub fn read_string<'a>(&mut self, bytes: &'a [u8]) -> Result<&'a str>
[src]
Reads string (String)
pub 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>,
[src]
&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
pub fn read_packed_fixed<'a, M>(&mut self, bytes: &'a [u8]) -> Result<&'a [M]>
[src]
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
pub fn read_message<'a, M>(&mut self, bytes: &'a [u8]) -> Result<M> where
M: MessageRead<'a>,
[src]
M: MessageRead<'a>,
Reads a nested message
First reads a varint and interprets it as the length of the message
pub fn read_message_by_len<'a, M>(
&mut self,
bytes: &'a [u8],
len: usize
) -> Result<M> where
M: MessageRead<'a>,
[src]
&mut self,
bytes: &'a [u8],
len: usize
) -> Result<M> where
M: MessageRead<'a>,
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.
pub 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,
[src]
&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,
Reads a map item: (key, value)
pub fn read_unknown(&mut self, bytes: &[u8], tag_value: u32) -> Result<()>
[src]
Reads unknown data, based on its tag value (which itself gives us the wire_type value)
pub fn len(&self) -> usize
[src]
Gets the remaining length of bytes not read yet
pub fn is_eof(&self) -> bool
[src]
Checks if self.len == 0
pub fn read_to_end(&mut self)
[src]
Advance inner cursor to the end
Trait Implementations
impl Clone for BytesReader
[src]
fn clone(&self) -> BytesReader
[src]
fn clone_from(&mut self, source: &Self)
1.0.0[src]
impl Debug for BytesReader
[src]
impl PartialEq<BytesReader> for BytesReader
[src]
fn eq(&self, other: &BytesReader) -> bool
[src]
fn ne(&self, other: &BytesReader) -> bool
[src]
impl StructuralPartialEq for BytesReader
[src]
Auto Trait Implementations
impl RefUnwindSafe for BytesReader
impl Send for BytesReader
impl Sync for BytesReader
impl Unpin for BytesReader
impl UnwindSafe for BytesReader
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> ToOwned for T where
T: Clone,
[src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
fn to_owned(&self) -> T
[src]
fn clone_into(&self, target: &mut T)
[src]
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>,