Loading...
Searching...
No Matches
mqtt Namespace Reference

## Data Structures

class | async_client
class | buffer_ref
class | buffer_view
class | callback
class | client
class | connect_options
class | connect_data
class | connect_options_builder
struct | no_persistence
class | create_options
class | create_options_builder
class | delivery_token
class | disconnect_options
class | disconnect_options_builder
struct | connected_event
struct | connection_lost_event
struct | disconnected_event
struct | shutdown_event
class | event
class | exception
class | missing_response
class | timeout_error
class | persistence_exception
class | security_exception
class | iaction_listener
class | iasync_client
class | iclient_persistence
class | message
class | message_ptr_builder
class | property
class | properties
class | response_options
class | response_options_builder
class | delivery_response_options
class | server_response
class | connect_response
struct | subscribe_response
class | unsubscribe_response
class | ssl_options
class | ssl_options_builder
class | string_collection
class | name_value_collection
class | subscribe_options
class | queue_closed
class | thread_queue
class | token
class | topic
class | topic_filter
class | topic_matcher
class | will_options

## Typedefs

using | async_client_ptr = async_client::ptr_t
using | string_ref = buffer_ref<char>
using | binary_ref = buffer_ref<char>
using | string_view = buffer_view<char>
using | binary_view = buffer_view<char>
using | callback_ptr = callback::ptr_t
using | const_callback_ptr = callback::const_ptr_t
using | client_ptr = client::ptr_t
using | connect_options_ptr = connect_options::ptr_t
using | persistence_type = std::variant<no_persistence, string, iclient_persistence*>
using | create_options_ptr = create_options::ptr_t
using | delivery_token_ptr = delivery_token::ptr_t
using | const_delivery_token_ptr = delivery_token::const_ptr_t
using | bad_cast = std::bad_cast
using | iaction_listener_ptr = iaction_listener::ptr_t
using | const_iaction_listener_ptr = iaction_listener::const_ptr_t
using | iclient_persistence_ptr = iclient_persistence::ptr_t
using | const_iclient_persistence_ptr = iclient_persistence::const_ptr_t
using | message_ptr = message::ptr_t
using | const_message_ptr = message::const_ptr_t
using | string_pair = std::tuple<string, string>
using | ssl_options_ptr = ssl_options::ptr_t
using | ssl_options_unique_ptr = ssl_options::unique_ptr_t
using | string_collection_ptr = string_collection::ptr_t
using | const_string_collection_ptr = string_collection::const_ptr_t
using | subscribe_options_ptr = subscribe_options::ptr_t
using | token_ptr = token::ptr_t
using | const_token_ptr = token::const_ptr_t
using | topic_ptr = topic::ptr_t
using | const_topic_ptr = topic::const_ptr_t
using | byte = uint8_t
using | string = std::string
using | binary = std::string
using | string_ptr = std::shared_ptr<const string>
using | binary_ptr = std::shared_ptr<const binary>
using | will_options_ptr = will_options::ptr_t
using | const_will_options_ptr = will_options::const_ptr_t
using | will_options_unique_ptr = will_options::unique_ptr_t

## Enumerations

enum

