mqute_codec/protocol/v5/
pubcomp.rs

1//! # Publish Complete Packet V5
2//!
3//! This module implements the MQTT v5 PubComp packet which is the final packet in
4//! the QoS 2 protocol flow, sent by either client or server to confirm receipt of
5//! a PubRel packet.
6
7use crate::protocol::v5::reason::ReasonCode;
8use crate::protocol::v5::util::{
9    ack, ack_decode_impl, ack_encode_impl, ack_properties, ack_properties_frame_impl,
10};
11use crate::protocol::{Flags, PacketType};
12
13/// Validates that a reason code is appropriate for a `PubComp` packet
14///
15/// MQTT v5 defines specific allowed reason codes for `PubComp`:
16/// - Success (0) - Normal completion of QoS 2 flow
17/// - Packet Identifier Not Found (146) - When the packet ID is unknown
18fn validate_pubcomp_reason_code(code: ReasonCode) -> bool {
19    matches!(code.into(), 0 | 146)
20}
21
22// Defines properties specific to `PubComp` packets
23ack_properties!(PubCompProperties);
24
25// Implements property frame handling for PubCompProperties
26ack_properties_frame_impl!(PubCompProperties);
27
28// Represents an MQTT v5 `PubComp` packet
29ack!(PubComp, PubCompProperties, validate_pubcomp_reason_code);
30
31// Implement decoding for `PubComp` packets
32ack_decode_impl!(
33    PubComp,
34    PacketType::PubComp,
35    Flags::default(),
36    validate_pubcomp_reason_code
37);
38
39// Implement encoding for `PubComp` packets
40ack_encode_impl!(PubComp, PacketType::PubComp, Flags::default());