![]() |
PahoMqttCpp
MQTT C++ Client for POSIX and Windows
|
#include <message.h>
Public Types | |
using | ptr_t = std::shared_ptr<message> |
using | const_ptr_t = std::shared_ptr<const message> |
Public Member Functions | |
message () | |
message (string_ref topic, const void *payload, size_t len, int qos, bool retained, const properties &props=properties()) | |
message (string_ref topic, const void *payload, size_t len) | |
message (string_ref topic, binary_ref payload, int qos, bool retained, const properties &props=properties()) | |
message (string_ref topic, binary_ref payload) | |
message (string_ref topic, const MQTTAsync_message &cmsg) | |
message (const message &other) | |
message (message &&other) | |
~message () | |
message & | operator= (const message &rhs) |
message & | operator= (message &&rhs) |
void | set_topic (string_ref topic) |
const string_ref & | get_topic_ref () const |
const string & | get_topic () const |
void | clear_payload () |
const binary_ref & | get_payload_ref () const |
const binary & | get_payload () const |
const string & | get_payload_str () const |
int | get_qos () const |
bool | is_duplicate () const |
bool | is_retained () const |
void | set_payload (binary_ref payload) |
void | set_payload (const void *payload, size_t n) |
void | set_qos (int qos) |
void | set_retained (bool retained) |
const properties & | get_properties () const |
void | set_properties (const properties &props) |
void | set_properties (properties &&props) |
string | to_string () const |
Static Public Member Functions | |
static ptr_t | create (string_ref topic, const void *payload, size_t len, int qos, bool retained, const properties &props=properties()) |
static ptr_t | create (string_ref topic, const void *payload, size_t len) |
static ptr_t | create (string_ref topic, binary_ref payload, int qos, bool retained, const properties &props=properties()) |
static ptr_t | create (string_ref topic, binary_ref payload) |
static ptr_t | create (string_ref topic, const MQTTAsync_message &msg) |
static void | validate_qos (int qos) |
Static Public Attributes | |
static constexpr int | DFLT_QOS = 0 |
static constexpr bool | DFLT_RETAINED = false |
Friends | |
class | async_client |
An MQTT message holds everything required for an MQTT PUBLISH message. This holds the binary message payload, topic string, and all the additional meta-data for an MQTT message.
The topic and payload buffers are kept as references to const data, so they can be reassigned as needed, but the buffers can not be updated in-place. Normally they would be created externally then copied or moved into the message. The library to transport the messages never touches the payloads or topics.
This also means that message objects are fairly cheap to copy, since they don't copy the payloads. They simply copy the reference to the buffers. It is safe to pass these buffer references across threads since all references promise not to update the contents of the buffer.
using mqtt::message::ptr_t = std::shared_ptr<message> |
Smart/shared pointer to this class.
using mqtt::message::const_ptr_t = std::shared_ptr<const message> |
Smart/shared pointer to this class.
|
inline |
Constructs a message with an empty payload, and all other values set to defaults.
mqtt::message::message | ( | string_ref | topic, |
const void * | payload, | ||
size_t | len, | ||
int | qos, | ||
bool | retained, | ||
const properties & | props = properties() ) |
Constructs a message with the specified array as a payload, and all other values set to defaults.
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. |
|
inline |
Constructs a message with the specified array as a payload, and all other values set to defaults.
topic | The message topic |
payload | the bytes to use as the message payload |
len | the number of bytes in the payload |
mqtt::message::message | ( | string_ref | topic, |
binary_ref | payload, | ||
int | qos, | ||
bool | retained, | ||
const properties & | props = properties() ) |
Constructs a message from a byte buffer. Note that the payload accepts copy or move semantics.
topic | The message topic |
payload | A byte 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. |
props | The MQTT v5 properties for the message. |
|
inline |
Constructs a message from a byte buffer. Note that the payload accepts copy or move semantics.
topic | The message topic |
payload | A byte buffer to use as the message payload. |
mqtt::message::message | ( | string_ref | topic, |
const MQTTAsync_message & | cmsg ) |
Constructs a message as a copy of the message structure.
topic | The message topic |
cmsg | A "C" MQTTAsync_message structure. |
mqtt::message::message | ( | const message & | other | ) |
Constructs a message as a copy of the other message.
other | The message to copy into this one. |
mqtt::message::message | ( | message && | other | ) |
Moves the other message to this one.
other | The message to move into this one. |
|
inline |
Destroys a message and frees all associated resources.
|
inlinestatic |
Constructs a message with the specified values.
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. |
|
inlinestatic |
Constructs a message with the specified array as a payload, and all other values set to defaults.
topic | The message topic |
payload | the bytes to use as the message payload |
len | the number of bytes in the payload |
|
inlinestatic |
Constructs a message from a byte buffer. Note that the payload accepts copy or move semantics.
topic | The message topic |
payload | A byte 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. |
props | The MQTT v5 properties for the message. |
|
inlinestatic |
Constructs a message from a byte buffer. Note that the payload accepts copy or move semantics.
topic | The message topic |
payload | A byte buffer to use as the message payload. |
|
inlinestatic |
Constructs a message as a copy of the C message struct.
topic | The message topic |
msg | A "C" MQTTAsync_message structure. |
Copies another message to this one.
rhs | The other message. |
Moves another message to this one.
rhs | The other message. |
|
inline |
Expose the underlying C struct for the unit tests. Sets the topic string.
topic | The topic on which the message is published. |
|
inline |
Gets the topic reference for the message.
|
inline |
Gets the topic for the message.
void mqtt::message::clear_payload | ( | ) |
Clears the payload, resetting it to be empty.
|
inline |
Gets the payload reference.
|
inline |
Gets the payload
|
inline |
Gets the payload as a string
|
inline |
Returns the quality of service for this message.
|
inline |
Returns whether or not this message might be a duplicate of one which has already been received.
|
inline |
Returns whether or not this message should be/was retained by the server.
void mqtt::message::set_payload | ( | binary_ref | payload | ) |
Sets the payload of this message to be the specified buffer. Note that this accepts copy or move operations: set_payload(buf); set_payload(std::move(buf));
payload | A buffer to use as the message payload. |
|
inline |
Sets the payload of this message to be the specified byte array.
payload | the bytes to use as the message payload |
n | the number of bytes in the payload |
|
inline |
Sets the quality of service for this message.
qos | The integer Quality of Service for the message |
|
inlinestatic |
Determines if the QOS value is a valid one.
qos | The QOS value. |
std::invalid_argument | If the qos value is invalid. |
|
inline |
Whether or not the publish message should be retained by the broker.
retained | true if the message should be retained by the broker, false if not. |
|
inline |
Gets the properties in the message.
|
inline |
Sets the properties in the message.
props | The properties to place into the message. |
|
inline |
Moves the properties into the message.
props | The properties to move into the message. |
|
inline |
Returns a string representation of this messages payload.
|
friend |
The client has special access.
|
staticconstexpr |
The default QoS for a message
|
staticconstexpr |
The default retained flag