Skip to main content

Reader

Struct Reader 

Source
pub struct Reader<'a> {
    pub pos: usize,
    /* private fields */
}

Fields§

§pos: usize

Implementations§

Source§

impl<'a> Reader<'a>

Source

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

Source

pub fn data(&self) -> &'a [u8]

Source

pub fn eof(&self) -> bool

Source

pub fn remaining(&self) -> usize

Source

pub fn varint(&mut self) -> Result<u64>

Read an unsigned varint, up to 10 bytes (uint64 range).

Source

pub fn zigzag32(&mut self) -> Result<i32>

Decode a zigzag varint as a 32-bit signed integer.

Source

pub fn zigzag64(&mut self) -> Result<i64>

Decode a zigzag varint as a 64-bit signed integer.

Source

pub fn fixed32(&mut self) -> Result<u32>

Source

pub fn fixed64(&mut self) -> Result<u64>

Source

pub fn float(&mut self) -> Result<f32>

Source

pub fn double(&mut self) -> Result<f64>

Source

pub fn bytes(&mut self) -> Result<Vec<u8>>

Length-prefixed bytes; returns a copy.

Source

pub fn bytes_view(&mut self) -> Result<&'a [u8]>

Length-prefixed bytes; returns a borrow into the underlying buffer.

Guards against attacker-supplied length-prefix overflow per HARDENING.md §API contract item 3: a 10-byte varint of 2^64-1 would wrap pos + len to a small value and slip past a naive bounds check, then trip a slice-indexing panic. Compute the end offset with checked_add and reject before slicing.

Source

pub fn string(&mut self) -> Result<String>

UTF-8 length-prefixed string.

Source

pub fn tag(&mut self) -> Result<(u32, WireType)>

Decode a tag varint into (field_number, wire_type).

Source

pub fn skip(&mut self, wire_type: WireType) -> Result<()>

Skip the value of a field with the given wire type.

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 = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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.