25#ifndef __mqtt_message_h
26#define __mqtt_message_h
66 static constexpr MQTTAsync_message DFLT_C_STRUCT MQTTAsync_message_initializer;
69 MQTTAsync_message msg_{DFLT_C_STRUCT};
84 void set_duplicate(
bool dup) { msg_.dup =
to_int(dup); }
88 using ptr_t = std::shared_ptr<message>;
108 string_ref topic,
const void* payload,
size_t len,
int qos,
bool retained,
172 string_ref topic,
const void* payload,
size_t len,
int qos,
bool retained,
175 return std::make_shared<message>(
176 std::move(
topic), payload, len, qos, retained, props
187 return std::make_shared<message>(
204 return std::make_shared<message>(
205 std::move(
topic), std::move(payload), qos, retained, props
215 return std::make_shared<message>(
225 return std::make_shared<message>(std::move(
topic), msg);
242#if defined(UNIT_TESTS)
243 const MQTTAsync_message& c_struct()
const {
return msg_; }
262 static const string EMPTY_STR;
263 return topic_ ? topic_.
str() : EMPTY_STR;
277 static const binary EMPTY_BIN;
278 return payload_ ? payload_.
str() : EMPTY_BIN;
284 static const string EMPTY_STR;
285 return payload_ ? payload_.
str() : EMPTY_STR;
336 if (qos < 0 || qos > 2)
337 throw exception(MQTTASYNC_BAD_QOS,
"Bad QoS");
356 msg_.properties = props_.
c_struct();
363 props_ = std::move(props);
364 msg_.properties = props_.
c_struct();
390 string_ref topic,
const void* payload,
size_t len,
int qos,
bool retained,
453 msg_->set_topic(
topic);
490 msg_->set_retained(on);
498 msg_->set_properties(std::move(props));
506 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:480
auto properties(mqtt::properties &&props) -> self &
Definition message.h:497
auto payload(binary_ref payload) -> self &
Definition message.h:463
auto payload(const void *payload, size_t n) -> self &
Definition message.h:472
message_ptr finalize()
Definition message.h:513
auto topic(string_ref topic) -> self &
Definition message.h:452
auto properties(const mqtt::properties &props) -> self &
Definition message.h:505
message_ptr_builder()
Definition message.h:447
auto retained(bool on) -> self &
Definition message.h:489
void set_properties(properties &&props)
Definition message.h:362
message(string_ref topic, binary_ref payload)
Definition message.h:139
const properties & get_properties() const
Definition message.h:349
const string & get_payload_str() const
Definition message.h:283
message(string_ref topic, const void *payload, size_t len)
Definition message.h:118
message(const message &other)
static ptr_t create(string_ref topic, const void *payload, size_t len)
Definition message.h:186
message()
Definition message.h:96
static constexpr bool DFLT_RETAINED
Definition message.h:62
string to_string() const
Definition message.h:370
void set_retained(bool retained)
Definition message.h:344
void set_topic(string_ref topic)
Definition message.h:249
static void validate_qos(int qos)
Definition message.h:335
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:298
static constexpr int DFLT_QOS
Definition message.h:60
std::shared_ptr< const message > const_ptr_t
Definition message.h:90
const binary & get_payload() const
Definition message.h:276
const string_ref & get_topic_ref() const
Definition message.h:256
void set_properties(const properties &props)
Definition message.h:354
const string & get_topic() const
Definition message.h:261
message & operator=(const message &rhs)
bool is_retained() const
Definition message.h:305
~message()
Definition message.h:160
const binary_ref & get_payload_ref() const
Definition message.h:272
void set_payload(const void *payload, size_t n)
Definition message.h:319
static ptr_t create(string_ref topic, const void *payload, size_t len, int qos, bool retained, const properties &props=properties())
Definition message.h:171
static ptr_t create(string_ref topic, binary_ref payload, int qos, bool retained, const properties &props=properties())
Definition message.h:200
int get_qos() const
Definition message.h:291
std::shared_ptr< message > ptr_t
Definition message.h:88
static ptr_t create(string_ref topic, binary_ref payload)
Definition message.h:214
void set_qos(int qos)
Definition message.h:326
static ptr_t create(string_ref topic, const MQTTAsync_message &msg)
Definition message.h:224
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:374
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:377
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:389