mqute_codec/protocol/v5/pubrel.rs
1//! # Publish Release (PubRel) Packet - MQTT v5
2//!
3//! This module implements the MQTT v5 `PubRel` packet, which is the third packet in the
4//! Quality of Service 2 (QoS 2) message delivery flow. The `PubRel` packet is sent by the
5//! publisher in response to a `PubRec` to indicate it is releasing the stored message.
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, QoS};
12
13/// Validates reason codes for `PubRel` packets
14///
15/// MQTT v5 specifies only two valid reason codes for `PubRel`:
16/// - 0x00 (Success) - Packet released normally
17/// - 0x92 (Packet Identifier Not Found) - When the Packet ID is unknown
18fn validate_pubrel_reason_code(code: ReasonCode) -> bool {
19 matches!(code.into(), 0 | 146)
20}
21
22// Defines properties specific to `PubRel` packets
23ack_properties!(PubRelProperties);
24
25// Implements the PropertyFrame trait for PubRelProperties
26ack_properties_frame_impl!(PubRelProperties);
27
28// Represents an MQTT v5 `PubRel` packet
29ack!(PubRel, PubRelProperties, validate_pubrel_reason_code);
30
31// Implements packet decoding for `PubRel`
32ack_decode_impl!(
33 PubRel,
34 PacketType::PubRel,
35 Flags::new(QoS::AtLeastOnce),
36 validate_pubrel_reason_code
37);
38
39// Implements packet encoding for `PubRel`
40ack_encode_impl!(PubRel, PacketType::PubRel, Flags::new(QoS::AtLeastOnce));