Skip to main content

Reader

Struct Reader 

Source
pub struct Reader<'a> { /* private fields */ }
Expand description

A cursor over a protobuf-encoded byte slice. Every accessor returns None on a truncated or malformed input rather than panicking.

Implementations§

Source§

impl<'a> Reader<'a>

Source

pub fn new(buf: &'a [u8]) -> Self

Wrap a byte slice.

Source

pub fn at_end(&self) -> bool

true once every byte has been consumed.

Source

pub fn read_varint(&mut self) -> Option<u64>

Read a base-128 varint (max 10 bytes, i.e. 64 bits). None on truncation or overlong encoding.

Source

pub fn read_tag(&mut self) -> Option<(u32, WireType)>

Read a field tag, returning (field_number, wire_type).

Source

pub fn read_len_delimited(&mut self) -> Option<&'a [u8]>

Read a length-delimited payload (a varint length then that many bytes).

Source

pub fn read_i32(&mut self) -> Option<u32>

Read a fixed 4-byte little-endian value.

Source

pub fn read_i64(&mut self) -> Option<u64>

Read a fixed 8-byte little-endian value.

Source

pub fn skip(&mut self, wt: WireType) -> Option<()>

Skip the payload of a field with the given wire type (for fields the descriptor walker does not care about).

Auto Trait Implementations§

§

impl<'a> Freeze for Reader<'a>

§

impl<'a> RefUnwindSafe for Reader<'a>

§

impl<'a> Send for Reader<'a>

§

impl<'a> Sync for Reader<'a>

§

impl<'a> Unpin for Reader<'a>

§

impl<'a> UnsafeUnpin for Reader<'a>

§

impl<'a> UnwindSafe for Reader<'a>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

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

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.