ReasonCode {
SUCCESS = 0 , NORMAL_DISCONNECTION = 0 , GRANTED_QOS_0 = 0 , GRANTED_QOS_1 = 1 ,
GRANTED_QOS_2 = 2 , DISCONNECT_WITH_WILL_MESSAGE = 4 , NO_MATCHING_SUBSCRIBERS = 16 , NO_SUBSCRIPTION_FOUND = 17 ,
CONTINUE_AUTHENTICATION = 24 , RE_AUTHENTICATE = 25 , UNSPECIFIED_ERROR = 128 , MALFORMED_PACKET = 129 ,
PROTOCOL_ERROR = 130 , IMPLEMENTATION_SPECIFIC_ERROR = 131 , UNSUPPORTED_PROTOCOL_VERSION = 132 , CLIENT_IDENTIFIER_NOT_VALID = 133 ,
BAD_USER_NAME_OR_PASSWORD = 134 , NOT_AUTHORIZED = 135 , SERVER_UNAVAILABLE = 136 , SERVER_BUSY = 137 ,
BANNED = 138 , SERVER_SHUTTING_DOWN = 139 , BAD_AUTHENTICATION_METHOD = 140 , KEEP_ALIVE_TIMEOUT = 141 ,
SESSION_TAKEN_OVER = 142 , TOPIC_FILTER_INVALID = 143 , TOPIC_NAME_INVALID = 144 , PACKET_IDENTIFIER_IN_USE = 145 ,
PACKET_IDENTIFIER_NOT_FOUND = 146 , RECEIVE_MAXIMUM_EXCEEDED = 147 , TOPIC_ALIAS_INVALID = 148 , PACKET_TOO_LARGE = 149 ,
MESSAGE_RATE_TOO_HIGH = 150 , QUOTA_EXCEEDED = 151 , ADMINISTRATIVE_ACTION = 152 , PAYLOAD_FORMAT_INVALID = 153 ,
RETAIN_NOT_SUPPORTED = 154 , QOS_NOT_SUPPORTED = 155 , USE_ANOTHER_SERVER = 156 , SERVER_MOVED = 157 ,
SHARED_SUBSCRIPTIONS_NOT_SUPPORTED = 158 , CONNECTION_RATE_EXCEEDED = 159 , MAXIMUM_CONNECT_TIME = 160 , SUBSCRIPTION_IDENTIFIERS_NOT_SUPPORTED = 161 ,
WILDCARD_SUBSCRIPTIONS_NOT_SUPPORTED = 162 , MQTTPP_V3_CODE = 0
}

## Functions

const string | PAHO_MQTTPP_VERSION_STR ("Paho MQTT C++ (mqttpp) v1.6.0")
const string | PAHO_MQTTPP_COPYRIGHT ("Copyright (c) 2013-2026 Frank Pagliughi")
template<typename T>
std::ostream & | operator<< (std::ostream &os, const buffer_ref< T > &buf)
template<typename T>
std::ostream & | operator<< (std::ostream &os, const buffer_view< T > &buf)
std::ostream & | operator<< (std::ostream &os, const exception &exc)
void * | persistence_malloc (size_t n)
void | persistence_free (void *p)
message_ptr | make_message (string_ref topic, const void *payload, size_t len, int qos, bool retained, const properties &props=properties())
message_ptr | make_message (string_ref topic, const void *payload, size_t len)
message_ptr | make_message (string_ref topic, binary_ref payload, int qos, bool retained, const properties &props=properties())
message_ptr | make_message (string_ref topic, binary_ref payload)
std::ostream & | operator<< (std::ostream &os, const property &prop)
template<typename T>
T | get (const property &)
template<>
uint8_t | get< uint8_t > (const property &prop)
template<>
uint16_t | get< uint16_t > (const property &prop)
template<>
int16_t | get< int16_t > (const property &prop)
template<>
uint32_t | get< uint32_t > (const property &prop)
template<>
int32_t | get< int32_t > (const property &prop)
template<>
string | get< string > (const property &prop)
template<>
string_pair | get< string_pair > (const property &prop)
template<typename T>
T | get (const properties &props, property::code propid, size_t idx)
template<typename T>
T | get (const properties &props, property::code propid)
std::string | to_string (ReasonCode reasonCode)
std::ostream & | operator<< (std::ostream &os, ReasonCode reasonCode)
template<class Rep, class Period>
std::chrono::seconds | to_seconds (const std::chrono::duration< Rep, Period > &dur)
template<class Rep, class Period>
long | to_seconds_count (const std::chrono::duration< Rep, Period > &dur)
template<class Rep, class Period>
std::chrono::milliseconds | to_milliseconds (const std::chrono::duration< Rep, Period > &dur)
template<class Rep, class Period>
long | to_milliseconds_count (const std::chrono::duration< Rep, Period > &dur)
bool | to_bool (int n)
int | to_int (bool b)
string | to_string (const char *cstr)

## Variables

const uint32_t | PAHO_MQTTPP_VERSION = 0x01060000
const uint32_t | VERSION {PAHO_MQTTPP_VERSION}
const string | VERSION_STR {PAHO_MQTTPP_VERSION_STR}
const string | COPYRIGHT {PAHO_MQTTPP_COPYRIGHT}
constexpr no_persistence | NO_PERSISTENCE {}

## Typedef Documentation

