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>
impl<'a> PayloadReader<'a>
pub fn new(body: &'a [u8]) -> 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>
pub fn with_budget(body: &'a [u8], budget: usize) -> PayloadReader<'a>
Reads body, letting its value allocate at most budget bytes.
pub fn finish(self) -> Result<(), PayloadDecodeError>
pub fn finish(self) -> Result<(), PayloadDecodeError>
Ends the read: PayloadDecodeError::Trailing when bytes are left.
pub fn u8(&mut self) -> Result<u8, PayloadDecodeError>
pub fn u8(&mut self) -> Result<u8, PayloadDecodeError>
One unsigned byte.
pub fn i8(&mut self) -> Result<i8, PayloadDecodeError>
pub fn i8(&mut self) -> Result<i8, PayloadDecodeError>
One signed byte.
pub fn i16(&mut self) -> Result<i16, PayloadDecodeError>
pub fn i16(&mut self) -> Result<i16, PayloadDecodeError>
A big-endian 16-bit integer.
pub fn u16(&mut self) -> Result<u16, PayloadDecodeError>
pub fn u16(&mut self) -> Result<u16, PayloadDecodeError>
A big-endian unsigned 16-bit integer.
pub fn i32(&mut self) -> Result<i32, PayloadDecodeError>
pub fn i32(&mut self) -> Result<i32, PayloadDecodeError>
A big-endian 32-bit integer.
pub fn i64(&mut self) -> Result<i64, PayloadDecodeError>
pub fn i64(&mut self) -> Result<i64, PayloadDecodeError>
A big-endian 64-bit integer.
pub fn f32(&mut self) -> Result<f32, PayloadDecodeError>
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>
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>
pub fn uuid(&mut self) -> Result<u128, PayloadDecodeError>
A UUID: 16 bytes, most significant first.
pub fn bool(&mut self) -> Result<bool, PayloadDecodeError>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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.