7#if !defined(ASYNC_MQTT_PACKET_STORE_PACKET_VARIANT_HPP)
8#define ASYNC_MQTT_PACKET_STORE_PACKET_VARIANT_HPP
10#include <async_mqtt/util/variant.hpp>
11#include <async_mqtt/packet/packet_id_type.hpp>
12#include <async_mqtt/packet/v3_1_1_publish.hpp>
13#include <async_mqtt/packet/v3_1_1_pubrel.hpp>
14#include <async_mqtt/packet/v5_publish.hpp>
15#include <async_mqtt/packet/v5_pubrel.hpp>
16#include <async_mqtt/exception.hpp>
38template <std::
size_t PacketIdBytes>
41 using packet_id_t =
typename packet_id_type<PacketIdBytes>::type;
50 switch (packet.
opts().get_qos()) {
51 case qos::at_least_once:
52 return response_packet::v3_1_1_puback;
53 case qos::exactly_once:
54 return response_packet::v3_1_1_pubrec;
58 "qos::at_most_once cannot store"
63 var_{force_move(packet)}
72 var_{force_move(packet)}
82 switch (packet.opts().get_qos()) {
83 case qos::at_least_once:
84 return response_packet::v5_puback;
85 case qos::exactly_once:
86 return response_packet::v5_pubrec;
90 "qos::at_most_once cannot store"
95 var_{force_move(packet)}
104 var_{force_move(packet)}
111 template <
typename Func>
115 std::forward<Func>(
func),
124 template <
typename Func>
128 std::forward<Func>(
func),
137 template <
typename Func>
141 std::forward<Func>(
func),
155 return p.const_buffer_sequence();
159 return std::vector<as::const_buffer>{};
173 return p.packet_id();
186 [] (
auto const& p) -> std::size_t {
200 [] (v5::basic_publish_packet<PacketIdBytes>
const& p) {
201 std::uint32_t
ret = 0;
203 for (
auto const&
prop : p.props()) {
219 return std::uint32_t(0);
232 [&] (v5::basic_publish_packet<PacketIdBytes>& p) {
234 for (
auto&
prop : p.props()) {
263 using variant_t = variant<
266 v5::basic_publish_packet<PacketIdBytes>,
274template <std::
size_t PacketIdBytes>
275inline std::ostream& operator<<(std::ostream& o, basic_store_packet_variant<PacketIdBytes>
const& v) {
278 [&] (
auto const& p) {
286using store_packet_variant = basic_store_packet_variant<2>;
Definition packet_variant.hpp:49
auto visit(Func &&func) const &
visit to variant
Definition packet_variant.hpp:74
MQTT packet variant for store.
Definition store_packet_variant.hpp:39
response_packet response_packet_type() const
Get response packet type corresponding to this packet.
Definition store_packet_variant.hpp:258
auto visit(Func &&func) const &
visit to variant
Definition store_packet_variant.hpp:112
basic_store_packet_variant(v3_1_1::basic_pubrel_packet< PacketIdBytes > packet)
constructor
Definition store_packet_variant.hpp:70
basic_store_packet_variant(v5::basic_publish_packet< PacketIdBytes > packet)
constructor
Definition store_packet_variant.hpp:79
std::vector< as::const_buffer > const_buffer_sequence() const
Create const buffer sequence it is for boost asio APIs.
Definition store_packet_variant.hpp:151
std::size_t size() const
Get packet size.
Definition store_packet_variant.hpp:183
basic_store_packet_variant(v5::basic_pubrel_packet< PacketIdBytes > packet)
constructor
Definition store_packet_variant.hpp:102
packet_id_t packet_id() const
Get packet id.
Definition store_packet_variant.hpp:169
auto visit(Func &&func) &&
visit to variant
Definition store_packet_variant.hpp:138
void update_message_expiry_interval(std::uint32_t val) const
Definition store_packet_variant.hpp:229
auto visit(Func &&func) &
visit to variant
Definition store_packet_variant.hpp:125
basic_store_packet_variant(v3_1_1::basic_publish_packet< PacketIdBytes > packet)
constructor
Definition store_packet_variant.hpp:47
std::uint32_t get_message_expiry_interval() const
Definition store_packet_variant.hpp:197
Definition property.hpp:350
MQTT PUBLISH packet (v3.1.1)
Definition v3_1_1_publish.hpp:50
constexpr pub::opts opts() const
Get publish_options.
Definition v3_1_1_publish.hpp:331
MQTT PUBREL packet (v3.1.1)
Definition v3_1_1_pubrel.hpp:41
MQTT PUBREL packet (v5)
Definition v5_pubrel.hpp:45
response_packet
corresponding response packet
Definition store_packet_variant.hpp:25
@ v5_pubrec
stored packet is v5_basic_publish_packet QoS2
@ v3_1_1_pubcomp
stored packet is v3_1_1_basic_pubrel_packet
@ v3_1_1_pubrec
stored packet is v3_1_1_basic_publish_packet QoS2
@ v5_pubcomp
stored packet is v5_basic_rel_packet
@ v3_1_1_puback
stored packet is v3_1_1_basic_publish_packet QoS1
@ v5_puback
stored packet is v5_basic_publish_packet QoS1
async_mqtt error class. It is used as CompletionToken parameter and exception.
Definition exception.hpp:29