## async_client_ptr

using mqtt::async_client_ptr = async_client::ptr_t

Smart/shared pointer to an asynchronous MQTT client object

## string_ref

using mqtt::string_ref = buffer_ref<char>

A reference to a text buffer.

## binary_ref

using mqtt::binary_ref = buffer_ref<char>

A reference to a binary buffer. Note that we're using char for the underlying data type to allow efficient moves to and from std::string's. Using a separate type indicates that the data may be arbitrary binary.

## string_view

using mqtt::string_view = buffer_view<char>

A buffer view for character string data.

## binary_view

using mqtt::binary_view = buffer_view<char>

A buffer view for binary data

## callback_ptr

using mqtt::callback_ptr = callback::ptr_t

Smart/shared pointer to a callback object

## const_callback_ptr

using mqtt::const_callback_ptr = callback::const_ptr_t

Smart/shared pointer to a const callback object

## client_ptr

using mqtt::client_ptr = client::ptr_t

Smart/shared pointer to an MQTT synchronous client object

## connect_options_ptr

using mqtt::connect_options_ptr = connect_options::ptr_t

Smart/shared pointer to a connection options object.

## persistence_type

using mqtt::persistence_type = std::variant<no_persistence, string, iclient_persistence*>

A variant for the different type of persistence:

- no_persistence: Any object of this type indicates no persistence is desired.
- string: Indicates file persistence. The string specifies the directory for the persistence store.
- iclient_persistence*: User-defined persistence

## create_options_ptr

using mqtt::create_options_ptr = create_options::ptr_t

Smart/shared pointer to a connection options object.

## delivery_token_ptr

using mqtt::delivery_token_ptr = delivery_token::ptr_t

Smart/shared pointer to a delivery_token

## const_delivery_token_ptr

using mqtt::const_delivery_token_ptr = delivery_token::const_ptr_t

Smart/shared pointer to a const delivery_token

## bad_cast

using mqtt::bad_cast = std::bad_cast

Bring std::bad_cast into the mqtt namespace

## iaction_listener_ptr

using mqtt::iaction_listener_ptr = iaction_listener::ptr_t

Smart/shared pointer to an action listener

## const_iaction_listener_ptr

using mqtt::const_iaction_listener_ptr = iaction_listener::const_ptr_t

Smart/shared pointer to a const action listener

## iclient_persistence_ptr

using mqtt::iclient_persistence_ptr = iclient_persistence::ptr_t

Smart/shared pointer to a persistence client

## const_iclient_persistence_ptr

using mqtt::const_iclient_persistence_ptr = iclient_persistence::const_ptr_t

Smart/shared pointer to a persistence client

## message_ptr

using mqtt::message_ptr = message::ptr_t

Smart/shared pointer to a message

## const_message_ptr

using mqtt::const_message_ptr = message::const_ptr_t

Smart/shared pointer to a const message

## string_pair

using mqtt::string_pair = std::tuple<string, string>

A pair of strings as a tuple.

## ssl_options_ptr

using mqtt::ssl_options_ptr = ssl_options::ptr_t

Shared pointer to the ssl options class.

## ssl_options_unique_ptr

using mqtt::ssl_options_unique_ptr = ssl_options::unique_ptr_t

Unique pointer to the ssl options class.

## string_collection_ptr

using mqtt::string_collection_ptr = string_collection::ptr_t

Smart/shared pointer to a string collection

## const_string_collection_ptr

using mqtt::const_string_collection_ptr = string_collection::const_ptr_t

Smart/shared pointer to a const string_collection

## subscribe_options_ptr

using mqtt::subscribe_options_ptr = subscribe_options::ptr_t

Smart/shared pointer to a subscribe options object.

## token_ptr

using mqtt::token_ptr = token::ptr_t

Smart/shared pointer to a token object

## const_token_ptr

using mqtt::const_token_ptr = token::const_ptr_t

Smart/shared pointer to a const token object

## topic_ptr

using mqtt::topic_ptr = topic::ptr_t

A smart/shared pointer to a topic object.

## const_topic_ptr

using mqtt::const_topic_ptr = topic::const_ptr_t

A smart/shared pointer to a const topic object.

## byte

using mqtt::byte = uint8_t

A 'byte' is an 8-bit, unsigned int

