25#ifndef __mqtt_message_h
26#define __mqtt_message_h
66 static constexpr MQTTAsync_message DFLT_C_STRUCT MQTTAsync_message_initializer;
68 static const string EMPTY_STR;
70 static const binary EMPTY_BIN;
73 MQTTAsync_message msg_{DFLT_C_STRUCT};
88 void set_duplicate(
bool dup) { msg_.dup =
to_int(dup); }
92 using ptr_t = std::shared_ptr<message>;
112 string_ref topic,
const void* payload,
size_t len,
int qos,
bool retained,
176 string_ref topic,
const void* payload,
size_t len,
int qos,
bool retained,
179 return std::make_shared<message>(
180 std::move(
topic), payload, len, qos, retained, props
191 return std::make_shared<message>(
208 return std::make_shared<message>(
209 std::move(
topic), std::move(payload), qos, retained, props
219 return std::make_shared<message>(
229 return std::make_shared<message>(std::move(
topic), msg);
246#if defined(UNIT_TESTS)
247 const MQTTAsync_message& c_struct()
const {
return msg_; }
266 return topic_ ? topic_.
str() : EMPTY_STR;
280 return payload_ ? payload_.
str() : EMPTY_BIN;
286 return payload_ ? payload_.
str() : EMPTY_STR;
337 if (qos < 0 || qos > 2)
338 throw exception(MQTTASYNC_BAD_QOS,
"Bad QoS");
357 msg_.properties = props_.
c_struct();
364 props_ = std::move(props);
365 msg_.properties = props_.
c_struct();
391 string_ref topic,
const void* payload,
size_t len,
int qos,
bool retained,
454 msg_->set_topic(
topic);
491 msg_->set_retained(on);
499 msg_->set_properties(std::move(props));
507 msg_->set_properties(props);
Definition async_client.h:121
char value_type
Definition buffer_ref.h:67
const blob & str() const
Definition buffer_ref.h:253
Definition exception.h:48
auto qos(int qos) -> self &
Definition message.h:481
auto properties(mqtt::properties &&props) -> self &
Definition message.h:498
auto payload(binary_ref payload) -> self &
Definition message.h:464
auto payload(const void *payload, size_t n) -> self &
Definition message.h:473
message_ptr finalize()
Definition message.h:514
auto topic(string_ref topic) -> self &
Definition message.h:453
auto properties(const mqtt::properties &props) -> self &
Definition message.h:506
message_ptr_builder()
Definition message.h:448
auto retained(bool on) -> self &
Definition message.h:490
void set_properties(properties &&props)
Definition message.h:363
message(string_ref topic, binary_ref payload)
Definition message.h:143
const properties & get_properties() const
Definition message.h:350
const string & get_payload_str() const
Definition message.h:285
message(string_ref topic, const void *payload, size_t len)
Definition message.h:122
message(const message &other)
static ptr_t create(string_ref topic, const void *payload, size_t len)
Definition message.h:190
message()
Definition message.h:100
static constexpr bool DFLT_RETAINED
Definition message.h:62
string to_string() const
Definition message.h:371
void set_retained(bool retained)
Definition message.h:345
void set_topic(string_ref topic)
Definition message.h:253
static void validate_qos(int qos)
Definition message.h:336
message & operator=(message &&rhs)
void set_payload(binary_ref payload)
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:299
static constexpr int DFLT_QOS
Definition message.h:60
std::shared_ptr< const message > const_ptr_t
Definition message.h:94
const binary & get_payload() const
Definition message.h:279
const string_ref & get_topic_ref() const
Definition message.h:260
void set_properties(const properties &props)
Definition message.h:355
const string & get_topic() const
Definition message.h:265
message & operator=(const message &rhs)
bool is_retained() const
Definition message.h:306
~message()
Definition message.h:164
const binary_ref & get_payload_ref() const
Definition message.h:275
void set_payload(const void *payload, size_t n)
Definition message.h:320
static ptr_t create(string_ref topic, const void *payload, size_t len, int qos, bool retained, const properties &props=properties())
Definition message.h:175
static ptr_t create(string_ref topic, binary_ref payload, int qos, bool retained, const properties &props=properties())
Definition message.h:204
int get_qos() const
Definition message.h:292
std::shared_ptr< message > ptr_t
Definition message.h:92
static ptr_t create(string_ref topic, binary_ref payload)
Definition message.h:218
void set_qos(int qos)
Definition message.h:327
static ptr_t create(string_ref topic, const MQTTAsync_message &msg)
Definition message.h:228
Definition properties.h:293
const MQTTProperties & c_struct() const
Definition properties.h:389
Definition async_client.h:60
message::ptr_t message_ptr
Definition message.h:375
bool to_bool(int n)
Definition types.h:107
std::string binary
Definition types.h:45
buffer_ref< char > binary_ref
Definition buffer_ref.h:305
message::const_ptr_t const_message_ptr
Definition message.h:378
buffer_ref< char > string_ref
Definition buffer_ref.h:297
int to_int(bool b)
Definition types.h:113
message_ptr make_message(string_ref topic, const void *payload, size_t len, int qos, bool retained, const properties &props=properties())
Definition message.h:390