PrevUpHomeNext

PUBACK properties

The last field in the Variable header of PUBACK packet is a set of Properties. A set contains a Property Length followed by the Properties. A Property consists of an Identifier and a value.

This section lists all possible PUBACK Properties and describes their usage:

Table 1.8. PUBACK properties

Identifier

Value type

Description

reason_string

std::string

A UTF-8 Encoded String representing the reason associated with this response.

user_property

std::pair<std::string, std::string>

Name, value pair (UTF-8 String Pair) defining User Property. There can be multiple pairs in one packet. This property may be used to provide additional diagnostic or other information.


Usage

After obtaining an instance of async_mqtt5::puback_props, the subscript operator can be used to access a Property.

The Identifiers listed in the table above are available within the async_mqtt5::prop namespace for Property access.

[Note] Note

When accessing a property value, the subscript operator will return a std::optional of the value type for all properties, except for async_mqtt5::prop::user_property, where it will return an instance of std::vector<std::pair<std::string, std::string>>.

Example

The following example shows how to set a Property value:

async_mqtt5::puback_props props;
props[async_mqtt5::prop::reason_string] = "Some reason...";
props[async_mqtt5::prop::user_property].emplace_back("name", "value");

The following example shows how to retrieve a Property value:

std::optional<std::string> reason_string = props[async_mqtt5::prop::reason_string];
if (reason_string.has_value())
	// reason string property was previously set
else
	// reason string property was not set

std::vector<std::pair<std::string, std::string>>& user_props = props[async_mqtt5::prop::user_property];
if (!user_props.empty())
	// user property was previously set
else
	// user property was not set

PrevUpHomeNext