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>
impl<'a> Reader<'a>
const fn duplicate(&self) -> Self
pub const fn take(&mut self, n: usize) -> Result<&'a [u8], DecodeError>
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>
pub const fn u8(&mut self) -> Result<u8, DecodeError>
pub const fn u16(&mut self) -> Result<u16, DecodeError>
pub const fn u16(&mut self) -> Result<u16, DecodeError>
pub const fn u32(&mut self) -> Result<u32, DecodeError>
pub const fn u32(&mut self) -> Result<u32, DecodeError>
pub const fn vbi(&mut self) -> Result<Vbi, DecodeError>
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>
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>
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>
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.