pub enum Packet {
}Expand description
Represents all possible MQTT v5 packet types
This enum serves as the main abstraction for working with MQTT packets, providing a unified interface for packet handling while maintaining type safety for each specific packet type.
§Example
use std::time::Duration;
use mqute_codec::protocol::v5::Packet;
use mqute_codec::protocol::v5::{Connect, ConnectProperties};
use bytes::{Bytes, BytesMut};
let properties = ConnectProperties {
session_expiry_interval: Some(3600),
..Default::default()
};
let connect = Connect::with_properties(
"client",
None,
None,
properties.clone(),
Duration::from_secs(30),
true);
let mut buf = BytesMut::new();
let packet = Packet::Connect(connect);
packet.encode(&mut buf).unwrap()Variants§
Connect(Connect)
Client-initiated connection request. First packet in connection establishment flow
ConnAck(ConnAck)
Server connection acknowledgment. Sent in response to CONNECT packet
Publish(Publish)
Message publication. Primary message delivery mechanism.
PubAck(PubAck)
QoS 1 publication acknowledgment. Acknowledges receipt of QoS 1 messages
PubRec(PubRec)
QoS 2 publication received (part 1). First packet in QoS 2 protocol flow
PubRel(PubRel)
QoS 2 publication release (part 2). Second packet in QoS 2 protocol flow
PubComp(PubComp)
QoS 2 publication complete (part 3). Final packet in QoS 2 protocol flow
Subscribe(Subscribe)
Subscription request. Begins subscription creation/modification
SubAck(SubAck)
Subscription acknowledgment. Confirms subscription processing results
Unsubscribe(Unsubscribe)
Unsubscription request. Begins subscription termination
UnsubAck(UnsubAck)
Unsubscription acknowledgment. Confirms unsubscription processing
PingReq(PingReq)
Keep-alive ping request. Must be responded to with PINGRESP
PingResp(PingResp)
Keep-alive ping response. Sent in response to PINGREQ to confirm connection is active
Disconnect(Disconnect)
Graceful connection termination. Properly closes the MQTT connection
Auth(Auth)
Authentication exchange. Used for extended authentication flows
Implementations§
Source§impl Packet
impl Packet
Sourcepub fn decode(raw_packet: RawPacket) -> Result<Self, Error>
pub fn decode(raw_packet: RawPacket) -> Result<Self, Error>
Decodes a raw MQTT packet into the appropriate Packet variant
This is the primary entry point for packet processing, handling:
- Packet type identification
- Payload validation
- Special cases for empty payload packets
- Delegation to specific packet decoders