Paho C++
1.0
The Paho MQTT C++ Client Library
|
An MQTT message holds everything required for an MQTT PUBLISH message. More...
#include <message.h>
Public Types | |
using | ptr_t = std::shared_ptr< message > |
Smart/shared pointer to this class. More... | |
using | const_ptr_t = std::shared_ptr< const message > |
Smart/shared pointer to this class. More... | |
Public Member Functions | |
message () | |
Constructs a message with an empty payload, and all other values set to defaults. | |
message (string_ref topic, const void *payload, size_t len, int qos, bool retained) | |
Constructs a message with the specified array as a payload, and all other values set to defaults. More... | |
message (string_ref topic, const void *payload, size_t len) | |
Constructs a message with the specified array as a payload, and all other values set to defaults. More... | |
message (string_ref topic, binary_ref payload, int qos, bool retained) | |
Constructs a message from a byte buffer. More... | |
message (string_ref topic, binary_ref payload) | |
Constructs a message from a byte buffer. More... | |
message (string_ref topic, const MQTTAsync_message &msg) | |
Constructs a message as a copy of the message structure. More... | |
message (const message &other) | |
Constructs a message as a copy of the other message. More... | |
message (message &&other) | |
Moves the other message to this one. More... | |
~message () | |
Destroys a message and frees all associated resources. | |
message & | operator= (const message &rhs) |
Copies another message to this one. More... | |
message & | operator= (message &&rhs) |
Moves another message to this one. More... | |
void | set_topic (string_ref topic) |
Sets the topic string. More... | |
const string_ref & | get_topic_ref () const |
Gets the topic reference for the message. More... | |
const string & | get_topic () const |
Gets the topic for the message. More... | |
void | clear_payload () |
Clears the payload, resetting it to be empty. | |
const binary_ref & | get_payload_ref () const |
Gets the payload reference. | |
const binary & | get_payload () const |
Gets the payload. | |
const string & | get_payload_str () const |
Gets the payload as a string. | |
int | get_qos () const |
Returns the quality of service for this message. More... | |
bool | is_duplicate () const |
Returns whether or not this message might be a duplicate of one which has already been received. More... | |
bool | is_retained () const |
Returns whether or not this message should be/was retained by the server. More... | |
void | set_payload (binary_ref payload) |
Sets the payload of this message to be the specified buffer. More... | |
void | set_payload (const void *payload, size_t n) |
Sets the payload of this message to be the specified byte array. More... | |
void | set_qos (int qos) |
Sets the quality of service for this message. More... | |
void | set_retained (bool retained) |
Whether or not the publish message should be retained by the broker. More... | |
string | to_string () const |
Returns a string representation of this messages payload. More... | |
Static Public Member Functions | |
static ptr_t | create (string_ref topic, const void *payload, size_t len, int qos, bool retained) |
Constructs a message with the specified array as a payload, and all other values set to defaults. More... | |
static ptr_t | create (string_ref topic, const void *payload, size_t len) |
Constructs a message with the specified array as a payload, and all other values set to defaults. More... | |
static ptr_t | create (string_ref topic, binary_ref payload, int qos, bool retained) |
Constructs a message from a byte buffer. More... | |
static ptr_t | create (string_ref topic, binary_ref payload) |
Constructs a message from a byte buffer. More... | |
static ptr_t | create (string_ref topic, const MQTTAsync_message &msg) |
Constructs a message as a copy of the C message struct. More... | |
static void | validate_qos (int qos) |
Determines if the QOS value is a valid one. More... | |
Static Public Attributes | |
static constexpr int | DFLT_QOS = 0 |
The default QoS for a message. | |
static constexpr bool | DFLT_RETAINED = false |
The default retained flag. | |
Friends | |
class | async_client |
The client has special access. More... | |
class | message_test |
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 touchec the payloads or topics.
This also means that message objects are farily 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::const_ptr_t = std::shared_ptr<const message> |
Smart/shared pointer to this class.
using mqtt::message::ptr_t = std::shared_ptr<message> |
Smart/shared pointer to this class.
mqtt::message::message | ( | string_ref | topic, |
const void * | payload, | ||
size_t | len, | ||
int | qos, | ||
bool | retained | ||
) |
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. |
|
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 | ||
) |
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. |
|
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 & | msg | ||
) |
Constructs a message as a copy of the message structure.
topic | The message topic |
msg | 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. |
|
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 |
qos | The quality of service for the message. |
retained | Whether the message should be retained by the broker. |
|
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. |
|
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. |
|
inline |
Returns the quality of service for this message.
|
inline |
Gets the topic for the message.
|
inline |
Gets the topic reference for the 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.
Copies another message to this one.
rhs | The other message. |
Moves another message to this one.
rhs | The other message. |
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 |
|
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 |
Sets the topic string.
topic | The topic on which the message is published. |
|
inline |
Returns a string representation of this messages payload.
|
inlinestatic |
Determines if the QOS value is a valid one.
qos | The QOS value. |
std::invalid_argument | If the qos value is invalid. |
|
friend |
The client has special access.