Struct GenericPubrel

Source
pub struct GenericPubrel<PacketIdType>
where PacketIdType: IsPacketId,
{ pub props: Option<Properties>, /* private fields */ }
Expand description

A PUBREL packet for MQTT v5.0 protocol.

The PUBREL packet is the third packet in the QoS 2 PUBLISH message exchange sequence. It is sent in response to a PUBREC packet and triggers the final PUBCOMP response. This packet instructs the receiver to release any stored state for the specified packet identifier and complete the QoS 2 delivery sequence.

§MQTT v5.0 Specification

According to the MQTT v5.0 specification, the PUBREL packet:

  • Is sent by the sender of a PUBLISH packet with QoS 2 in response to a PUBREC
  • Contains the same Packet Identifier as the original PUBLISH and PUBREC packets
  • Has a fixed header with packet type 6 (0110) and reserved bits set to 0010
  • May optionally include a reason code indicating the result of the release operation
  • May optionally include properties for additional metadata
  • Must be acknowledged with a PUBCOMP packet

§QoS 2 Message Flow

The PUBREL packet is part of the four-packet QoS 2 handshake:

  1. PUBLISH (QoS 2) -> 2. PUBREC -> 3. PUBREL -> 4. PUBCOMP

§Generic Support

This struct supports generic packet identifiers through the PacketIdType parameter, allowing for extended packet ID ranges (e.g., u32) for broker clustering scenarios. The standard type alias Pubrel uses u16 packet identifiers as per MQTT specification.

§Examples

Creating a basic PUBREL packet:

use mqtt_protocol_core::mqtt;
use mqtt_protocol_core::mqtt::prelude::*;

let pubrel = mqtt::packet::v5_0::Pubrel::builder()
    .packet_id(123u16)
    .build()
    .unwrap();

assert_eq!(pubrel.packet_id(), 123u16);

Creating a PUBREL with reason code:

use mqtt_protocol_core::mqtt;
use mqtt_protocol_core::mqtt::prelude::*;

let pubrel = mqtt::packet::v5_0::Pubrel::builder()
    .packet_id(456u16)
    .reason_code(mqtt::result_code::PubrelReasonCode::Success)
    .build()
    .unwrap();

assert_eq!(pubrel.packet_id(), 456u16);
assert_eq!(pubrel.reason_code(), Some(mqtt::result_code::PubrelReasonCode::Success));

Creating a PUBREL with properties:

use mqtt_protocol_core::mqtt;
use mqtt_protocol_core::mqtt::prelude::*;

let props = mqtt::packet::Properties::from(vec![
    mqtt::packet::Property::ReasonString("Release successful".to_string())
]);

let pubrel = mqtt::packet::v5_0::Pubrel::builder()
    .packet_id(789u16)
    .reason_code(mqtt::result_code::PubrelReasonCode::Success)
    .props(props)
    .build()
    .unwrap();

Fields§

§props: Option<Properties>

Optional MQTT v5.0 properties associated with this PUBREL packet.

Properties can include:

  • ReasonString: Human readable string designed for diagnostics
  • UserProperty: Name-value pairs for application-specific metadata

Only one ReasonString property is allowed per packet. Properties can only be included if a reason code is also present.

Implementations§

Source§

impl<PacketIdType> GenericPubrel<PacketIdType>
where PacketIdType: IsPacketId,

Source

pub fn props(&self) -> &Option<Properties>

Optional MQTT v5.0 properties associated with this PUBREL packet.

Properties can include:

  • ReasonString: Human readable string designed for diagnostics
  • UserProperty: Name-value pairs for application-specific metadata

Only one ReasonString property is allowed per packet. Properties can only be included if a reason code is also present.

Source§

impl<PacketIdType> GenericPubrel<PacketIdType>
where PacketIdType: IsPacketId,

Source

pub fn builder() -> GenericPubrelBuilder<PacketIdType>

Creates a new builder for constructing a PUBREL packet.

§Returns

A new GenericPubrelBuilder instance for building PUBREL packets.

§Examples
use mqtt_protocol_core::mqtt;

let builder = mqtt::packet::v5_0::Pubrel::builder();
let pubrel = builder
    .packet_id(42u16)
    .build()
    .unwrap();
Source

pub fn packet_type() -> PacketType

Returns the packet type for PUBREL packets.

§Returns

Always returns PacketType::Pubrel.

§Examples
use mqtt_protocol_core::mqtt;

