Skip to content

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.

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

Variable bytes of at most max bytes.

DecodeError::OverLimit or DecodeError::Truncated.

pub fn string(&mut self, max: usize) -> Result<&'a str, DecodeError>

string of at most max bytes; valid UTF-8, not normalised.

As Self::bytes, or DecodeError::InvalidUtf8.

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.

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.

DecodeError::OverLimit, DecodeError::Truncated, or whatever f returns.

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

A reader over input.

pub const fn remaining(&self) -> usize

Bytes not yet read.

pub const fn finish(self) -> Result<(), DecodeError>

Ends a top-level decode.

DecodeError::TrailingBytes when input remains.

pub fn fixed(&mut self, n: usize) -> Result<&'a [u8], DecodeError>

bytes[n]: the next n bytes.

DecodeError::Truncated.

pub fn array<N>(&mut self) -> Result<[u8; N], DecodeError>

bytes[N] as an array.

DecodeError::Truncated.

pub fn peek_u8(&self) -> Result<u8, DecodeError>

The next byte without consuming it.

DecodeError::Truncated.

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

u8.

DecodeError::Truncated.

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

u16, big-endian.

DecodeError::Truncated.

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

u32, big-endian.

DecodeError::Truncated.

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

u64, big-endian.

DecodeError::Truncated.

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

bool: only 0x00 and 0x01.

DecodeError::InvalidBool or DecodeError::Truncated.

pub fn get<T>(&mut self) -> Result<T, DecodeError>

Reads a value with a canonical decoding.

Whatever the value’s decoder returns.

Clone, Debug

Full rustdoc page