ntex_mqtt/
types.rs

1pub(crate) const MQTT: &[u8] = b"MQTT";
2pub(crate) const MQTT_LEVEL_3: u8 = 4;
3pub(crate) const MQTT_LEVEL_5: u8 = 5;
4pub(crate) const WILL_QOS_SHIFT: u8 = 3;
5
6/// Max possible packet size
7pub(crate) const MAX_PACKET_SIZE: u32 = 0xF_FF_FF_FF;
8
9prim_enum! {
10    /// Quality of Service
11    #[derive(serde::Serialize, serde::Deserialize, PartialOrd, Ord, Hash)]
12    pub enum QoS {
13        /// At most once delivery
14        ///
15        /// The message is delivered according to the capabilities of the underlying network.
16        /// No response is sent by the receiver and no retry is performed by the sender.
17        /// The message arrives at the receiver either once or not at all.
18        AtMostOnce = 0,
19        /// At least once delivery
20        ///
21        /// This quality of service ensures that the message arrives at the receiver at least once.
22        /// A QoS 1 PUBLISH Packet has a Packet Identifier in its variable header
23        /// and is acknowledged by a PUBACK Packet.
24        AtLeastOnce = 1,
25        /// Exactly once delivery
26        ///
27        /// This is the highest quality of service,
28        /// for use when neither loss nor duplication of messages are acceptable.
29        /// There is an increased overhead associated with this quality of service.
30        ExactlyOnce = 2
31    }
32}
33
34bitflags::bitflags! {
35    #[derive(Copy, Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)]
36    pub struct ConnectFlags: u8 {
37        const USERNAME    = 0b1000_0000;
38        const PASSWORD    = 0b0100_0000;
39        const WILL_RETAIN = 0b0010_0000;
40        const WILL_QOS    = 0b0001_1000;
41        const WILL        = 0b0000_0100;
42        const CLEAN_START = 0b0000_0010;
43    }
44}
45
46bitflags::bitflags! {
47    #[derive(Copy, Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)]
48    pub struct ConnectAckFlags: u8 {
49        const SESSION_PRESENT = 0b0000_0001;
50    }
51}
52
53pub(super) mod packet_type {
54    pub(crate) const CONNECT: u8 = 0b0001_0000;
55    pub(crate) const CONNACK: u8 = 0b0010_0000;
56    pub(crate) const PUBLISH_START: u8 = 0b0011_0000;
57    pub(crate) const PUBLISH_END: u8 = 0b0011_1111;
58    pub(crate) const PUBACK: u8 = 0b0100_0000;
59    pub(crate) const PUBREC: u8 = 0b0101_0000;
60    pub(crate) const PUBREL: u8 = 0b0110_0010;
61    pub(crate) const PUBCOMP: u8 = 0b0111_0000;
62    pub(crate) const SUBSCRIBE: u8 = 0b1000_0010;
63    pub(crate) const SUBACK: u8 = 0b1001_0000;
64    pub(crate) const UNSUBSCRIBE: u8 = 0b1010_0010;
65    pub(crate) const UNSUBACK: u8 = 0b1011_0000;
66    pub(crate) const PINGREQ: u8 = 0b1100_0000;
67    pub(crate) const PINGRESP: u8 = 0b1101_0000;
68    pub(crate) const DISCONNECT: u8 = 0b1110_0000;
69    pub(crate) const AUTH: u8 = 0b1111_0000;
70
71    pub(crate) const fn is_publish(packet_type: u8) -> bool {
72        matches!(packet_type, PUBLISH_START..=PUBLISH_END)
73    }
74}
75
76#[derive(Debug, PartialEq, Eq, Clone, Copy)]
77pub(crate) struct FixedHeader {
78    /// Fixed Header byte
79    pub(crate) first_byte: u8,
80    /// the number of bytes remaining within the current packet,
81    /// including data in the variable header and the payload.
82    pub(crate) remaining_length: u32,
83}