Module protocol

Source
Expand description

§Protocol Implementation

Contains all MQTT packet definitions and protocol logic.

§Organization

  • v3: MQTT v3.1 protocol implementation
  • v4: MQTT v3.1.1 protocol implementation
  • v5: MQTT v5.0 protocol implementation
  • common: Shared types between protocol versions

§Example: Creating a CONNECT Packet

use std::time::Duration;
use mqute_codec::protocol::{v5::Connect, Credentials};

let connect = Connect::new(
    "client_id",
    Some(Credentials::login("user", "pass")),
    None,
    Duration::from_secs(30),  // keep alive
    true // clean session
);

§Example: Creating a PUBLISH Packet

use mqute_codec::protocol::v4::{Publish};
use mqute_codec::protocol::{Flags, QoS};
use bytes::Bytes;

let flag = Flags::new(QoS::AtLeastOnce);

let publish = Publish::new(
    "topic",
    1234,
    Bytes::from("payload"),
    flag
);

§MQTT Protocol Implementation

This module provides complete implementations of MQTT protocol versions 3.1, 3.1.1, and 5.0, with shared components for packet handling and protocol logic.

§Examples

§Working with different protocol versions

use std::time::Duration;
use mqute_codec::protocol::{v4, v5, Protocol};
use mqute_codec::protocol::QoS;

// Create v3.1.1 CONNECT packet
let connect_v4 = v4::Connect::new(
    "client_id",
    None,
    None,
    Duration::from_secs(30),
    true
);
assert_eq!(connect_v4.protocol(), Protocol::V4);

// Create v5 CONNECT with properties
let connect_v5 = v5::Connect::new(
    "client_id",
    None,
    None,
    Duration::from_secs(30),
    true
);
assert_eq!(connect_v5.protocol(), Protocol::V5);

Modules§

v3
MQTT v3.1 Implementation
v4
MQTT v3.1.1 Implementation
v5
MQTT v5.0 Implementation

Structs§

Codes
Re-export common protocol types The Codes module provides a generic structure to handle a collection of MQTT return codes. These codes are used in various MQTT control packets, such as ConnAck, SubAck, and UnsubAck.
Credentials
Represents authentication information for an MQTT connection.
FixedHeader
Represents the fixed header of an MQTT packet.
Flags
Represents the control flags in an MQTT packet.
TopicFilters
Re-export common protocol types The TopicFilters provides a structure to handle a collection of MQTT topic filters. Topic filters are used in MQTT subscriptions and unsubscriptions.

Enums§

PacketType
Represents the type of MQTT packet.
Protocol
Represents the MQTT protocol version.
QoS
Represents the Quality of Service (QoS) levels in MQTT.