let packet_type = mqtt::packet::v5_0::Pubrel::packet_type();
assert_eq!(packet_type, mqtt::packet::packet_type::PacketType::Pubrel);
Source

pub fn packet_id(&self) -> PacketIdType

Returns the packet identifier of this PUBREL packet.

The packet identifier must match the packet identifier of the original PUBLISH and PUBREC packets in the QoS 2 message exchange.

§Returns

The packet identifier as the specified PacketIdType.

§Examples
use mqtt_protocol_core::mqtt;

let pubrel = mqtt::packet::v5_0::Pubrel::builder()
    .packet_id(1337u16)
    .build()
    .unwrap();

assert_eq!(pubrel.packet_id(), 1337u16);
Source

pub fn reason_code(&self) -> Option<PubrelReasonCode>

Returns the reason code of this PUBREL packet, if present.

The reason code indicates the result of the packet identifier release operation. If no reason code is present, it implies successful processing (equivalent to PubrelReasonCode::Success).

Available reason codes:

  • Success: The packet identifier has been released successfully
  • PacketIdentifierNotFound: The specified packet identifier was not found
§Returns

An Option<PubrelReasonCode> containing the reason code if present, or None if no reason code was included in the packet.

§Examples
use mqtt_protocol_core::mqtt;

let pubrel = mqtt::packet::v5_0::Pubrel::builder()
    .packet_id(123u16)
    .reason_code(mqtt::result_code::PubrelReasonCode::Success)
    .build()
    .unwrap();

assert_eq!(pubrel.reason_code(),
           Some(mqtt::result_code::PubrelReasonCode::Success));
Source

pub fn size(&self) -> usize

Returns the total size of this PUBREL packet in bytes.

This includes the fixed header, variable header (packet identifier, optional reason code), and optional properties.

§Returns

The total packet size in bytes as a usize.

§Examples
use mqtt_protocol_core::mqtt;

let pubrel = mqtt::packet::v5_0::Pubrel::builder()
    .packet_id(1u16)
    .build()
    .unwrap();

let size = pubrel.size();
// Minimum size: 1 (fixed header) + 1 (remaining length) + 2 (packet id)
assert!(size >= 4);
Source

pub fn to_buffers(&self) -> Vec<IoSlice<'_>>

Converts this PUBREL packet into a vector of I/O slices for efficient network transmission.

This method creates zero-copy I/O slices that can be used with vectored I/O operations for efficient packet transmission over network connections.

§Returns

A Vec<IoSlice<'_>> containing slices of the packet data ready for transmission. The slices are ordered according to the MQTT v5.0 packet structure.

§Examples
use mqtt_protocol_core::mqtt;

let pubrel = mqtt::packet::v5_0::Pubrel::builder()
    .packet_id(1u16)
    .build()
    .unwrap();

let buffers = pubrel.to_buffers();
// Can be used with vectored write operations
Source

pub fn parse(data: &[u8]) -> Result<(Self, usize), MqttError>

Parses a PUBREL packet from raw bytes.

This method deserializes a PUBREL packet from its wire format according to the MQTT v5.0 specification. It validates the packet structure and ensures all components are correctly formatted.

§Parameters
  • data - The raw byte slice containing the PUBREL packet data (excluding fixed header)
§Returns

A Result containing:

  • Ok((GenericPubrel<PacketIdType>, usize)) - The parsed packet and number of bytes consumed
  • Err(MqttError) - Parsing error if the packet is malformed
§Errors

Returns MqttError::MalformedPacket if:

  • The packet identifier is zero (invalid)
  • The reason code is invalid
  • The property format is incorrect
  • The packet is truncated or malformed
§Examples
use mqtt_protocol_core::mqtt;

let packet_data = &[0x00, 0x01]; // Packet ID = 1
match mqtt::packet::v5_0::Pubrel::parse(packet_data) {
    Ok((pubrel, consumed)) => {
        assert_eq!(pubrel.packet_id(), 1u16);
        assert_eq!(consumed, 2);
    }
    Err(e) => panic!("Parse error: {:?}", e),
}

Trait Implementations§

Source§

impl AsConcrete<GenericPubrel<u16>> for Packet

Source§

impl<PacketIdType> Clone for GenericPubrel<PacketIdType>
where PacketIdType: IsPacketId + Clone, PacketIdType::Buffer: Clone,

Source§

