async_mqtt 9.0.1
Loading...
Searching...
No Matches
v5_auth.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_V5_AUTH_HPP)
8#define ASYNC_MQTT_PACKET_V5_AUTH_HPP
9
10#include <utility>
11#include <numeric>
12
13#include <async_mqtt/buffer_to_packet_variant.hpp>
14#include <async_mqtt/error.hpp>
15
16#include <async_mqtt/packet/control_packet_type.hpp>
17#include <async_mqtt/packet/property_variant.hpp>
18
19#include <async_mqtt/util/buffer.hpp>
20#include <async_mqtt/util/static_vector.hpp>
21
27namespace async_mqtt::v5 {
28
29namespace as = boost::asio;
30
48public:
49
57 explicit auth_packet(
58 auth_reason_code reason_code,
60 );
61
65 explicit auth_packet();
66
72 explicit auth_packet(
73 auth_reason_code reason_code
74 );
75
80 static constexpr control_packet_type type() {
82 }
83
89 std::vector<as::const_buffer> const_buffer_sequence() const;
90
95 std::size_t size() const;
96
101 std::size_t num_of_const_buffer_sequence() const;
102
108
113 properties const& props() const;
114
121 friend
122 std::ostream& operator<<(std::ostream& o, auth_packet const& v) {
123 o <<
124 "v5::auth{";
125 if (v.reason_code_) {
126 o << "rc:" << *v.reason_code_;
127 }
128 if (!v.props().empty()) {
129 o << ",ps:" << v.props();
130 };
131 o << "}";
132 return o;
133 }
134
135private:
136 explicit auth_packet(
137 std::optional<auth_reason_code> reason_code,
139 );
140
141private:
142
143 template <std::size_t PacketIdBytesArg>
146
147#if defined(ASYNC_MQTT_UNIT_TEST_FOR_PACKET)
148 friend struct ::ut_packet::v5_auth;
149 friend struct ::ut_packet::v5_auth_no_arg;
150 friend struct ::ut_packet::v5_auth_pid_rc;
151 friend struct ::ut_packet::v5_auth_prop_len_last;
152 friend struct ::ut_packet::v5_auth_error;
153#endif // defined(ASYNC_MQTT_UNIT_TEST_FOR_PACKET)
154
155 // private constructor for internal use
156 explicit auth_packet(buffer buf, error_code& ec);
157
158private:
159 std::uint8_t fixed_header_;
160 std::size_t remaining_length_;
161 static_vector<char, 4> remaining_length_buf_;
162
163 std::optional<auth_reason_code> reason_code_;
164
165 std::size_t property_length_ = 0;
166 static_vector<char, 4> property_length_buf_;
167 properties props_;
168};
169
182bool operator<(auth_packet const& lhs, auth_packet const& rhs);
183
196bool operator==(auth_packet const& lhs, auth_packet const& rhs);
197
198} // namespace async_mqtt::v5
199
200#if !defined(ASYNC_MQTT_SEPARATE_COMPILATION)
201#include <async_mqtt/packet/impl/v5_auth.ipp>
202#endif // !defined(ASYNC_MQTT_SEPARATE_COMPILATION)
203
204#endif // ASYNC_MQTT_PACKET_V5_AUTH_HPP
The varaint type of all packets and system_error.
Definition packet_variant_fwd.hpp:37
buffer that has string_view interface and shared ownership This class is only for advanced usecase su...
Definition buffer.hpp:46
MQTT AUTH packet (v5)
Definition v5_auth.hpp:47
std::size_t num_of_const_buffer_sequence() const
Get number of element of const_buffer_sequence.
std::size_t size() const
Get packet size.
bool operator==(auth_packet const &lhs, auth_packet const &rhs)
equal operator
properties const & props() const
Get properties.
auth_packet(auth_reason_code reason_code, properties props)
constructor
static constexpr control_packet_type type()
Get MQTT control packet type.
Definition v5_auth.hpp:80
auth_reason_code code() const
Get reason code.
friend std::ostream & operator<<(std::ostream &o, auth_packet const &v)
stream output operator
Definition v5_auth.hpp:122
auth_packet(auth_reason_code reason_code)
constructor
std::vector< as::const_buffer > const_buffer_sequence() const
Create const buffer sequence it is for boost asio APIs.
bool operator<(auth_packet const &lhs, auth_packet const &rhs)
less than operator
auth_reason_code
auth reason code It is reported via AUTH packet
Definition error.hpp:1030
sys::error_code error_code
sys is a namespace alias of boost::sytem.
Definition error.hpp:56
protocol_version
MQTT protocol version.
Definition protocol_version.hpp:29
basic_packet_variant< PacketIdBytes > buffer_to_basic_packet_variant(buffer buf, protocol_version ver, error_code &ec)
create basic_packet_variant from the buffer
control_packet_type
MQTT control packet type.
Definition control_packet_type.hpp:26
std::vector< property_variant > properties
property variant collection type
Definition property_variant.hpp:224