## string

using mqtt::string = std::string

An mqtt string is just a std::string

## binary

using mqtt::binary = std::string

A binary blob of data is, umm, just a string too!

## string_ptr

using mqtt::string_ptr = std::shared_ptr<const string>

Smart/shared pointer to a const string

## binary_ptr

using mqtt::binary_ptr = std::shared_ptr<const binary>

Smart/shared pointer to a const binary blob

## will_options_ptr

using mqtt::will_options_ptr = will_options::ptr_t

Shared pointer to a will options object.

## const_will_options_ptr

using mqtt::const_will_options_ptr = will_options::const_ptr_t

Shared pointer to a const will options object.

## will_options_unique_ptr

using mqtt::will_options_unique_ptr = will_options::unique_ptr_t

Unique pointer to a will options object.

## Enumeration Type Documentation

## ReasonCode

enum mqtt::ReasonCode

The MQTT v5 Reason Codes.

Enumerator
SUCCESS |
NORMAL_DISCONNECTION |
GRANTED_QOS_0 |
GRANTED_QOS_1 |
GRANTED_QOS_2 |
DISCONNECT_WITH_WILL_MESSAGE |
NO_MATCHING_SUBSCRIBERS |
NO_SUBSCRIPTION_FOUND |
CONTINUE_AUTHENTICATION |
RE_AUTHENTICATE |
UNSPECIFIED_ERROR |
MALFORMED_PACKET |
PROTOCOL_ERROR |
IMPLEMENTATION_SPECIFIC_ERROR |
UNSUPPORTED_PROTOCOL_VERSION |
CLIENT_IDENTIFIER_NOT_VALID |
BAD_USER_NAME_OR_PASSWORD |
NOT_AUTHORIZED |
SERVER_UNAVAILABLE |
SERVER_BUSY |
BANNED |
SERVER_SHUTTING_DOWN |
BAD_AUTHENTICATION_METHOD |
KEEP_ALIVE_TIMEOUT |
SESSION_TAKEN_OVER |
TOPIC_FILTER_INVALID |
TOPIC_NAME_INVALID |
PACKET_IDENTIFIER_IN_USE |
PACKET_IDENTIFIER_NOT_FOUND |
RECEIVE_MAXIMUM_EXCEEDED |
TOPIC_ALIAS_INVALID |
PACKET_TOO_LARGE |
MESSAGE_RATE_TOO_HIGH |
QUOTA_EXCEEDED |
ADMINISTRATIVE_ACTION |
PAYLOAD_FORMAT_INVALID |
RETAIN_NOT_SUPPORTED |
QOS_NOT_SUPPORTED |
USE_ANOTHER_SERVER |
SERVER_MOVED |
SHARED_SUBSCRIPTIONS_NOT_SUPPORTED |
CONNECTION_RATE_EXCEEDED |
MAXIMUM_CONNECT_TIME |
SUBSCRIPTION_IDENTIFIERS_NOT_SUPPORTED |
WILDCARD_SUBSCRIPTIONS_NOT_SUPPORTED |
MQTTPP_V3_CODE |

## Function Documentation

## PAHO_MQTTPP_VERSION_STR()

const string mqtt::PAHO_MQTTPP_VERSION_STR | ( | "Paho MQTT C++ (mqttpp) v1.6.0" |  | ) |

The version string for the client library

## PAHO_MQTTPP_COPYRIGHT()

const string mqtt::PAHO_MQTTPP_COPYRIGHT | ( | "Copyright (c) 2013-2026 Frank Pagliughi" |  | ) |

Copyright notice for the client library

## operator<<() [1/5]

template<typename T>

std::ostream & mqtt::operator<< | ( | std::ostream & | os,
|  | const buffer_ref< T > & | buf )

Stream inserter for a buffer reference. This does a binary write of the data in the buffer.

Parameters

  os | The output stream.
  buf | The buffer reference to write.

Returns
  A reference to the output stream.

## operator<<() [2/5]

template<typename T>

std::ostream & mqtt::operator<< | ( | std::ostream & | os,
|  | const buffer_view< T > & | buf )

Stream inserter for a buffer view. This does a binary write of the data in the buffer.

Parameters

  os | The output stream.
  buf | The buffer reference to write.

