async_mqtt 9.0.1
Loading...
Searching...
No Matches
subopts.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_SUBOPTS_HPP)
8#define ASYNC_MQTT_PACKET_SUBOPTS_HPP
9
10#include <cstdint>
11#include <ostream>
12
13#include <async_mqtt/packet/qos.hpp>
14
20namespace async_mqtt {
21
22namespace sub {
23
35enum class retain_handling : std::uint8_t
36{
37 send = 0b00000000,
38 send_only_new_subscription = 0b00010000,
39 not_send = 0b00100000,
40};
41
53enum class rap : std::uint8_t
54{
55 dont = 0b00000000,
56 retain = 0b00001000,
57};
58
70enum class nl : std::uint8_t
71{
72 no = 0b00000000,
73 yes = 0b00000100,
74};
75
90struct opts final {
91 constexpr opts() = delete;
92 ~opts() = default;
93 constexpr opts(opts &&) = default;
94 constexpr opts(opts const&) = default;
95 constexpr opts& operator=(opts &&) = default;
96 constexpr opts& operator=(opts const&) = default;
97
102 explicit constexpr opts(std::uint8_t value) : data_(value) { }
103
108 constexpr opts(retain_handling value) : data_(static_cast<std::uint8_t>(value)) { }
109
114 constexpr opts(rap value) : data_(static_cast<std::uint8_t>(value)) { }
115
120 constexpr opts(nl value) : data_(static_cast<std::uint8_t>(value)) { }
121
126 constexpr opts(qos value) : data_(static_cast<std::uint8_t>(value)) { }
127
133 constexpr opts operator|(opts rhs) const { return opts(data_ | rhs.data_); }
134
140 constexpr opts operator|(retain_handling rhs) const { return *this | opts(rhs); }
141
147 constexpr opts operator|(rap rhs) const { return *this | opts(rhs); }
148
154 constexpr opts operator|(nl rhs) const { return *this | opts(rhs); }
155
161 constexpr opts operator|(qos rhs) const { return *this | opts(rhs); }
162
168 constexpr opts& operator|=(opts rhs) { return (*this = (*this | rhs)); }
169
175 constexpr opts& operator|=(retain_handling rhs) { return (*this = (*this | rhs)); }
176
182 constexpr opts& operator|=(rap rhs) { return (*this = (*this | rhs)); }
183
189 constexpr opts& operator|=(nl rhs) { return (*this = (*this | rhs)); }
190
196 constexpr opts& operator|=(qos rhs) { return (*this = (*this | rhs)); }
197
204 { return static_cast<enum retain_handling>(data_ & 0b00110000); }
205
211 constexpr rap get_rap() const
212 { return static_cast<enum rap>(data_ & 0b00001000); }
213
219 constexpr nl get_nl() const
220 { return static_cast<enum nl>(data_ & 0b00000100); }
221
227 constexpr qos get_qos() const
228 { return static_cast<enum qos>(data_ & 0b00000011); }
229
235 explicit constexpr operator std::uint8_t() const { return data_; }
236
242 constexpr bool operator==(opts rhs) const { return data_ == rhs.data_; }
243
249 constexpr bool operator<(opts rhs) const { return data_ < rhs.data_; }
250
251private:
252 std::uint8_t data_;
253};
254
267constexpr opts operator|(retain_handling lhs, rap rhs) { return opts(lhs) | rhs; }
268
281constexpr opts operator|(retain_handling lhs, nl rhs) { return opts(lhs) | rhs; }
282
295constexpr opts operator|(retain_handling lhs, qos rhs) { return opts(lhs) | rhs; }
296
309constexpr opts operator|(rap lhs, retain_handling rhs) { return opts(lhs) | rhs; }
310
323constexpr opts operator|(rap lhs, nl rhs) { return opts(lhs) | rhs; }
324
337constexpr opts operator|(rap lhs, qos rhs) { return opts(lhs) | rhs; }
338
351constexpr opts operator|(nl lhs, retain_handling rhs) { return opts(lhs) | rhs; }
352
365constexpr opts operator|(nl lhs, rap rhs) { return opts(lhs) | rhs; }
366
379constexpr opts operator|(nl lhs, qos rhs) { return opts(lhs) | rhs; }
380
393constexpr opts operator|(qos lhs, retain_handling rhs) { return opts(lhs) | rhs; }
394
407constexpr opts operator|(qos lhs, rap rhs) { return opts(lhs) | rhs; }
408
421constexpr opts operator|(qos lhs, nl rhs) { return opts(lhs) | rhs; }
422
435constexpr char const* retain_handling_to_str(retain_handling v) {
436 switch(v) {
437 case retain_handling::send: return "send";
438 case retain_handling::send_only_new_subscription: return "send_only_new_subscription";
439 case retain_handling::not_send: return "not_send";
440 default: return "invalid_retain_handling";
441 }
442}
443
457inline
458std::ostream& operator<<(std::ostream& o, retain_handling v)
459{
461 return o;
462}
463
476constexpr char const* rap_to_str(rap v) {
477 switch(v) {
478 case rap::dont: return "dont";
479 case rap::retain: return "retain";
480 default: return "invalid_rap";
481 }
482}
483
497inline
498std::ostream& operator<<(std::ostream& o, rap v)
499{
500 o << rap_to_str(v);
501 return o;
502}
503
516constexpr char const* nl_to_str(nl v) {
517 switch(v) {
518 case nl::no: return "no";
519 case nl::yes: return "yes";
520 default: return "invalid_nl";
521 }
522}
523
537inline
538std::ostream& operator<<(std::ostream& o, nl v)
539{
540 o << nl_to_str(v);
541 return o;
542}
543
544} // namespace sub
545
546} // namespace async_mqtt
547
548#endif // ASYNC_MQTT_PACKET_SUBOPTS_HPP
qos
MQTT QoS.
Definition qos.hpp:35
constexpr char const * nl_to_str(nl v)
stringize nl(no local)
Definition subopts.hpp:516
constexpr char const * retain_handling_to_str(retain_handling v)
stringize retain_handling
Definition subopts.hpp:435
std::ostream & operator<<(std::ostream &o, retain_handling v)
output to the stream
Definition subopts.hpp:458
nl
MQTT NoLocal.
Definition subopts.hpp:71
std::ostream & operator<<(std::ostream &o, rap v)
output to the stream
Definition subopts.hpp:498
rap
MQTT RetainAsPublished.
Definition subopts.hpp:54
retain_handling
MQTT RetainHandling.
Definition subopts.hpp:36
constexpr char const * rap_to_str(rap v)
stringize rap(retain as published)
Definition subopts.hpp:476
std::ostream & operator<<(std::ostream &o, nl v)
output to the stream
Definition subopts.hpp:538
@ no
Subscriber's publish would be delivered to the subscriber itself. Same as MQTT v.3....
@ yes
Subscriber's publish would not be delivered to the subscriber itself.
@ retain
Preserve published Retain delivery on publish by the broker.
@ dont
Retain is set to 0 delivery on publish by the broker. Same as MQTT v.3.1.1.
@ send_only_new_subscription
Only new subscription. Not overwrite.
@ send
Always send. Same as MQTT v.3.1.1.
MQTT SubscribeOptions.
Definition subopts.hpp:90
constexpr opts & operator|=(rap rhs)
Combine opts operator.
Definition subopts.hpp:182
constexpr bool operator<(opts rhs) const
less than operator
Definition subopts.hpp:249
constexpr opts operator|(retain_handling rhs) const
Combine opts operator.
Definition subopts.hpp:140
constexpr opts(qos value)
constructor
Definition subopts.hpp:126
constexpr opts & operator|=(retain_handling rhs)
Combine opts operator.
Definition subopts.hpp:175
constexpr opts operator|(nl lhs, retain_handling rhs)
Combine opts operator.
Definition subopts.hpp:351
constexpr opts operator|(retain_handling lhs, nl rhs)
Combine opts operator.
Definition subopts.hpp:281
constexpr opts(std::uint8_t value)
constructor
Definition subopts.hpp:102
constexpr opts operator|(rap rhs) const
Combine opts operator.
Definition subopts.hpp:147
constexpr opts operator|(qos rhs) const
Combine opts operator.
Definition subopts.hpp:161
constexpr opts operator|(rap lhs, retain_handling rhs)
Combine opts operator.
Definition subopts.hpp:309
constexpr bool operator==(opts rhs) const
equal operator
Definition subopts.hpp:242
constexpr opts operator|(qos lhs, retain_handling rhs)
Combine opts operator.
Definition subopts.hpp:393
constexpr opts & operator|=(opts rhs)
Combine opts operator.
Definition subopts.hpp:168
constexpr opts operator|(nl rhs) const
Combine opts operator.
Definition subopts.hpp:154
constexpr opts & operator|=(nl rhs)
Combine opts operator.
Definition subopts.hpp:189
constexpr opts operator|(rap lhs, nl rhs)
Combine opts operator.
Definition subopts.hpp:323
constexpr opts operator|(qos lhs, rap rhs)
Combine opts operator.
Definition subopts.hpp:407
constexpr opts operator|(retain_handling lhs, qos rhs)
Combine opts operator.
Definition subopts.hpp:295
constexpr opts(rap value)
constructor
Definition subopts.hpp:114
constexpr operator std::uint8_t() const
Get byte image.
Definition subopts.hpp:235
constexpr opts operator|(retain_handling lhs, rap rhs)
Combine opts operator.
Definition subopts.hpp:267
constexpr opts & operator|=(qos rhs)
Combine opts operator.
Definition subopts.hpp:196
constexpr opts operator|(opts rhs) const
Combine opts operator.
Definition subopts.hpp:133
constexpr opts(retain_handling value)
constructor
Definition subopts.hpp:108
constexpr retain_handling get_retain_handling() const
Get retain_handling.
Definition subopts.hpp:203
constexpr opts operator|(nl lhs, rap rhs)
Combine opts operator.
Definition subopts.hpp:365
constexpr qos get_qos() const
Get qos.
Definition subopts.hpp:227
constexpr opts operator|(nl lhs, qos rhs)
Combine opts operator.
Definition subopts.hpp:379
constexpr rap get_rap() const
Get rap.
Definition subopts.hpp:211
constexpr nl get_nl() const
Get nl.
Definition subopts.hpp:219
constexpr opts operator|(rap lhs, qos rhs)
Combine opts operator.
Definition subopts.hpp:337
constexpr opts operator|(qos lhs, nl rhs)
Combine opts operator.
Definition subopts.hpp:421
constexpr opts(nl value)
constructor
Definition subopts.hpp:120