async_mqtt 9.0.1
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/util/buffer.hpp>
11#include <async_mqtt/packet/pubopts.hpp>
12#include <async_mqtt/packet/property_variant.hpp>
13#include <async_mqtt/util/json_like_out.hpp>
14
15namespace async_mqtt {
16
30class will {
31public:
43 template <
44 typename StringViewLikeTopic,
45 typename StringViewLikeMessage,
46 std::enable_if_t<
47 std::is_convertible_v<std::decay_t<StringViewLikeTopic>, std::string_view> &&
48 std::is_convertible_v<std::decay_t<StringViewLikeMessage>, std::string_view>,
49 std::nullptr_t
50 > = nullptr
51 >
52 explicit will(
53 StringViewLikeTopic&& topic,
54 StringViewLikeMessage&& message,
55 pub::opts pubopts = {},
56 properties props = {}
57 ) :
58 topic_{std::string{std::forward<StringViewLikeTopic>(topic)}},
59 message_{std::string{std::forward<StringViewLikeMessage>(message)}},
60 pubopts_{pubopts},
61 props_(force_move(props))
62 {}
63
68 std::string topic() const {
69 return std::string{topic_};
70 }
71
76 buffer const& topic_as_buffer() const {
77 return topic_;
78 }
79
85 return topic_;
86 }
87
92 std::string message() const {
93 return std::string{message_};
94 }
95
100 buffer const& message_as_buffer() const {
101 return message_;
102 }
103
109 return message_;
110 }
111
116 constexpr pub::retain get_retain() const {
117 return pubopts_.get_retain();
118 }
119
124 constexpr qos get_qos() const {
125 return pubopts_.get_qos();
126 }
127
132 constexpr properties const& props() const {
133 return props_;
134 }
135
140 constexpr properties& props() {
141 return props_;
142 }
143
150 friend
151 bool operator==(will const& lhs, will const& rhs) {
152 return
153 std::tie(lhs.topic_, lhs.message_, lhs.pubopts_, lhs.props_) ==
154 std::tie(rhs.topic_, rhs.message_, rhs.pubopts_, rhs.props_);
155 }
156
163 friend
164 bool operator<(will const& lhs, will const& rhs) {
165 return
166 std::tie(lhs.topic_, lhs.message_, lhs.pubopts_, lhs.props_) <
167 std::tie(rhs.topic_, rhs.message_, rhs.pubopts_, rhs.props_);
168 }
169
170private:
171 buffer topic_;
172 buffer message_;
173 pub::opts pubopts_;
174 properties props_;
175};
176
177/*
178 * @ingroup connect_v3_1_1
179 * @ingroup connect_v5
180 * @brief output to the stream
181 * @param os output stream
182 * @param v target
183 * @return output stream
184 *
185 * #### Requirements
186 * - Header: async_mqtt/packet/will.hpp
187 * - Convenience header: async_mqtt/all.hpp
188 *
189 */
190inline std::ostream& operator<<(std::ostream& o, will const& v) {
191 o << "{" <<
192 "topic:" << v.topic_as_buffer() << "," <<
193 "message:" << json_like_out(v.message_as_buffer()) << "," <<
194 "qos:" << v.get_qos() << "," <<
195 "retain:" << v.get_retain();
196 if (!v.props().empty()) {
197 o << ",ps:" << v.props();
198 }
199 o << "}";
200 return o;
201}
202
203} // namespace async_mqtt
204
205#endif // ASYNC_MQTT_PACKET_WILL_HPP
buffer that has string_view interface and shared ownership This class is only for advanced usecase su...
Definition buffer.hpp:46
MQTT will message.
Definition will.hpp:30
buffer & topic_as_buffer()
Get topic as a buffer.
Definition will.hpp:84
buffer const & topic_as_buffer() const
Get topic as a buffer.
Definition will.hpp:76
std::string topic() const
Get topic.
Definition will.hpp:68
will(StringViewLikeTopic &&topic, StringViewLikeMessage &&message, pub::opts pubopts={}, properties props={})
constructor
Definition will.hpp:52
friend bool operator<(will const &lhs, will const &rhs)
less than operator
Definition will.hpp:164
constexpr qos get_qos() const
Get QoS.
Definition will.hpp:124
buffer const & message_as_buffer() const
Get message as a buffer.
Definition will.hpp:100
constexpr properties & props()
Get properties.
Definition will.hpp:140
std::string message() const
Get message.
Definition will.hpp:92
friend bool operator==(will const &lhs, will const &rhs)
equal operator
Definition will.hpp:151
constexpr properties const & props() const
Get properties.
Definition will.hpp:132
constexpr pub::retain get_retain() const
Get retain.
Definition will.hpp:116
buffer & message_as_buffer()
Get message as a buffer.
Definition will.hpp:108
std::ostream & operator<<(std::ostream &o, mqtt_error v)
output to the stream
std::vector< property_variant > properties
property variant collection type
Definition property_variant.hpp:224
retain
MQTT RETAIN.
Definition pubopts.hpp:100
qos
MQTT QoS.
Definition qos.hpp:35
MQTT PublishOptions.
Definition pubopts.hpp:136
constexpr retain get_retain() const
Get retain.
Definition pubopts.hpp:232
constexpr qos get_qos() const
Get qos.
Definition pubopts.hpp:248