Returns
  A reference to the output stream.

## operator<<() [3/5]

std::ostream & mqtt::operator<< | ( | std::ostream & | os,
|  | const exception & | exc )

inline

Stream inserter writes a fairly verbose message

Parameters

  os | The stream.
  exc | The exception to write.

Returns
  A reference to the stream.

## persistence_malloc()

void * mqtt::persistence_malloc | ( | size_t | n | ) |

inline

Allocate memory for use with user persistence.

Parameters

  n | The number of bytes for the buffer.

Returns
  A pointer to the allocated memory

## persistence_free()

void mqtt::persistence_free | ( | void * | p | ) |

inline

Frees memory allocated with persistence_malloc().

Parameters

  p | Pointer to a buffer obtained by persistence_malloc.

## make_message() [1/4]

message_ptr mqtt::make_message | ( | string_ref | topic,
|  | const void * | payload,
|  | size_t | len,
|  | int | qos,
|  | bool | retained,
|  | const properties & | props = properties() )

inline

Constructs a message with the specified array as a payload, and all other values set to defaults.

Parameters

  topic | The message topic
  payload | the bytes to use as the message payload
  len | the number of bytes in the payload
  qos | The quality of service for the message.
  retained | Whether the message should be retained by the broker.
  props | The MQTT v5 properties for the message.

## make_message() [2/4]

message_ptr mqtt::make_message | ( | string_ref | topic,
|  | const void * | payload,
|  | size_t | len )

inline

Constructs a message with the specified array as a payload, and all other values set to defaults.

Parameters

  topic | The message topic
  payload | the bytes to use as the message payload
  len | the number of bytes in the payload

## make_message() [3/4]

message_ptr mqtt::make_message | ( | string_ref | topic,
|  | binary_ref | payload,
|  | int | qos,
|  | bool | retained,
|  | const properties & | props = properties() )

inline

Constructs a message with the specified values.

Parameters

  topic | The message topic
  payload | A buffer to use as the message payload.
  qos | The quality of service for the message.
  retained | Whether the message should be retained by the broker.

## make_message() [4/4]

message_ptr mqtt::make_message | ( | string_ref | topic,
|  | binary_ref | payload )

inline

Constructs a message with the specified buffer as a payload, and all other values set to defaults.

Parameters

  topic | The message topic
  payload | A string to use as the message payload.

## operator<<() [4/5]

std::ostream & mqtt::operator<< | ( | std::ostream & | os,
|  | const property & | prop )

## get() [1/3]

template<typename T>

T mqtt::get | ( | const property & |  | ) |

inline

Extracts the value from the property as the specified type.

Returns
  The value from the property as the specified type.

## get< uint8_t >()

template<>

uint8_t mqtt::get< uint8_t > | ( | const property & | prop | ) |

inline

Extracts the value from the property as an unsigned 8-bit integer.

Returns
  The value from the property as an unsigned 8-bit integer.

## get< uint16_t >()

template<>

uint16_t mqtt::get< uint16_t > | ( | const property & | prop | ) |

inline

Extracts the value from the property as an unsigned 16-bit integer.

Returns
  The value from the property as an unsigned 16-bit integer.

## get< int16_t >()

template<>

int16_t mqtt::get< int16_t > | ( | const property & | prop | ) |

inline

Extracts the value from the property as a signed 16-bit integer.

Returns
  The value from the property as a signed 16-bit integer.

Deprecated
  All integer properties are unsigned. Use get<uint16_t>()

## get< uint32_t >()

template<>

uint32_t mqtt::get< uint32_t > | ( | const property & | prop | ) |

inline

Extracts the value from the property as an unsigned 32-bit integer.

Returns
  The value from the property as an unsigned 32-bit integer.

## get< int32_t >()

template<>

int32_t mqtt::get< int32_t > | ( | const property & | prop | ) |

inline

Extracts the value from the property as a signed 32-bit integer.

Returns
  The value from the property as a signed 32-bit integer.

Deprecated
  All integer properties are unsigned. Use get<uint32_t>()

## get< string >()

template<>

string mqtt::get< string > | ( | const property & | prop | ) |

inline

Extracts the value from the property as a string.

Returns
  The value from the property as a string.

## get< string_pair >()

template<>

