7#if !defined(ASYNC_MQTT_PACKET_PACKET_VARIANT_HPP)
8#define ASYNC_MQTT_PACKET_PACKET_VARIANT_HPP
12#include <boost/asio/buffer.hpp>
14#include <async_mqtt/packet/control_packet_type.hpp>
15#include <async_mqtt/packet/packet_variant_fwd.hpp>
16#include <async_mqtt/packet/packet_fwd.hpp>
17#include <async_mqtt/packet/v3_1_1_connect.hpp>
18#include <async_mqtt/packet/v3_1_1_connack.hpp>
19#include <async_mqtt/packet/v3_1_1_publish.hpp>
20#include <async_mqtt/packet/v3_1_1_puback.hpp>
21#include <async_mqtt/packet/v3_1_1_pubrec.hpp>
22#include <async_mqtt/packet/v3_1_1_pubrel.hpp>
23#include <async_mqtt/packet/v3_1_1_pubcomp.hpp>
24#include <async_mqtt/packet/v3_1_1_subscribe.hpp>
25#include <async_mqtt/packet/v3_1_1_suback.hpp>
26#include <async_mqtt/packet/v3_1_1_unsubscribe.hpp>
27#include <async_mqtt/packet/v3_1_1_unsuback.hpp>
28#include <async_mqtt/packet/v3_1_1_pingreq.hpp>
29#include <async_mqtt/packet/v3_1_1_pingresp.hpp>
30#include <async_mqtt/packet/v3_1_1_disconnect.hpp>
31#include <async_mqtt/packet/v5_connect.hpp>
32#include <async_mqtt/packet/v5_connack.hpp>
33#include <async_mqtt/packet/v5_publish.hpp>
34#include <async_mqtt/packet/v5_puback.hpp>
35#include <async_mqtt/packet/v5_pubrec.hpp>
36#include <async_mqtt/packet/v5_pubrel.hpp>
37#include <async_mqtt/packet/v5_pubcomp.hpp>
38#include <async_mqtt/packet/v5_subscribe.hpp>
39#include <async_mqtt/packet/v5_suback.hpp>
40#include <async_mqtt/packet/v5_unsubscribe.hpp>
41#include <async_mqtt/packet/v5_unsuback.hpp>
42#include <async_mqtt/packet/v5_pingreq.hpp>
43#include <async_mqtt/packet/v5_pingresp.hpp>
44#include <async_mqtt/packet/v5_disconnect.hpp>
45#include <async_mqtt/packet/v5_auth.hpp>
47#include <async_mqtt/util/overload.hpp>
50namespace as = boost::asio;
52template <std::
size_t PacketIdBytes>
53class basic_packet_variant {
82 template <
typename Func>
89 template <
typename Func>
96 template <
typename Func>
103 template <
typename T>
110 template <
typename T>
111 decltype(
auto)
get()
const;
117 template <
typename T>
124 template <
typename T>
131 std::optional<control_packet_type>
type()
const;
140 operator bool()
const;
151 return lhs.var_ < rhs.var_;
161 return lhs.var_ == rhs.var_;
164 using variant_t = std::variant<
207template <std::
size_t PacketIdBytes>
212#include <async_mqtt/packet/impl/packet_variant.hpp>
214#if !defined(ASYNC_MQTT_SEPARATE_COMPILATION)
215#include <async_mqtt/packet/impl/packet_variant.ipp>
The varaint type of all packets and system_error.
Definition packet_variant_fwd.hpp:37
basic_packet_variant()=default
constructor the variant value is monostate
decltype(auto) get() const
Get by type. If not match, then throw std::bad_variant_access exception.
auto visit(Func &&func) const &
visit to variant
friend bool operator<(basic_packet_variant< PacketIdBytes > const &lhs, basic_packet_variant< PacketIdBytes > const &rhs)
less than operator
Definition packet_variant.hpp:150
std::optional< control_packet_type > type() const
Get control_packet_type.
decltype(auto) get()
Get by type. If not match, then throw std::bad_variant_access exception.
decltype(auto) get_if() const
Get by type pointer.
decltype(auto) get_if()
Get by type pointer.
std::ostream & operator<<(std::ostream &o, basic_packet_variant< PacketIdBytes > const &v)
stream output operator
friend bool operator==(basic_packet_variant< PacketIdBytes > const &lhs, basic_packet_variant< PacketIdBytes > const &rhs)
equal operator
Definition packet_variant.hpp:160
basic_packet_variant(Packet &&packet)
constructor
auto visit(Func &&func) &
visit to variant
auto visit(Func &&func) &&
visit to variant
std::vector< as::const_buffer > const_buffer_sequence() const
Create const buffer sequence it is for boost asio APIs.
MQTT PUBACK packet (v3.1.1)
Definition v3_1_1_puback.hpp:54
MQTT PUBCOMP packet (v3.1.1)
Definition v3_1_1_pubcomp.hpp:54
MQTT PUBLISH packet (v3.1.1)
Definition v3_1_1_publish.hpp:61
MQTT PUBREC packet (v3.1.1)
Definition v3_1_1_pubrec.hpp:53
MQTT PUBREL packet (v3.1.1)
Definition v3_1_1_pubrel.hpp:55
MQTT SUBACK packet (v3.1.1)
Definition v3_1_1_suback.hpp:53
MQTT SUBSCRIBE packet (v3.1.1)
Definition v3_1_1_subscribe.hpp:52
MQTT UNSUBACK packet (v3.1.1)
Definition v3_1_1_unsuback.hpp:50
MQTT UNSUBSCRIBE packet (v3.1.1)
Definition v3_1_1_unsubscribe.hpp:53
MQTT CONNACK packet (v3.1.1)
Definition v3_1_1_connack.hpp:44
MQTT CONNECT packet (v3.1.1)
Definition v3_1_1_connect.hpp:42
MQTT DISCONNECT packet (v3.1.1)
Definition v3_1_1_disconnect.hpp:57
MQTT PINGREQ packet (v3.1.1)
Definition v3_1_1_pingreq.hpp:48
MQTT PINGRESP packet (v3.1.1)
Definition v3_1_1_pingresp.hpp:48
MQTT AUTH packet (v5)
Definition v5_auth.hpp:47
MQTT PUBACK packet (v5)
Definition v5_puback.hpp:55
MQTT PUBCOMP packet (v5)
Definition v5_pubcomp.hpp:56
MQTT PUBLISH packet (v5)
Definition v5_publish.hpp:63
MQTT PUBREC packet (v5)
Definition v5_pubrec.hpp:55
MQTT PUBREL packet (v5)
Definition v5_pubrel.hpp:56
MQTT SUBACK packet (v5)
Definition v5_suback.hpp:53
MQTT SUBSCRIBE packet (v5)
Definition v5_subscribe.hpp:53
MQTT UNSUBACK packet (v5)
Definition v5_unsuback.hpp:52
MQTT UNSUBSCRIBE packet (v5)
Definition v5_unsubscribe.hpp:54
MQTT CONNACK packet (v5)
Definition v5_connack.hpp:44
MQTT CONNECT packet (v5)
Definition v5_connect.hpp:49
MQTT DISCONNECT packet (v5)
Definition v5_disconnect.hpp:50
MQTT PINGREQ packet (v5)
Definition v5_pingreq.hpp:50
MQTT PINGRESP packet (v5)
Definition v5_pingresp.hpp:57