Reader

Struct Reader 

pub struct Reader<'a> {
    remaining: &'a [u8],
}
Expand description

MQTT wire format reader.

All operations are atomic: if any method returns an error, the reader’s state is unchanged.

Fields§

§remaining: &'a [u8]

Implementations§

§

impl<'a> Reader<'a>

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

Creates a new reader over the given data.

pub const fn is_empty(&self) -> bool

Returns true if there are no more bytes to read.

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

Returns the remaining unread bytes without consuming them.

const fn duplicate(&self) -> Self

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

Takes exactly n bytes from the remaining data, returning a slice.

§Errors

Returns DecodeError::InsufficientData if fewer than n bytes remain.

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

Reads a single byte.

§Errors

Returns DecodeError::InsufficientData if no bytes remain.

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

Reads a big-endian u16.

§Errors

Returns DecodeError::InsufficientData if fewer than 2 bytes remain.

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

Reads a big-endian u32.

§Errors

Returns DecodeError::InsufficientData if fewer than 4 bytes remain.

pub const fn vbi(&mut self) -> Result<Vbi, DecodeError>

Reads a Variable Byte Integer (1–4 bytes).

§Errors

Returns DecodeError::InsufficientData if the input is truncated, or DecodeError::MalformedVbi if the encoding is invalid.

pub const fn binary(&mut self) -> Result<&'a MqttBytes, DecodeError>

Reads a length-prefixed binary data.

§Errors

Returns DecodeError::InsufficientData if the input is truncated.

pub const fn string(&mut self) -> Result<&'a MqttStr, DecodeError>

Reads a length-prefixed UTF-8 string with additional MQTT validation.

§Errors

Returns DecodeError::InsufficientData if the input is truncated, DecodeError::InvalidUtf8 if the string is not valid UTF-8, or DecodeError::StringContainsNull if the string contains a null byte.

pub const fn string_pair( &mut self, ) -> Result<(&'a MqttStr, &'a MqttStr), DecodeError>

Reads a pair of length-prefixed UTF-8 strings with additional MQTT validation.

§Errors

Returns DecodeError if either string cannot be read or is invalid.

Trait Implementations§

§

impl<'a> Clone for Reader<'a>

§

fn clone(&self) -> Reader<'a>

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
§

impl<'a> Debug for Reader<'a>

§

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

Formats the value using the given formatter. Read more

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> 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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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.