string_pair mqtt::get< string_pair > | ( | const property & | prop | ) |

inline

Extracts the value from the property as a pair of strings.

Returns
  The value from the property as a pair of strings.

## get() [2/3]

template<typename T>

T mqtt::get | ( | const properties & | props,
|  | property::code | propid,
|  | size_t | idx )

inline

Retrieves a single value from a property list for when there may be multiple identical property ID's.

Template Parameters

  T | The type of the value to retrieve

Parameters

  props | The property list
  propid | The property ID code for the desired value.
  idx | Index of the desired property ID

Returns
  The requested value of type T

## get() [3/3]

template<typename T>

T mqtt::get | ( | const properties & | props,
|  | property::code | propid )

inline

Retrieves a single value from a property list.

Template Parameters

  T | The type of the value to retrieve

Parameters

  props | The property list
  propid | The property ID code for the desired value.

Returns
  The requested value of type T

## to_string() [1/2]

std::string mqtt::to_string | ( | ReasonCode | reasonCode | ) |

Get the string representation of the reason code.

Parameters

  reasonCode | An MQTT v5 reason code.

Returns
  The string representation of the reason code.

## operator<<() [5/5]

std::ostream & mqtt::operator<< | ( | std::ostream & | os,
|  | ReasonCode | reasonCode )

ostream inserter for reason codes

Parameters

  os | The output stream
  reasonCode | The reason code.

Returns
  Reference to the output stream

## to_seconds()

template<class Rep, class Period>

std::chrono::seconds mqtt::to_seconds | ( | const std::chrono::duration< Rep, Period > & | dur | ) |

Convert a chrono duration to seconds. This casts away precision to get integer seconds.

Parameters

  dur | A chrono duration type

Returns
  The duration as a chrono seconds value

## to_seconds_count()

template<class Rep, class Period>

long mqtt::to_seconds_count | ( | const std::chrono::duration< Rep, Period > & | dur | ) |

Convert a chrono duration to a number of seconds. This casts away precision to get integer seconds.

Parameters

  dur | A chrono duration type

Returns
  The duration as a number of seconds

## to_milliseconds()

template<class Rep, class Period>

std::chrono::milliseconds mqtt::to_milliseconds | ( | const std::chrono::duration< Rep, Period > & | dur | ) |

Convert a chrono duration to milliseconds. This casts away precision to get integer milliseconds.

Parameters

  dur | A chrono duration type

Returns
  The duration as a chrono milliseconds value

## to_milliseconds_count()

template<class Rep, class Period>

long mqtt::to_milliseconds_count | ( | const std::chrono::duration< Rep, Period > & | dur | ) |

Convert a chrono duration to a number of milliseconds. This casts away precision to get integer milliseconds.

Parameters

  dur | A chrono duration type

Returns
  The duration as a number of milliseconds

## to_bool()

bool mqtt::to_bool | ( | int | n | ) |

inline

Converts an into to a bool.

Parameters

  n | An integer.

Returns
  true if n not equal to zero, false otherwise

## to_int()

int mqtt::to_int | ( | bool | b | ) |

inline

Converts the boolean into a C integer true/false value.

Parameters

  b | A boolean

Returns
  Zero if b is false, non-zero if b is true.

## to_string() [2/2]

string mqtt::to_string | ( | const char * | cstr | ) |

inline

Gets a valid string for the char pointer, returning an empty string if the pointer is NULL.

Parameters

  cstr | A C-string pointer

Returns
  A string copy of the C array. If cstr is NULL, this returns an empty string.

## Variable Documentation

## PAHO_MQTTPP_VERSION

const uint32_t mqtt::PAHO_MQTTPP_VERSION = 0x01060000

The version number for the client library.

## VERSION

const uint32_t mqtt::VERSION {PAHO_MQTTPP_VERSION}

The version number for the client library.

## VERSION_STR

const string mqtt::VERSION_STR {PAHO_MQTTPP_VERSION_STR}

The version string for the client library

## COPYRIGHT

const string mqtt::COPYRIGHT {PAHO_MQTTPP_COPYRIGHT}

Copyright notice for the client library

## NO_PERSISTENCE

no_persistence mqtt::NO_PERSISTENCE {}

constexpr

A constant used to indicate that no persistence is desired