7#if !defined(ASYNC_MQTT_PACKET_PACKET_TRAITS_HPP)
8#define ASYNC_MQTT_PACKET_PACKET_TRAITS_HPP
21template <std::
size_t PacketIdBytes>
22class basic_publish_packet;
24template <std::
size_t PacketIdBytes>
25class basic_puback_packet;
27template <std::
size_t PacketIdBytes>
28class basic_pubrec_packet;
30template <std::
size_t PacketIdBytes>
31class basic_pubrel_packet;
33template <std::
size_t PacketIdBytes>
34class basic_pubcomp_packet;
36template <std::
size_t PacketIdBytes>
37class basic_subscribe_packet;
39template <std::
size_t PacketIdBytes>
40class basic_suback_packet;
42template <std::
size_t PacketIdBytes>
43class basic_unsubscribe_packet;
45template <std::
size_t PacketIdBytes>
46class basic_unsuback_packet;
52class disconnect_packet;
62template <std::
size_t PacketIdBytes>
63class basic_publish_packet;
65template <std::
size_t PacketIdBytes>
66class basic_puback_packet;
68template <std::
size_t PacketIdBytes>
69class basic_pubrec_packet;
71template <std::
size_t PacketIdBytes>
72class basic_pubrel_packet;
74template <std::
size_t PacketIdBytes>
75class basic_pubcomp_packet;
77template <std::
size_t PacketIdBytes>
78class basic_subscribe_packet;
80template <std::
size_t PacketIdBytes>
81class basic_suback_packet;
83template <std::
size_t PacketIdBytes>
84class basic_unsubscribe_packet;
86template <std::
size_t PacketIdBytes>
87class basic_unsuback_packet;
93class disconnect_packet;
99template <std::
size_t PacketIdBytes>
100class basic_store_packet_variant;
102template <
template <std::
size_t>
typename,
typename>
103struct is_instance_of : std::false_type {};
105template <
template <std::
size_t>
typename T, std::size_t N>
106struct is_instance_of<T, T<N>> : std::true_type {};
108template <
typename Packet>
109constexpr bool is_client_sendable() {
111 std::is_same_v<v3_1_1::connect_packet, Packet> ||
112 std::is_same_v<v3_1_1::pingreq_packet, Packet> ||
113 std::is_same_v<v3_1_1::disconnect_packet, Packet> ||
114 is_instance_of<v3_1_1::basic_publish_packet, Packet>::value ||
115 is_instance_of<v3_1_1::basic_puback_packet, Packet>::value ||
116 is_instance_of<v3_1_1::basic_pubrec_packet, Packet>::value ||
117 is_instance_of<v3_1_1::basic_pubrel_packet, Packet>::value ||
118 is_instance_of<v3_1_1::basic_pubcomp_packet, Packet>::value ||
119 is_instance_of<v3_1_1::basic_subscribe_packet, Packet>::value ||
120 is_instance_of<v3_1_1::basic_unsubscribe_packet, Packet>::value ||
121 std::is_same_v<v5::connect_packet, Packet> ||
122 std::is_same_v<v5::pingreq_packet, Packet> ||
123 std::is_same_v<v5::disconnect_packet, Packet> ||
124 is_instance_of<v5::basic_publish_packet, Packet>::value ||
125 is_instance_of<v5::basic_puback_packet, Packet>::value ||
126 is_instance_of<v5::basic_pubrec_packet, Packet>::value ||
127 is_instance_of<v5::basic_pubrel_packet, Packet>::value ||
128 is_instance_of<v5::basic_pubcomp_packet, Packet>::value ||
129 is_instance_of<v5::basic_subscribe_packet, Packet>::value ||
130 is_instance_of<v5::basic_unsubscribe_packet, Packet>::value ||
131 std::is_same_v<v5::auth_packet, Packet> ||
132 is_instance_of<basic_store_packet_variant, Packet>::value
136template <
typename Packet>
137constexpr bool is_server_sendable() {
139 std::is_same_v<v3_1_1::connack_packet, Packet> ||
140 std::is_same_v<v3_1_1::pingresp_packet, Packet> ||
141 is_instance_of<v3_1_1::basic_publish_packet, Packet>::value ||
142 is_instance_of<v3_1_1::basic_puback_packet, Packet>::value ||
143 is_instance_of<v3_1_1::basic_pubrec_packet, Packet>::value ||
144 is_instance_of<v3_1_1::basic_pubrel_packet, Packet>::value ||
145 is_instance_of<v3_1_1::basic_pubcomp_packet, Packet>::value ||
146 is_instance_of<v3_1_1::basic_suback_packet, Packet>::value ||
147 is_instance_of<v3_1_1::basic_unsuback_packet, Packet>::value ||
148 std::is_same_v<v5::connack_packet, Packet> ||
149 std::is_same_v<v5::pingresp_packet, Packet> ||
150 std::is_same_v<v5::disconnect_packet, Packet> ||
151 is_instance_of<v5::basic_publish_packet, Packet>::value ||
152 is_instance_of<v5::basic_puback_packet, Packet>::value ||
153 is_instance_of<v5::basic_pubrec_packet, Packet>::value ||
154 is_instance_of<v5::basic_pubrel_packet, Packet>::value ||
155 is_instance_of<v5::basic_pubcomp_packet, Packet>::value ||
156 is_instance_of<v5::basic_suback_packet, Packet>::value ||
157 is_instance_of<v5::basic_unsuback_packet, Packet>::value ||
158 std::is_same_v<v5::auth_packet, Packet> ||
159 is_instance_of<basic_store_packet_variant, Packet>::value
163template <
typename Packet>
164constexpr bool is_v5() {
166 std::is_same_v<v5::connect_packet, Packet> ||
167 std::is_same_v<v5::connack_packet, Packet> ||
168 std::is_same_v<v5::pingreq_packet, Packet> ||
169 std::is_same_v<v5::pingresp_packet, Packet> ||
170 std::is_same_v<v5::disconnect_packet, Packet> ||
171 is_instance_of<v5::basic_publish_packet, Packet>::value ||
172 is_instance_of<v5::basic_puback_packet, Packet>::value ||
173 is_instance_of<v5::basic_pubrec_packet, Packet>::value ||
174 is_instance_of<v5::basic_pubrel_packet, Packet>::value ||
175 is_instance_of<v5::basic_pubcomp_packet, Packet>::value ||
176 is_instance_of<v5::basic_subscribe_packet, Packet>::value ||
177 is_instance_of<v5::basic_suback_packet, Packet>::value ||
178 is_instance_of<v5::basic_unsubscribe_packet, Packet>::value ||
179 is_instance_of<v5::basic_unsuback_packet, Packet>::value ||
180 std::is_same_v<v5::auth_packet, Packet>;
183template <
typename Packet>
184constexpr bool is_v3_1_1() {
186 std::is_same_v<v3_1_1::connect_packet, Packet> ||
187 std::is_same_v<v3_1_1::connack_packet, Packet> ||
188 std::is_same_v<v3_1_1::pingreq_packet, Packet> ||
189 std::is_same_v<v3_1_1::pingresp_packet, Packet> ||
190 std::is_same_v<v3_1_1::disconnect_packet, Packet> ||
191 is_instance_of<v3_1_1::basic_publish_packet, Packet>::value ||
192 is_instance_of<v3_1_1::basic_puback_packet, Packet>::value ||
193 is_instance_of<v3_1_1::basic_pubrec_packet, Packet>::value ||
194 is_instance_of<v3_1_1::basic_pubrel_packet, Packet>::value ||
195 is_instance_of<v3_1_1::basic_pubcomp_packet, Packet>::value ||
196 is_instance_of<v3_1_1::basic_subscribe_packet, Packet>::value ||
197 is_instance_of<v3_1_1::basic_suback_packet, Packet>::value ||
198 is_instance_of<v3_1_1::basic_unsubscribe_packet, Packet>::value ||
199 is_instance_of<v3_1_1::basic_unsuback_packet, Packet>::value;
202template <
typename Packet>
203constexpr bool is_auth() {
205 std::is_same_v<v5::auth_packet, Packet>;
208template <
typename Packet>
209constexpr bool is_connect() {
211 std::is_same_v<v3_1_1::connect_packet, Packet> ||
212 std::is_same_v<v5::connect_packet, Packet>;
215template <
typename Packet>
216constexpr bool is_connack() {
218 std::is_same_v<v3_1_1::connack_packet, Packet> ||
219 std::is_same_v<v5::connack_packet, Packet>;
222template <
typename Packet>
223constexpr bool is_publish() {
225 is_instance_of<v3_1_1::basic_publish_packet, Packet>::value ||
226 is_instance_of<v5::basic_publish_packet, Packet>::value;
229template <
typename Packet>
230constexpr bool is_puback() {
232 is_instance_of<v3_1_1::basic_puback_packet, Packet>::value ||
233 is_instance_of<v5::basic_puback_packet, Packet>::value;
236template <
typename Packet>
237constexpr bool is_pubrec() {
239 is_instance_of<v3_1_1::basic_pubrec_packet, Packet>::value ||
240 is_instance_of<v5::basic_pubrec_packet, Packet>::value;
243template <
typename Packet>
244constexpr bool is_pubrel() {
246 is_instance_of<v3_1_1::basic_pubrel_packet, Packet>::value ||
247 is_instance_of<v5::basic_pubrel_packet, Packet>::value;
250template <
typename Packet>
251constexpr bool is_pubcomp() {
253 is_instance_of<v3_1_1::basic_pubcomp_packet, Packet>::value ||
254 is_instance_of<v5::basic_pubcomp_packet, Packet>::value;
257template <
typename Packet>
258constexpr bool is_subscribe() {
260 is_instance_of<v3_1_1::basic_subscribe_packet, Packet>::value ||
261 is_instance_of<v5::basic_subscribe_packet, Packet>::value;
264template <
typename Packet>
265constexpr bool is_suback() {
267 is_instance_of<v3_1_1::basic_suback_packet, Packet>::value ||
268 is_instance_of<v5::basic_suback_packet, Packet>::value;
271template <
typename Packet>
272constexpr bool is_unsubscribe() {
274 is_instance_of<v3_1_1::basic_unsubscribe_packet, Packet>::value ||
275 is_instance_of<v5::basic_unsubscribe_packet, Packet>::value;
278template <
typename Packet>
279constexpr bool is_unsuback() {
281 is_instance_of<v3_1_1::basic_unsuback_packet, Packet>::value ||
282 is_instance_of<v5::basic_unsuback_packet, Packet>::value;
285template <
typename Packet>
286constexpr bool is_pingreq() {
288 std::is_same_v<v3_1_1::pingreq_packet, Packet> ||
289 std::is_same_v<v5::pingreq_packet, Packet>;
292template <
typename Packet>
293constexpr bool is_pingresp() {
295 std::is_same_v<v3_1_1::pingresp_packet, Packet> ||
296 std::is_same_v<v5::pingresp_packet, Packet>;
299template <
typename Packet>
300constexpr bool is_disconnect() {
302 std::is_same_v<v3_1_1::disconnect_packet, Packet> ||
303 std::is_same_v<v5::disconnect_packet, Packet>;
306template <
typename Packet>
307constexpr bool own_packet_id() {
309 is_publish<Packet>() ||
310 is_pubrel<Packet>() ||
311 is_subscribe<Packet>() ||
312 is_unsubscribe<Packet>();