7#if !defined(ASYNC_MQTT_PACKET_PACKET_HELPER_HPP)
8#define ASYNC_MQTT_PACKET_PACKET_HELPER_HPP
12#include <async_mqtt/packet/packet_iterator.hpp>
13#include <async_mqtt/packet/packet_traits.hpp>
14#include <async_mqtt/packet/packet_variant.hpp>
18template <
typename Packet>
19constexpr bool is_packet() {
21 std::is_same_v<v3_1_1::connect_packet, Packet> ||
22 std::is_same_v<v3_1_1::connack_packet, Packet> ||
23 std::is_same_v<v3_1_1::pingreq_packet, Packet> ||
24 std::is_same_v<v3_1_1::pingresp_packet, Packet> ||
25 std::is_same_v<v3_1_1::disconnect_packet, Packet> ||
26 is_instance_of<v3_1_1::basic_publish_packet, Packet>::value ||
27 is_instance_of<v3_1_1::basic_puback_packet, Packet>::value ||
28 is_instance_of<v3_1_1::basic_pubrec_packet, Packet>::value ||
29 is_instance_of<v3_1_1::basic_pubrel_packet, Packet>::value ||
30 is_instance_of<v3_1_1::basic_pubcomp_packet, Packet>::value ||
31 is_instance_of<v3_1_1::basic_subscribe_packet, Packet>::value ||
32 is_instance_of<v3_1_1::basic_suback_packet, Packet>::value ||
33 is_instance_of<v3_1_1::basic_unsubscribe_packet, Packet>::value ||
34 is_instance_of<v3_1_1::basic_unsuback_packet, Packet>::value ||
35 std::is_same_v<v5::connect_packet, Packet> ||
36 std::is_same_v<v5::connack_packet, Packet> ||
37 std::is_same_v<v5::pingreq_packet, Packet> ||
38 std::is_same_v<v5::pingresp_packet, Packet> ||
39 std::is_same_v<v5::disconnect_packet, Packet> ||
40 is_instance_of<v5::basic_publish_packet, Packet>::value ||
41 is_instance_of<v5::basic_puback_packet, Packet>::value ||
42 is_instance_of<v5::basic_pubrec_packet, Packet>::value ||
43 is_instance_of<v5::basic_pubrel_packet, Packet>::value ||
44 is_instance_of<v5::basic_pubcomp_packet, Packet>::value ||
45 is_instance_of<v5::basic_subscribe_packet, Packet>::value ||
46 is_instance_of<v5::basic_suback_packet, Packet>::value ||
47 is_instance_of<v5::basic_unsubscribe_packet, Packet>::value ||
48 is_instance_of<v5::basic_unsuback_packet, Packet>::value ||
49 std::is_same_v<v5::auth_packet, Packet> ||
50 is_instance_of<basic_packet_variant, Packet>::value
54template<
class InputIt1,
class InputIt2>
55bool lexicographical_compare(
61 for (; (first1 != last1) && (first2 != last2); ++first1, ++first2) {
62 if (*first1 < *first2)
return true;
63 if (*first2 < *first1)
return false;
65 return (first1 == last1) && (first2 != last2);
68template <
typename Lhs,
typename Rhs>
69std::enable_if_t<is_packet<Lhs>() && is_packet<Rhs>(),
bool>
70operator==(Lhs
const& lhs, Rhs
const& rhs) {
72 auto [lb, le] = make_packet_range(lcbs);
73 auto rcbs = rhs.const_buffer_sequence();
74 auto [rb, re] = make_packet_range(rcbs);
75 if (std::distance(lb, le) != std::distance(rb, re))
return false;
76 return std::equal(lb, le, rb);
79template <
typename Lhs,
typename Rhs>
80std::enable_if_t<is_packet<Lhs>() && is_packet<Rhs>(),
bool>
81operator<(Lhs
const& lhs, Rhs
const& rhs) {
83 auto [lb, le] = make_packet_range(lcbs);
84 auto rcbs = rhs.const_buffer_sequence();
85 auto [rb, re] = make_packet_range(rcbs);
87 lexicographical_compare(
std::vector< as::const_buffer > const_buffer_sequence() const
Create const buffer sequence it is for boost asio APIs.
Definition packet_variant.hpp:166