fn clone(&self) -> GenericPubrel<PacketIdType>

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<PacketIdType> Debug for GenericPubrel<PacketIdType>
where PacketIdType: IsPacketId + Serialize,

Debug trait implementation for PUBREL packets.

This implementation provides debug formatting that delegates to the Display implementation, ensuring consistent output format for both debugging and display purposes.

§Examples

use mqtt_protocol_core::mqtt;

let pubrel = mqtt::packet::v5_0::Pubrel::builder()
    .packet_id(123u16)
    .build()
    .unwrap();

println!("{:?}", pubrel);
// Output: {"type":"pubrel","packet_id":123}
Source§

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

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

impl<PacketIdType> Display for GenericPubrel<PacketIdType>
where PacketIdType: IsPacketId + Serialize,

Display trait implementation for PUBREL packets.

This implementation provides a human-readable string representation of the PUBREL packet in JSON format. This is useful for debugging, logging, and diagnostic purposes.

§Format

The output format is a JSON string containing:

  • type: The packet type (“pubrel”)
  • packet_id: The packet identifier
  • reason_code: The reason code (if present)
  • props: The properties (if present)

If serialization fails, an error message is returned in JSON format.

§Examples

use mqtt_protocol_core::mqtt;

let pubrel = mqtt::packet::v5_0::Pubrel::builder()
    .packet_id(42u16)
    .build()
    .unwrap();

println!("{}", pubrel);
// Output: {"type":"pubrel","packet_id":42}
Source§

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

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

impl<PacketIdType> From<GenericPubrel<PacketIdType>> for GenericPacket<PacketIdType>
where PacketIdType: IsPacketId + Serialize,

Source§

fn from(v: GenericPubrel<PacketIdType>) -> GenericPacket<PacketIdType>

Converts to this type from the input type.
Source§

impl<PacketIdType> GenericPacketDisplay for GenericPubrel<PacketIdType>
where PacketIdType: IsPacketId + Serialize,

Generic packet display trait implementation for PUBREL packets.

This implementation provides generic display formatting capabilities that can be used by the MQTT protocol library framework for consistent packet representation across different display contexts.

§Methods

  • fmt_debug(): Provides debug formatting via the Debug trait
  • fmt_display(): Provides display formatting via the Display trait
Source§

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

Source§

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

Source§

impl<PacketIdType> GenericPacketTrait for GenericPubrel<PacketIdType>
where PacketIdType: IsPacketId,

Generic packet trait implementation for PUBREL packets.

This implementation provides the generic packet interface required by the MQTT protocol library framework. It enables PUBREL packets to be used polymorphically with other packet types in the system.

§Methods

  • size(): Returns the total packet size in bytes
  • to_buffers(): Returns I/O slices for efficient transmission
Source§

fn size(&self) -> usize

Source§

fn to_buffers(&self) -> Vec<IoSlice<'_>>

Source§

impl IntoConcreteOwned<GenericPubrel<u16>> for Packet

Source§

impl<PacketIdType> PacketKind for GenericPubrel<PacketIdType>
where PacketIdType: IsPacketId,

Source§

const IS_PUBREL: bool = true

true if this is a PUBREL packet
Source§

const IS_V5_0: bool = true

true if this is an MQTT v5.0 packet
Source§

const IS_CONNECT: bool = false

true if this is a CONNECT packet
Source§

const IS_CONNACK: bool = false

true if this is a CONNACK packet
Source§

const IS_PUBLISH: bool = false

true if this is a PUBLISH packet
Source§

const IS_PUBACK: bool = false

true if this is a PUBACK packet
Source§

const IS_PUBREC: bool = false

true if this is a PUBREC packet
Source§

const IS_PUBCOMP: bool = false

true if this is a PUBCOMP packet
Source§

const IS_SUBSCRIBE: bool = false

true if this is a SUBSCRIBE packet
Source§

const IS_SUBACK: bool = false

true if this is a SUBACK packet
Source§

const IS_UNSUBSCRIBE: bool = false

true if this is an UNSUBSCRIBE packet
Source§

const IS_UNSUBACK: bool = false

true if this is an UNSUBACK packet
Source§

const IS_PINGREQ: bool = false

true if this is a PINGREQ packet
Source§

const IS_PINGRESP: bool = false

true if this is a PINGRESP packet
Source§

const IS_DISCONNECT: bool = false

true if this is a DISCONNECT packet
Source§

const IS_AUTH: bool = false

