Paho C++  1.0
The Paho MQTT C++ Client Library
 All Classes Files Functions Variables Typedefs Friends
mqtt::message Class Reference

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.
 
messageoperator= (const message &rhs)
 Copies another message to this one. More...
 
messageoperator= (message &&rhs)
 Moves another message to this one. More...
 
void set_topic (string_ref topic)
 Sets the topic string. More...
 
const string_refget_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_refget_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
 

Detailed Description

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.

Member Typedef Documentation

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.

Constructor & Destructor Documentation

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.

Parameters
topicThe message topic
payloadthe bytes to use as the message payload
lenthe number of bytes in the payload
qosThe quality of service for the message.
retainedWhether the message should be retained by the broker.
mqtt::message::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
topicThe message topic
payloadthe bytes to use as the message payload
lenthe 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.

Parameters
topicThe message topic
payloadA byte buffer to use as the message payload.
qosThe quality of service for the message.
retainedWhether the message should be retained by the broker.
mqtt::message::message ( string_ref  topic,
binary_ref  payload 
)
inline

Constructs a message from a byte buffer.

Note that the payload accepts copy or move semantics.

Parameters
topicThe message topic
payloadA 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.

Parameters
topicThe message topic
msgA "C" MQTTAsync_message structure.
mqtt::message::message ( const message other)

Constructs a message as a copy of the other message.

Parameters
otherThe message to copy into this one.
mqtt::message::message ( message &&  other)

Moves the other message to this one.

Parameters
otherThe message to move into this one.

Member Function Documentation

static ptr_t mqtt::message::create ( string_ref  topic,
const void *  payload,
size_t  len,
int  qos,
bool  retained 
)
inlinestatic

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

Parameters
topicThe message topic
payloadthe bytes to use as the message payload
lenthe number of bytes in the payload
qosThe quality of service for the message.
retainedWhether the message should be retained by the broker.
static ptr_t mqtt::message::create ( string_ref  topic,
const void *  payload,
size_t  len 
)
inlinestatic

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

Parameters
topicThe message topic
payloadthe bytes to use as the message payload
lenthe number of bytes in the payload
static ptr_t mqtt::message::create ( string_ref  topic,
binary_ref  payload,
int  qos,
bool  retained 
)
inlinestatic

Constructs a message from a byte buffer.

Note that the payload accepts copy or move semantics.

Parameters
topicThe message topic
payloadA byte buffer to use as the message payload.
qosThe quality of service for the message.
retainedWhether the message should be retained by the broker.
static ptr_t mqtt::message::create ( string_ref  topic,
binary_ref  payload 
)
inlinestatic

Constructs a message from a byte buffer.

Note that the payload accepts copy or move semantics.

Parameters
topicThe message topic
payloadA byte buffer to use as the message payload.
static ptr_t mqtt::message::create ( string_ref  topic,
const MQTTAsync_message &  msg 
)
inlinestatic

Constructs a message as a copy of the C message struct.

Parameters
topicThe message topic
msgA "C" MQTTAsync_message structure.
int mqtt::message::get_qos ( ) const
inline

Returns the quality of service for this message.

Returns
The quality of service for this message.
const string& mqtt::message::get_topic ( ) const
inline

Gets the topic for the message.

Returns
The topic string for the message.
const string_ref& mqtt::message::get_topic_ref ( ) const
inline

Gets the topic reference for the message.

Returns
The topic reference for the message.
bool mqtt::message::is_duplicate ( ) const
inline

Returns whether or not this message might be a duplicate of one which has already been received.

Returns
true this message might be a duplicate of one which has already been received, false otherwise
bool mqtt::message::is_retained ( ) const
inline

Returns whether or not this message should be/was retained by the server.

Returns
true if this message should be/was retained by the server, false otherwise.
message& mqtt::message::operator= ( const message rhs)

Copies another message to this one.

Parameters
rhsThe other message.
Returns
A reference to this message.
message& mqtt::message::operator= ( message &&  rhs)

Moves another message to this one.

Parameters
rhsThe other message.
Returns
A reference to this 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));

Parameters
payloadA buffer to use as the message payload.
void mqtt::message::set_payload ( const void *  payload,
size_t  n 
)
inline

Sets the payload of this message to be the specified byte array.

Parameters
payloadthe bytes to use as the message payload
nthe number of bytes in the payload
void mqtt::message::set_qos ( int  qos)
inline

Sets the quality of service for this message.

Parameters
qosThe integer Quality of Service for the message
void mqtt::message::set_retained ( bool  retained)
inline

Whether or not the publish message should be retained by the broker.

Parameters
retainedtrue if the message should be retained by the broker, false if not.
void mqtt::message::set_topic ( string_ref  topic)
inline

Sets the topic string.

Parameters
topicThe topic on which the message is published.
string mqtt::message::to_string ( ) const
inline

Returns a string representation of this messages payload.

Returns
string
static void mqtt::message::validate_qos ( int  qos)
inlinestatic

Determines if the QOS value is a valid one.

Parameters
qosThe QOS value.
Exceptions
std::invalid_argumentIf the qos value is invalid.

Friends And Related Function Documentation

friend class async_client
friend

The client has special access.


The documentation for this class was generated from the following file: