async_mqtt 5.0.0
Loading...
Searching...
No Matches
will.hpp
1// Copyright Takatoshi Kondo 2015
2//
3// Distributed under the Boost Software License, Version 1.0.
4// (See accompanying file LICENSE_1_0.txt or copy at
5// http://www.boost.org/LICENSE_1_0.txt)
6
7#if !defined(ASYNC_MQTT_PACKET_WILL_HPP)
8#define ASYNC_MQTT_PACKET_WILL_HPP
9
10#include <async_mqtt/buffer.hpp>
12#include <async_mqtt/packet/property_variant.hpp>
13#include <async_mqtt/util/json_like_out.hpp>
14
15namespace async_mqtt {
16
17class will {
18public:
30 will(buffer topic,
31 buffer message,
32 pub::opts pubopts = {},
33 properties props = {}
34 )
35 :topic_{force_move(topic)},
36 message_{force_move(message)},
37 pubopts_{pubopts},
38 props_(force_move(props))
39 {}
40
41 constexpr buffer const& topic() const {
42 return topic_;
43 }
44 constexpr buffer& topic() {
45 return topic_;
46 }
47 constexpr buffer const& message() const {
48 return message_;
49 }
50 constexpr buffer& message() {
51 return message_;
52 }
53 constexpr pub::retain get_retain() const {
54 return pubopts_.get_retain();
55 }
56 constexpr qos get_qos() const {
57 return pubopts_.get_qos();
58 }
59 constexpr properties const& props() const {
60 return props_;
61 }
62 constexpr properties& props() {
63 return props_;
64 }
65
66 friend
67 bool operator==(will const& lhs, will const& rhs) {
68 return
69 std::tie(lhs.topic_, lhs.message_, lhs.pubopts_, lhs.props_) ==
70 std::tie(rhs.topic_, rhs.message_, rhs.pubopts_, rhs.props_);
71 }
72
73 friend
74 bool operator<(will const& lhs, will const& rhs) {
75 return
76 std::tie(lhs.topic_, lhs.message_, lhs.pubopts_, lhs.props_) <
77 std::tie(rhs.topic_, rhs.message_, rhs.pubopts_, rhs.props_);
78 }
79
80private:
81 buffer topic_;
82 buffer message_;
83 pub::opts pubopts_;
84 properties props_;
85};
86
87inline std::ostream& operator<<(std::ostream& o, will const& val) {
88 o << "{" <<
89 "topic:" << val.topic() << "," <<
90 "message:" << json_like_out(val.message()) << "," <<
91 "qos:" << val.get_qos() << "," <<
92 "retain:" << val.get_retain();
93 if (!val.props().empty()) {
94 o << ",ps:" << val.props();
95 }
96 o << "}";
97 return o;
98}
99
100} // namespace async_mqtt
101
102#endif // ASYNC_MQTT_PACKET_WILL_HPP
qos
MQTT QoS.
Definition qos.hpp:23
constexpr retain get_retain() const
Get retain.
Definition pubopts.hpp:161
constexpr qos get_qos() const
Get qos.
Definition pubopts.hpp:177