async_mqtt 5.0.0
Loading...
Searching...
No Matches
packet_traits.hpp
1// Copyright Takatoshi Kondo 2022
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_PACKET_TRAITS_HPP)
8#define ASYNC_MQTT_PACKET_PACKET_TRAITS_HPP
9
10#include <cstdint>
11#include <type_traits>
12
13namespace async_mqtt {
14
15namespace v3_1_1 {
16
17class connect_packet;
18
19class connack_packet;
20
21template <std::size_t PacketIdBytes>
22class basic_publish_packet;
23
24template <std::size_t PacketIdBytes>
25class basic_puback_packet;
26
27template <std::size_t PacketIdBytes>
28class basic_pubrec_packet;
29
30template <std::size_t PacketIdBytes>
31class basic_pubrel_packet;
32
33template <std::size_t PacketIdBytes>
34class basic_pubcomp_packet;
35
36template <std::size_t PacketIdBytes>
37class basic_subscribe_packet;
38
39template <std::size_t PacketIdBytes>
40class basic_suback_packet;
41
42template <std::size_t PacketIdBytes>
43class basic_unsubscribe_packet;
44
45template <std::size_t PacketIdBytes>
46class basic_unsuback_packet;
47
48class pingreq_packet;
49
50class pingresp_packet;
51
52class disconnect_packet;
53
54} // namespace v3_1_1
55
56namespace v5 {
57
58class connect_packet;
59
60class connack_packet;
61
62template <std::size_t PacketIdBytes>
63class basic_publish_packet;
64
65template <std::size_t PacketIdBytes>
66class basic_puback_packet;
67
68template <std::size_t PacketIdBytes>
69class basic_pubrec_packet;
70
71template <std::size_t PacketIdBytes>
72class basic_pubrel_packet;
73
74template <std::size_t PacketIdBytes>
75class basic_pubcomp_packet;
76
77template <std::size_t PacketIdBytes>
78class basic_subscribe_packet;
79
80template <std::size_t PacketIdBytes>
81class basic_suback_packet;
82
83template <std::size_t PacketIdBytes>
84class basic_unsubscribe_packet;
85
86template <std::size_t PacketIdBytes>
87class basic_unsuback_packet;
88
89class pingreq_packet;
90
91class pingresp_packet;
92
93class disconnect_packet;
94
95class auth_packet;
96
97} // namespace v5
98
99template <std::size_t PacketIdBytes>
100class basic_store_packet_variant;
101
102template <template <std::size_t> typename, typename>
103struct is_instance_of : std::false_type {};
104
105template <template <std::size_t> typename T, std::size_t N>
106struct is_instance_of<T, T<N>> : std::true_type {};
107
108template <typename Packet>
109constexpr bool is_client_sendable() {
110 return
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
133 ;
134}
135
136template <typename Packet>
137constexpr bool is_server_sendable() {
138 return
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
160 ;
161}
162
163template <typename Packet>
164constexpr bool is_v5() {
165 return
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>;
181}
182
183template <typename Packet>
184constexpr bool is_v3_1_1() {
185 return
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;
200}
201
202template <typename Packet>
203constexpr bool is_auth() {
204 return
205 std::is_same_v<v5::auth_packet, Packet>;
206}
207
208template <typename Packet>
209constexpr bool is_connect() {
210 return
211 std::is_same_v<v3_1_1::connect_packet, Packet> ||
212 std::is_same_v<v5::connect_packet, Packet>;
213}
214
215template <typename Packet>
216constexpr bool is_connack() {
217 return
218 std::is_same_v<v3_1_1::connack_packet, Packet> ||
219 std::is_same_v<v5::connack_packet, Packet>;
220}
221
222template <typename Packet>
223constexpr bool is_publish() {
224 return
225 is_instance_of<v3_1_1::basic_publish_packet, Packet>::value ||
226 is_instance_of<v5::basic_publish_packet, Packet>::value;
227}
228
229template <typename Packet>
230constexpr bool is_puback() {
231 return
232 is_instance_of<v3_1_1::basic_puback_packet, Packet>::value ||
233 is_instance_of<v5::basic_puback_packet, Packet>::value;
234}
235
236template <typename Packet>
237constexpr bool is_pubrec() {
238 return
239 is_instance_of<v3_1_1::basic_pubrec_packet, Packet>::value ||
240 is_instance_of<v5::basic_pubrec_packet, Packet>::value;
241}
242
243template <typename Packet>
244constexpr bool is_pubrel() {
245 return
246 is_instance_of<v3_1_1::basic_pubrel_packet, Packet>::value ||
247 is_instance_of<v5::basic_pubrel_packet, Packet>::value;
248}
249
250template <typename Packet>
251constexpr bool is_pubcomp() {
252 return
253 is_instance_of<v3_1_1::basic_pubcomp_packet, Packet>::value ||
254 is_instance_of<v5::basic_pubcomp_packet, Packet>::value;
255}
256
257template <typename Packet>
258constexpr bool is_subscribe() {
259 return
260 is_instance_of<v3_1_1::basic_subscribe_packet, Packet>::value ||
261 is_instance_of<v5::basic_subscribe_packet, Packet>::value;
262}
263
264template <typename Packet>
265constexpr bool is_suback() {
266 return
267 is_instance_of<v3_1_1::basic_suback_packet, Packet>::value ||
268 is_instance_of<v5::basic_suback_packet, Packet>::value;
269}
270
271template <typename Packet>
272constexpr bool is_unsubscribe() {
273 return
274 is_instance_of<v3_1_1::basic_unsubscribe_packet, Packet>::value ||
275 is_instance_of<v5::basic_unsubscribe_packet, Packet>::value;
276}
277
278template <typename Packet>
279constexpr bool is_unsuback() {
280 return
281 is_instance_of<v3_1_1::basic_unsuback_packet, Packet>::value ||
282 is_instance_of<v5::basic_unsuback_packet, Packet>::value;
283}
284
285template <typename Packet>
286constexpr bool is_pingreq() {
287 return
288 std::is_same_v<v3_1_1::pingreq_packet, Packet> ||
289 std::is_same_v<v5::pingreq_packet, Packet>;
290}
291
292template <typename Packet>
293constexpr bool is_pingresp() {
294 return
295 std::is_same_v<v3_1_1::pingresp_packet, Packet> ||
296 std::is_same_v<v5::pingresp_packet, Packet>;
297}
298
299template <typename Packet>
300constexpr bool is_disconnect() {
301 return
302 std::is_same_v<v3_1_1::disconnect_packet, Packet> ||
303 std::is_same_v<v5::disconnect_packet, Packet>;
304}
305
306template <typename Packet>
307constexpr bool own_packet_id() {
308 return
309 is_publish<Packet>() ||
310 is_pubrel<Packet>() ||
311 is_subscribe<Packet>() ||
312 is_unsubscribe<Packet>();
313}
314
315} // namespace async_mqtt
316
317#endif // ASYNC_MQTT_PACKET_PACKET_TRAITS_HPP