Struct encoding::Reader
zaun_community_protocol::encoding::Reader · Struct
pub struct Reader<'a> { … }Reads canonical encodings from a byte slice. Lengths and counts are checked against the field’s limit and the remaining input before anything is allocated.
Methods
Section titled “Methods”pub fn bytes(&mut self, max: usize) -> Result<&'a [u8], DecodeError>Variable bytes of at most max bytes.
Errors
Section titled “Errors”DecodeError::OverLimit or DecodeError::Truncated.
string
Section titled “string”pub fn string(&mut self, max: usize) -> Result<&'a str, DecodeError>string of at most max bytes; valid UTF-8, not normalised.
Errors
Section titled “Errors”As Self::bytes, or DecodeError::InvalidUtf8.
option
Section titled “option”pub fn option<T, impl FnOnce(&mut Self) -> Result<T, DecodeError>>(&mut self, f: impl FnOnce(&mut Self) -> Result<T, DecodeError>) -> Result<Option<T>, DecodeError>option<T> with the value read by f; tags other than 0x00/0x01 are errors.
Errors
Section titled “Errors”DecodeError::InvalidOptionTag, or whatever f returns.
pub fn list<T, impl FnMut(&mut Self) -> Result<T, DecodeError>>(&mut self, max: usize, f: impl FnMut(&mut Self) -> Result<T, DecodeError>) -> Result<Vec<T>, DecodeError>list<T> of at most max elements, each read by f.
Errors
Section titled “Errors”DecodeError::OverLimit, DecodeError::Truncated, or whatever f returns.
pub const fn new(input: &'a [u8]) -> SelfA reader over input.
remaining
Section titled “remaining”pub const fn remaining(&self) -> usizeBytes not yet read.
finish
Section titled “finish”pub const fn finish(self) -> Result<(), DecodeError>Ends a top-level decode.
Errors
Section titled “Errors”DecodeError::TrailingBytes when input remains.
pub fn fixed(&mut self, n: usize) -> Result<&'a [u8], DecodeError>bytes[n]: the next n bytes.
Errors
Section titled “Errors”DecodeError::Truncated.
pub fn array<N>(&mut self) -> Result<[u8; N], DecodeError>bytes[N] as an array.
Errors
Section titled “Errors”DecodeError::Truncated.
peek_u8
Section titled “peek_u8”pub fn peek_u8(&self) -> Result<u8, DecodeError>The next byte without consuming it.
Errors
Section titled “Errors”DecodeError::Truncated.
pub fn u8(&mut self) -> Result<u8, DecodeError>u8.
Errors
Section titled “Errors”DecodeError::Truncated.
pub fn u16(&mut self) -> Result<u16, DecodeError>u16, big-endian.
Errors
Section titled “Errors”DecodeError::Truncated.
pub fn u32(&mut self) -> Result<u32, DecodeError>u32, big-endian.
Errors
Section titled “Errors”DecodeError::Truncated.
pub fn u64(&mut self) -> Result<u64, DecodeError>u64, big-endian.
Errors
Section titled “Errors”DecodeError::Truncated.
pub fn bool(&mut self) -> Result<bool, DecodeError>bool: only 0x00 and 0x01.
Errors
Section titled “Errors”DecodeError::InvalidBool or DecodeError::Truncated.
pub fn get<T>(&mut self) -> Result<T, DecodeError>Reads a value with a canonical decoding.
Errors
Section titled “Errors”Whatever the value’s decoder returns.
Trait implementations
Section titled “Trait implementations”Clone, Debug