true if this is an AUTH packet (v5.0 only)
Source§

const IS_V3_1_1: bool = false

true if this is an MQTT v3.1.1 packet
Source§

impl<PacketIdType> PartialEq for GenericPubrel<PacketIdType>
where PacketIdType: IsPacketId + PartialEq, PacketIdType::Buffer: PartialEq,

Source§

fn eq(&self, other: &GenericPubrel<PacketIdType>) -> 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<PacketIdType> Serialize for GenericPubrel<PacketIdType>
where PacketIdType: IsPacketId + Serialize,

Serialize implementation for PUBREL packets.

This implementation allows PUBREL packets to be serialized into various formats (JSON, YAML, etc.) using the serde framework. The serialization includes all relevant packet fields in a structured format.

§Serialized Fields

  • type: Always “pubrel” to identify the packet type
  • packet_id: The packet identifier value
  • reason_code: The reason code (if present)
  • props: The properties (if present)

§Examples

use mqtt_protocol_core::mqtt;
use serde_json;

let pubrel = mqtt::packet::v5_0::Pubrel::builder()
    .packet_id(123u16)
    .reason_code(mqtt::result_code::PubrelReasonCode::Success)
    .build()
    .unwrap();

let json = serde_json::to_string(&pubrel).unwrap();
// Result: {"type":"pubrel","packet_id":123,"reason_code":"Success"}
Source§

fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl<PacketIdType> TryFrom<GenericPubrel<PacketIdType>> for GenericStorePacket<PacketIdType>
where PacketIdType: IsPacketId + Serialize,

Source§

type Error = MqttError

The type returned in the event of a conversion error.
Source§

fn try_from(pubrel: GenericPubrel<PacketIdType>) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl<PacketIdType> TryInto<GenericPubrel<PacketIdType>> for GenericPacket<PacketIdType>
where PacketIdType: IsPacketId + Serialize,

Source§

type Error = &'static str

The type returned in the event of a conversion error.
Source§

fn try_into( self, ) -> Result<GenericPubrel<PacketIdType>, <Self as TryInto<GenericPubrel<PacketIdType>>>::Error>

Performs the conversion.
Source§

impl<PacketIdType> Eq for GenericPubrel<PacketIdType>
where PacketIdType: IsPacketId + Eq, PacketIdType::Buffer: Eq,

Source§

impl<PacketIdType> SendableRole<Any> for GenericPubrel<PacketIdType>
where PacketIdType: IsPacketId,

Source§

impl<PacketIdType> SendableRole<Client> for GenericPubrel<PacketIdType>
where PacketIdType: IsPacketId,

Source§

impl<PacketIdType> SendableRole<Server> for GenericPubrel<PacketIdType>
where PacketIdType: IsPacketId,

Source§

impl<PacketIdType> StructuralPartialEq for GenericPubrel<PacketIdType>
where PacketIdType: IsPacketId,

Auto Trait Implementations§

§

impl<PacketIdType> Freeze for GenericPubrel<PacketIdType>
where <PacketIdType as IsPacketId>::Buffer: Freeze,

§

impl<PacketIdType> RefUnwindSafe for GenericPubrel<PacketIdType>
where <PacketIdType as IsPacketId>::Buffer: RefUnwindSafe,

§

impl<PacketIdType> Send for GenericPubrel<PacketIdType>
where <PacketIdType as IsPacketId>::Buffer: Send,

§

impl<PacketIdType> Sync for GenericPubrel<PacketIdType>
where <PacketIdType as IsPacketId>::Buffer: Sync,

§

impl<PacketIdType> Unpin for GenericPubrel<PacketIdType>
where <PacketIdType as IsPacketId>::Buffer: Unpin,

§

impl<PacketIdType> UnwindSafe for GenericPubrel<PacketIdType>
where <PacketIdType as IsPacketId>::Buffer: UnwindSafe,

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> AsConcrete<T> for T

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<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> IntoConcreteOwned<T> for T

Source§

impl<Role, PacketIdType, T> Sendable<Role, PacketIdType> for T
where Role: RoleType, PacketIdType: IsPacketId, T: SendableRole<Role> + SendableVersion + Display + Debug + PacketKind + SendableHelper<Role, PacketIdType>,

Source§

fn dispatch_send( self, connection: &mut GenericConnection<Role, PacketIdType>, ) -> Vec<GenericEvent<PacketIdType>>

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> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. 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.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more