GenericPuback

Struct GenericPuback 

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

A PUBACK packet for MQTT v5.0 protocol.

The PUBACK packet is the response to a PUBLISH packet with QoS level 1. This packet acknowledges the receipt of a PUBLISH packet and may contain a reason code and properties to provide additional information about the acknowledgment status.

§MQTT v5.0 Specification

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

  • Is sent by the receiver of a PUBLISH packet with QoS 1
  • Contains the same Packet Identifier as the PUBLISH packet being acknowledged
  • May optionally include a reason code indicating the result of the PUBLISH processing
  • May optionally include properties for additional metadata

§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 Puback uses u16 packet identifiers as per MQTT specification.

§Examples

Creating a basic PUBACK packet:

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

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

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

Creating a PUBACK with reason code:

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

let puback = mqtt::packet::v5_0::Puback::builder()
    .packet_id(456u16)
    .reason_code(mqtt::result_code::PubackReasonCode::Success)
    .build()
    .unwrap();

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

Fields§

§props: Option<Properties>

Optional MQTT v5.0 properties associated with this PUBACK 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.

Implementations§

Source§

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

Source

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

Optional MQTT v5.0 properties associated with this PUBACK 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.

Source§

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

Source

pub fn builder() -> GenericPubackBuilder<PacketIdType>

Creates a new builder for constructing a PUBACK packet.

§Returns

A new GenericPubackBuilder instance for building PUBACK packets.

§Examples
use mqtt_protocol_core::mqtt;

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

pub fn packet_type() -> PacketType

Returns the packet type for PUBACK packets.

§Returns

Always returns PacketType::Puback.

§Examples
use mqtt_protocol_core::mqtt;

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

pub fn packet_id(&self) -> PacketIdType

Returns the packet identifier of this PUBACK packet.

The packet identifier must match the packet identifier of the PUBLISH packet that this PUBACK is acknowledging.

§Returns

The packet identifier as the specified PacketIdType.

§Examples
use mqtt_protocol_core::mqtt;

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

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

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

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

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

§Returns

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

§Examples
use mqtt_protocol_core::mqtt;
use mqtt_protocol_core::mqtt::prelude::*;

// PUBACK without reason code (implies success)
let puback = mqtt::packet::v5_0::Puback::builder()
    .packet_id(1u16)
    .build()
    .unwrap();

assert_eq!(puback.reason_code(), None);

// PUBACK with explicit reason code
let puback_with_reason = mqtt::packet::v5_0::Puback::builder()
    .packet_id(2u16)
    .reason_code(mqtt::result_code::PubackReasonCode::NoMatchingSubscribers)
    .build()
    .unwrap();

assert_eq!(puback_with_reason.reason_code(),
           Some(mqtt::result_code::PubackReasonCode::NoMatchingSubscribers));
Source

pub fn size(&self) -> usize

Returns the total size of the PUBACK packet in bytes.

This includes the fixed header, remaining length field, packet identifier, optional reason code, optional property length, and optional properties.

§Returns

The total packet size in bytes.

§Examples
use mqtt_protocol_core::mqtt;

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

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

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

Converts the PUBACK packet into a vector of I/O slices for efficient transmission.

This method prepares the packet data for network transmission by organizing it into a series of byte slices that can be sent without additional copying.

§Returns

A Vec<IoSlice<'_>> containing the packet data organized as I/O slices. The slices are ordered as: fixed header, remaining length, packet identifier, optional reason code, optional property length, and optional properties.

§Examples
use mqtt_protocol_core::mqtt;

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

let buffers = puback.to_buffers();
assert!(!buffers.is_empty());
Source

pub fn to_continuous_buffer(&self) -> Vec<u8>

Create a continuous buffer containing the complete packet data

Returns a vector containing all packet bytes in a single continuous buffer. This method provides an alternative to to_buffers() for no-std environments where vectored I/O is not available.

The returned buffer contains the complete PUBACK packet serialized according to the MQTT v5.0 protocol specification, including fixed header, remaining length, packet identifier, optional reason code, and optional properties.

§Returns

A vector containing the complete packet data

§Examples
use mqtt_protocol_core::mqtt;

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

let buffer = puback.to_continuous_buffer();
assert!(!buffer.is_empty());
Source

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

Parses a PUBACK packet from raw bytes.

