Skip to main content

PayloadReader

Struct PayloadReader 

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

A payload body being read. It borrows the body and never reads past it.

Implementations§

§

impl<'a> PayloadReader<'a>

pub fn new(body: &'a [u8]) -> PayloadReader<'a>

Reads body with PAYLOAD_DECODE_BUDGET bytes of allocation.

pub fn with_budget(body: &'a [u8], budget: usize) -> PayloadReader<'a>

Reads body, letting its value allocate at most budget bytes.

pub fn remaining(&self) -> usize

How many bytes are not read yet.

pub fn finish(self) -> Result<(), PayloadDecodeError>

Ends the read: PayloadDecodeError::Trailing when bytes are left.

pub fn u8(&mut self) -> Result<u8, PayloadDecodeError>

One unsigned byte.

pub fn i8(&mut self) -> Result<i8, PayloadDecodeError>

One signed byte.

pub fn i16(&mut self) -> Result<i16, PayloadDecodeError>

A big-endian 16-bit integer.

pub fn u16(&mut self) -> Result<u16, PayloadDecodeError>

A big-endian unsigned 16-bit integer.

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

A big-endian 32-bit integer.

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

A big-endian 64-bit integer.

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

A big-endian 32-bit float; NaN and the infinities pass.

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

A big-endian 64-bit float; NaN and the infinities pass.

pub fn uuid(&mut self) -> Result<u128, PayloadDecodeError>

A UUID: 16 bytes, most significant first.

pub fn bool(&mut self) -> Result<bool, PayloadDecodeError>

A boolean: 0 or 1, anything else is refused.

pub fn finite_f32(&mut self) -> Result<f32, PayloadDecodeError>

A 32-bit float that must be finite.

pub fn finite_f64(&mut self) -> Result<f64, PayloadDecodeError>

A 64-bit float that must be finite.

pub fn var_int(&mut self) -> Result<i32, PayloadDecodeError>

A VarInt: up to five 7-bit groups, least significant first.

pub fn var_long(&mut self) -> Result<i64, PayloadDecodeError>

A VarLong: up to ten 7-bit groups, least significant first.

pub fn length(&mut self, limit: usize) -> Result<usize, PayloadDecodeError>

A VarInt length or count of at most limit. A negative one and one past the limit are refused here, before the caller reserves anything.

pub fn bytes(&mut self, limit: usize) -> Result<&'a [u8], PayloadDecodeError>

A byte array of at most limit bytes: its VarInt length, then the bytes, borrowed from the body.

pub fn str_within( &mut self, limit: usize, ) -> Result<&'a str, PayloadDecodeError>

A string of at most limit UTF-8 bytes: its VarInt byte length, then the bytes, borrowed from the body. For a vanilla N-character bound, a schema can pass 3N UTF-8 bytes.

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

An owned string of at most PAYLOAD_MAX_STRING_BYTES UTF-8 bytes.

pub fn nested<T>( &mut self, read: impl FnOnce(&mut PayloadReader<'a>) -> Result<T, PayloadDecodeError>, ) -> Result<T, PayloadDecodeError>

Reads one level down, refusing past PAYLOAD_MAX_DEPTH. A codec of a type that can hold itself calls this around the inner value.

pub fn list<T>( &mut self, limit: usize, read: impl FnMut(&mut PayloadReader<'a>) -> Result<T, PayloadDecodeError>, ) -> Result<Vec<T>, PayloadDecodeError>

A list of at most limit entries: its VarInt count, then each entry read by read, one level down. The count is checked against limit and the list’s decoded size against the budget before it is reserved.

pub fn option<T>( &mut self, read: impl FnOnce(&mut PayloadReader<'a>) -> Result<T, PayloadDecodeError>, ) -> Result<Option<T>, PayloadDecodeError>

An optional value: a boolean, then the value one level down when it is true.

Trait Implementations§

§

impl<'a> Debug for PayloadReader<'a>

§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<'a> Freeze for PayloadReader<'a>

§

impl<'a> RefUnwindSafe for PayloadReader<'a>

§

impl<'a> Send for PayloadReader<'a>

§

impl<'a> Sync for PayloadReader<'a>

§

impl<'a> Unpin for PayloadReader<'a>

§

impl<'a> UnsafeUnpin for PayloadReader<'a>

§

impl<'a> UnwindSafe for PayloadReader<'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.