pub struct MqttLayer {
pub index: LayerIndex,
}Expand description
MQTT layer – a zero-copy view into a packet buffer.
Fields§
§index: LayerIndexImplementations§
Source§impl MqttLayer
impl MqttLayer
Sourcepub fn new(index: LayerIndex) -> Self
pub fn new(index: LayerIndex) -> Self
Create a new MQTT layer from a layer index.
Sourcepub fn at_start(len: usize) -> Self
pub fn at_start(len: usize) -> Self
Create an MQTT layer starting at offset 0 (for standalone parsing).
Sourcepub fn msg_type(&self, buf: &[u8]) -> Result<u8, FieldError>
pub fn msg_type(&self, buf: &[u8]) -> Result<u8, FieldError>
Get the message type (bits 7-4 of byte 0).
Sourcepub fn qos(&self, buf: &[u8]) -> Result<u8, FieldError>
pub fn qos(&self, buf: &[u8]) -> Result<u8, FieldError>
Get the QoS level (bits 2-1 of byte 0).
Sourcepub fn retain(&self, buf: &[u8]) -> Result<bool, FieldError>
pub fn retain(&self, buf: &[u8]) -> Result<bool, FieldError>
Get the RETAIN flag (bit 0 of byte 0).
Sourcepub fn remaining_length(&self, buf: &[u8]) -> Result<u32, FieldError>
pub fn remaining_length(&self, buf: &[u8]) -> Result<u32, FieldError>
Get the remaining length (variable-length integer starting at byte 1).
Sourcepub fn fixed_header_len(&self, buf: &[u8]) -> usize
pub fn fixed_header_len(&self, buf: &[u8]) -> usize
Compute the fixed header length (1 byte type/flags + N bytes remaining length).
Sourcepub fn topic_len(&self, buf: &[u8]) -> Result<u16, FieldError>
pub fn topic_len(&self, buf: &[u8]) -> Result<u16, FieldError>
Get the topic length for a PUBLISH message (2-byte big-endian at variable header start).
Sourcepub fn topic(&self, buf: &[u8]) -> Result<String, FieldError>
pub fn topic(&self, buf: &[u8]) -> Result<String, FieldError>
Get the topic string for a PUBLISH message.
Sourcepub fn msgid(&self, buf: &[u8]) -> Result<u16, FieldError>
pub fn msgid(&self, buf: &[u8]) -> Result<u16, FieldError>
Get the message ID for PUBLISH (QoS > 0), PUBACK, PUBREC, PUBREL, PUBCOMP,
SUBSCRIBE, SUBACK, UNSUBSCRIBE, UNSUBACK messages.
For PUBLISH: message ID follows the topic (2 bytes topic_len + topic bytes).
For others: message ID is at the start of the variable header.
Sourcepub fn value(&self, buf: &[u8]) -> Result<Vec<u8>, FieldError>
pub fn value(&self, buf: &[u8]) -> Result<Vec<u8>, FieldError>
Get the payload value for a PUBLISH message (bytes after topic + optional msgid).
Sourcepub fn proto_name(&self, buf: &[u8]) -> Result<String, FieldError>
pub fn proto_name(&self, buf: &[u8]) -> Result<String, FieldError>
Get the protocol name from a CONNECT message (e.g., “MQTT” or “MQIsdp”).
Sourcepub fn proto_level(&self, buf: &[u8]) -> Result<u8, FieldError>
pub fn proto_level(&self, buf: &[u8]) -> Result<u8, FieldError>
Get the protocol level/version byte from a CONNECT message.
Sourcepub fn connect_flags(&self, buf: &[u8]) -> Result<u8, FieldError>
pub fn connect_flags(&self, buf: &[u8]) -> Result<u8, FieldError>
Get the connect flags byte from a CONNECT message.
Sourcepub fn usernameflag(&self, buf: &[u8]) -> Result<bool, FieldError>
pub fn usernameflag(&self, buf: &[u8]) -> Result<bool, FieldError>
Get the username flag from CONNECT flags (bit 7).
Sourcepub fn passwordflag(&self, buf: &[u8]) -> Result<bool, FieldError>
pub fn passwordflag(&self, buf: &[u8]) -> Result<bool, FieldError>
Get the password flag from CONNECT flags (bit 6).
Sourcepub fn willretainflag(&self, buf: &[u8]) -> Result<bool, FieldError>
pub fn willretainflag(&self, buf: &[u8]) -> Result<bool, FieldError>
Get the will retain flag from CONNECT flags (bit 5).
Sourcepub fn will_qosflag(&self, buf: &[u8]) -> Result<u8, FieldError>
pub fn will_qosflag(&self, buf: &[u8]) -> Result<u8, FieldError>
Get the will QoS from CONNECT flags (bits 4-3).
Sourcepub fn willflag(&self, buf: &[u8]) -> Result<bool, FieldError>
pub fn willflag(&self, buf: &[u8]) -> Result<bool, FieldError>
Get the will flag from CONNECT flags (bit 2).
Sourcepub fn cleansess(&self, buf: &[u8]) -> Result<bool, FieldError>
pub fn cleansess(&self, buf: &[u8]) -> Result<bool, FieldError>
Get the clean session flag from CONNECT flags (bit 1).
Sourcepub fn klive(&self, buf: &[u8]) -> Result<u16, FieldError>
pub fn klive(&self, buf: &[u8]) -> Result<u16, FieldError>
Get the keep alive value from a CONNECT message (2-byte big-endian).
Sourcepub fn client_id(&self, buf: &[u8]) -> Result<String, FieldError>
pub fn client_id(&self, buf: &[u8]) -> Result<String, FieldError>
Get the client ID from a CONNECT message.
Sourcepub fn sess_present_flag(&self, buf: &[u8]) -> Result<u8, FieldError>
pub fn sess_present_flag(&self, buf: &[u8]) -> Result<u8, FieldError>
Get the session present flag from a CONNACK message (byte 0 of variable header).
Sourcepub fn retcode(&self, buf: &[u8]) -> Result<u8, FieldError>
pub fn retcode(&self, buf: &[u8]) -> Result<u8, FieldError>
Get the return code from a CONNACK message (byte 1 of variable header).
Sourcepub fn retcodes(&self, buf: &[u8]) -> Result<Vec<u8>, FieldError>
pub fn retcodes(&self, buf: &[u8]) -> Result<Vec<u8>, FieldError>
Get the return codes from a SUBACK message (bytes after the 2-byte msgid).
Sourcepub fn field_names() -> &'static [&'static str]
pub fn field_names() -> &'static [&'static str]
Get the field names for this layer.
Sourcepub fn get_field(
&self,
buf: &[u8],
name: &str,
) -> Option<Result<FieldValue, FieldError>>
pub fn get_field( &self, buf: &[u8], name: &str, ) -> Option<Result<FieldValue, FieldError>>
Get a field value by name.
Sourcepub fn set_field(
&self,
_buf: &mut [u8],
_name: &str,
_value: FieldValue,
) -> Option<Result<(), FieldError>>
pub fn set_field( &self, _buf: &mut [u8], _name: &str, _value: FieldValue, ) -> Option<Result<(), FieldError>>
Set a field value by name (limited support for MQTT).