This method deserializes a byte array into a PUBACK packet structure, validating the packet format and extracting all components including packet identifier, optional reason code, and optional properties.

§Parameters
  • data - A byte slice containing the PUBACK packet data (excluding fixed header and remaining length)
§Returns

A Result containing:

  • Ok((Self, usize)) - The parsed PUBACK packet and the number of bytes consumed
  • Err(MqttError) - An error if the packet is malformed or invalid
§Errors

Returns MqttError::MalformedPacket if:

  • The packet identifier is zero (invalid)
  • The data is too short to contain a valid packet identifier
  • The reason code is invalid
  • Properties are malformed

Returns MqttError::ProtocolError if:

  • Invalid properties are present for PUBACK packets
  • More than one ReasonString property is present
§Examples
use mqtt_protocol_core::mqtt;

// Parse PUBACK packet data
let data = &[0x00, 0x01]; // packet_id = 1
let (puback, consumed) = mqtt::packet::v5_0::Puback::parse(data).unwrap();

assert_eq!(puback.packet_id(), 1u16);
assert_eq!(consumed, 2);

Trait Implementations§

Source§

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

Source§

fn clone(&self) -> GenericPuback<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 GenericPuback<PacketIdType>
where PacketIdType: IsPacketId + Serialize,

Debug implementation for GenericPuback.

Uses the same JSON formatting as the Display implementation to provide consistent debug output across the library.

§Examples

use mqtt_protocol_core::mqtt;

let puback = mqtt::packet::v5_0::Puback::builder()
    .packet_id(456u16)
    .build()
    .unwrap();

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

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

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

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

Display implementation for GenericPuback.

Formats the PUBACK packet as JSON for human-readable output. This is useful for logging, debugging, and diagnostic purposes.

§Output Format

The output is JSON formatted and includes all packet fields. If serialization fails, an error message is displayed instead.

§Examples

use mqtt_protocol_core::mqtt;

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

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

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

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

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

Source§

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

Converts to this type from the input type.
Source§

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

GenericPacketDisplay implementation for GenericPuback.

Provides formatted display capabilities for the PUBACK packet that can be used by the generic packet display system. This enables consistent formatting across all packet types.

§Trait Methods

  • fmt_debug(): Debug formatting (JSON output)
  • fmt_display(): Display formatting (JSON output)
Source§

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

Source§

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

Source§

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

GenericPacketTrait implementation for GenericPuback.

Provides the core packet interface methods required by the MQTT protocol library. This trait enables the PUBACK packet to be used generically alongside other packet types in the protocol processing pipeline.

§Trait Methods

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

fn size(&self) -> usize

Source§

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

Source§

fn to_continuous_buffer(&self) -> Vec<u8>

Create a continuous buffer containing the complete packet data Read more
Source§

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

Source§

const IS_PUBACK: bool = true

true if this is a PUBACK 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_PUBREC: bool = false

true if this is a PUBREC packet
Source§

const IS_PUBREL: bool = false

true if this is a PUBREL 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 GenericPuback<PacketIdType>
where PacketIdType: IsPacketId + PartialEq, PacketIdType::Buffer: PartialEq,

Source§

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

Serialize implementation for GenericPuback.

Serializes the PUBACK packet into a structured format suitable for JSON output or other serialization formats. The serialization includes the packet type, packet identifier, optional reason code, and optional properties.

§Serialized Fields

  • type: Always “puback”
  • packet_id: The packet identifier
  • reason_code: Present only if a reason code was set
  • props: Present only if properties were set

§Examples

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

let puback = mqtt::packet::v5_0::Puback::builder()
    .packet_id(42u16)
    .reason_code(mqtt::result_code::PubackReasonCode::Success)
    .build()
    .unwrap();

let json = serde_json::to_string(&puback).unwrap();
// JSON will contain: {"type":"puback","packet_id":42,"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> TryInto<GenericPuback<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<GenericPuback<PacketIdType>, <Self as TryInto<GenericPuback<PacketIdType>>>::Error>

Performs the conversion.
Source§

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

Source§

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

Source§

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

Source§

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

Source§

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

Auto Trait Implementations§

§

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

§

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

§

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

§

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

§

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

§

impl<PacketIdType> UnwindSafe for GenericPuback<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> 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, 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<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.