Enum Packet

Source
pub enum Packet {
Show 15 variants Connect(Connect), ConnAck(ConnAck), Publish(Publish), PubAck(PubAck), PubRec(PubRec), PubRel(PubRel), PubComp(PubComp), Subscribe(Subscribe), SubAck(SubAck), Unsubscribe(Unsubscribe), UnsubAck(UnsubAck), PingReq(PingReq), PingResp(PingResp), Disconnect(Disconnect), Auth(Auth),
}
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

Source

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
Source

pub fn encode(&self, buf: &mut BytesMut) -> Result<(), Error>

Encodes the packet into its wire format

Delegates to the specific packet implementation’s encoder while providing a unified interface for all packet types.

Trait Implementations§

Source§

impl Clone for Packet

Source§

fn clone(&self) -> Packet

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
Source§

impl Debug for Packet

Source§

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

Formats the value using the given formatter. Read more
Source§

impl PartialEq for Packet

Source§

fn eq(&self, other: &Packet) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Eq for Packet

Source§

impl StructuralPartialEq for Packet

Auto Trait Implementations§

§

impl !Freeze for Packet

§

impl RefUnwindSafe for Packet

§

impl Send for Packet

§

impl Sync for Packet

§

impl Unpin for Packet

§

impl UnwindSafe for Packet

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.