7#if !defined(ASYNC_MQTT_PACKET_PUBOPTS_HPP)
8#define ASYNC_MQTT_PACKET_PUBOPTS_HPP
10#include <boost/assert.hpp>
27 return (
v & 0b00001000) != 0;
37 return static_cast<qos>((
v & 0b00000110) >> 1);
47 return (
v & 0b00000001) != 0;
58 else fixed_header &=
static_cast<std::uint8_t
>(~0b00001000);
77enum class dup : std::uint8_t {
88 constexpr opts() =
default;
91 constexpr opts(
opts const&) =
default;
92 constexpr opts& operator=(
opts &&) =
default;
93 constexpr opts& operator=(
opts const&) =
default;
162 {
return static_cast<enum retain>(data_ & 0b00000001); }
170 {
return static_cast<enum dup>(data_ & 0b00001000); }
178 {
return static_cast<enum qos>((data_ & 0b00000110) >> 1); }
185 explicit constexpr operator std::uint8_t()
const {
return data_; }
198 std::uint8_t data_ = 0;
241 case retain::yes:
return "yes";
242 case retain::no:
return "no";
243 default:
return "invalid_retain";
254 os << retain_to_str(val);
264 case dup::yes:
return "yes";
265 case dup::no:
return "no";
266 default:
return "invalid_dup";
278 os << dup_to_str(val);
Definition packet_variant.hpp:49
retain
MQTT RETAIN.
Definition pubopts.hpp:66
dup
MQTT DUP.
Definition pubopts.hpp:77
qos
MQTT QoS.
Definition qos.hpp:23
MQTT PublishOptions.
Definition pubopts.hpp:87
constexpr operator std::uint8_t() const
Get byte image.
Definition pubopts.hpp:185
constexpr opts operator|(dup lhs, retain rhs)
Combine opts operator.
Definition pubopts.hpp:216
constexpr char const * dup_to_str(dup v)
stringize dup
Definition pubopts.hpp:262
constexpr opts(std::uint8_t value)
constructor
Definition pubopts.hpp:99
constexpr opts(dup value)
constructor
Definition pubopts.hpp:111
constexpr opts & operator|=(retain rhs)
Combine opts operator.
Definition pubopts.hpp:146
constexpr qos get_qos(std::uint8_t v)
Get qos from the fixed header.
Definition pubopts.hpp:36
constexpr char const * retain_to_str(retain v)
stringize retain
Definition pubopts.hpp:239
constexpr void set_dup(std::uint8_t &fixed_header, bool dup)
Set DUP to the fixed header.
Definition pubopts.hpp:56
constexpr bool operator==(opts rhs) const
equal operator
Definition pubopts.hpp:190
constexpr opts operator|(qos lhs, retain rhs)
Combine opts operator.
Definition pubopts.hpp:227
constexpr dup get_dup() const
Get dup.
Definition pubopts.hpp:169
constexpr bool operator<(opts rhs) const
less than operator
Definition pubopts.hpp:195
constexpr opts operator|(dup lhs, qos rhs)
Combine opts operator.
Definition pubopts.hpp:221
constexpr retain get_retain() const
Get retain.
Definition pubopts.hpp:161
constexpr bool is_retain(std::uint8_t v)
Check fixed header is RETAIN.
Definition pubopts.hpp:46
constexpr qos get_qos() const
Get qos.
Definition pubopts.hpp:177
constexpr opts & operator|=(qos rhs)
Combine opts operator.
Definition pubopts.hpp:154
constexpr opts operator|(opts rhs) const
Combine opts operator.
Definition pubopts.hpp:125
std::ostream & operator<<(std::ostream &os, retain val)
output to the stream retain
Definition pubopts.hpp:252
constexpr opts & operator|=(dup rhs)
Combine opts operator.
Definition pubopts.hpp:150
constexpr opts(retain value)
constructor
Definition pubopts.hpp:105
constexpr opts operator|(qos rhs) const
Combine opts operator.
Definition pubopts.hpp:137
std::ostream & operator<<(std::ostream &os, dup val)
output to the stream dup
Definition pubopts.hpp:276
constexpr opts operator|(retain lhs, dup rhs)
Combine opts operator.
Definition pubopts.hpp:205
constexpr opts operator|(qos lhs, dup rhs)
Combine opts operator.
Definition pubopts.hpp:232
constexpr opts operator|(retain lhs, qos rhs)
Combine opts operator.
Definition pubopts.hpp:210
constexpr opts(qos value)
constructor
Definition pubopts.hpp:117
constexpr opts operator|(dup rhs) const
Combine opts operator.
Definition pubopts.hpp:133
constexpr opts operator|(retain rhs) const
Combine opts operator.
Definition pubopts.hpp:129
constexpr bool is_dup(std::uint8_t v)
Check fixed header is DUP.
Definition pubopts.hpp:26
constexpr opts & operator|=(opts rhs)
Combine opts operator.
Definition pubopts.hpp:142