25#ifndef __mqtt_message_h
26#define __mqtt_message_h
68 MQTTAsync_message msg_;
83 void set_duplicate(
bool dup) { msg_.dup =
to_int(dup); }
87 using ptr_t = std::shared_ptr<message>;
107 int qos,
bool retained,
170 return std::make_shared<message>(std::move(
topic), payload, len,
171 qos, retained, props);
181 return std::make_shared<message>(std::move(
topic), payload, len,
195 return std::make_shared<message>(std::move(
topic), std::move(payload),
196 qos, retained, props);
205 return std::make_shared<message>(std::move(
topic), std::move(payload),
214 return std::make_shared<message>(std::move(
topic), msg);
231 #if defined(UNIT_TESTS)
232 const MQTTAsync_message& c_struct()
const {
return msg_; }
251 static const string EMPTY_STR;
252 return topic_ ? topic_.
str() : EMPTY_STR;
266 static const binary EMPTY_BIN;
267 return payload_ ? payload_.
str() : EMPTY_BIN;
273 static const string EMPTY_STR;
274 return payload_ ? payload_.
str() : EMPTY_STR;
325 if (qos < 0 || qos > 2)
326 throw exception(MQTTASYNC_BAD_QOS,
"Bad QoS");
354 props_ = std::move(props);
355 msg_.properties = props_.
c_struct();
391 int qos,
bool retained) {
413 int qos,
bool retained) {
439 msg_->set_topic(
topic);
476 msg_->set_retained(on);
484 msg_->set_properties(std::move(props));
492 msg_->set_properties(props);
Definition: async_client.h:108
char value_type
Definition: buffer_ref.h:66
const blob & str() const
Definition: buffer_ref.h:246
Definition: exception.h:47
Definition: message.h:423
auto qos(int qos) -> self &
Definition: message.h:466
auto properties(mqtt::properties &&props) -> self &
Definition: message.h:483
auto payload(binary_ref payload) -> self &
Definition: message.h:449
auto payload(const void *payload, size_t n) -> self &
Definition: message.h:458
message_ptr finalize()
Definition: message.h:499
auto topic(string_ref topic) -> self &
Definition: message.h:438
auto properties(const mqtt::properties &props) -> self &
Definition: message.h:491
message_ptr_builder()
Definition: message.h:433
auto retained(bool on) -> self &
Definition: message.h:475
void set_properties(properties &&props)
Definition: message.h:353
message(string_ref topic, binary_ref payload)
Definition: message.h:135
const properties & get_properties() const
Definition: message.h:338
const string & get_payload_str() const
Definition: message.h:272
message(string_ref topic, const void *payload, size_t len)
Definition: message.h:116
message(const message &other)
static ptr_t create(string_ref topic, const void *payload, size_t len)
Definition: message.h:180
static PAHO_MQTTPP_EXPORT const int DFLT_QOS
Definition: message.h:59
string to_string() const
Definition: message.h:361
void set_retained(bool retained)
Definition: message.h:333
void set_topic(string_ref topic)
Definition: message.h:238
static void validate_qos(int qos)
Definition: message.h:324
message & operator=(message &&rhs)
void set_payload(binary_ref payload)
static PAHO_MQTTPP_EXPORT const bool DFLT_RETAINED
Definition: message.h:61
message(string_ref topic, const void *payload, size_t len, int qos, bool retained, const properties &props=properties())
message(string_ref topic, binary_ref payload, int qos, bool retained, const properties &props=properties())
message(string_ref topic, const MQTTAsync_message &cmsg)
bool is_duplicate() const
Definition: message.h:287
std::shared_ptr< const message > const_ptr_t
Definition: message.h:89
const binary & get_payload() const
Definition: message.h:265
const string_ref & get_topic_ref() const
Definition: message.h:245
void set_properties(const properties &props)
Definition: message.h:345
const string & get_topic() const
Definition: message.h:250
message & operator=(const message &rhs)
bool is_retained() const
Definition: message.h:294
~message()
Definition: message.h:156
const binary_ref & get_payload_ref() const
Definition: message.h:261
void set_payload(const void *payload, size_t n)
Definition: message.h:308
static ptr_t create(string_ref topic, const void *payload, size_t len, int qos, bool retained, const properties &props=properties())
Definition: message.h:168
static ptr_t create(string_ref topic, binary_ref payload, int qos, bool retained, const properties &props=properties())
Definition: message.h:193
int get_qos() const
Definition: message.h:280
std::shared_ptr< message > ptr_t
Definition: message.h:87
static ptr_t create(string_ref topic, binary_ref payload)
Definition: message.h:204
void set_qos(int qos)
Definition: message.h:315
static ptr_t create(string_ref topic, const MQTTAsync_message &msg)
Definition: message.h:213
Definition: properties.h:256
const MQTTProperties & c_struct() const
Definition: properties.h:308
#define PAHO_MQTTPP_EXPORT
Definition: export.h:40
Definition: async_client.h:49
message::ptr_t message_ptr
Definition: message.h:365
bool to_bool(int n)
Definition: types.h:161
message_ptr make_message(string_ref topic, const void *payload, size_t len)
Definition: message.h:377
std::string binary
Definition: types.h:42
buffer_ref< char > binary_ref
Definition: buffer_ref.h:298
message::const_ptr_t const_message_ptr
Definition: message.h:368
buffer_ref< char > string_ref
Definition: buffer_ref.h:290
int to_int(bool b)
Definition: types.h:167