async_mqtt 9.0.1
Loading...
Searching...
No Matches
v5_disconnect.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_DISCONNECT_HPP)
8#define ASYNC_MQTT_PACKET_V5_DISCONNECT_HPP
9
10#include <async_mqtt/buffer_to_packet_variant.hpp>
11#include <async_mqtt/error.hpp>
12
13#include <async_mqtt/packet/control_packet_type.hpp>
14#include <async_mqtt/packet/property_variant.hpp>
15
16#include <async_mqtt/util/buffer.hpp>
17#include <async_mqtt/util/static_vector.hpp>
18
24namespace async_mqtt::v5 {
25
26namespace as = boost::asio;
27
51public:
61 disconnect_reason_code reason_code,
63 );
64
69 );
70
78 disconnect_reason_code reason_code
79 );
80
85 static constexpr control_packet_type type() {
87 }
88
94 std::vector<as::const_buffer> const_buffer_sequence() const;
95
100 std::size_t size() const;
101
106 std::size_t num_of_const_buffer_sequence() const;
107
113
118 properties const& props() const;
119
126 friend
127 std::ostream& operator<<(std::ostream& o, disconnect_packet const& v) {
128 o <<
129 "v5::disconnect{";
130 if (v.reason_code_) {
131 o << "rc:" << *v.reason_code_;
132 }
133 if (!v.props().empty()) {
134 o << ",ps:" << v.props();
135 };
136 o << "}";
137 return o;
138 }
139
140private:
141
142 template <std::size_t PacketIdBytesArg>
145
146#if defined(ASYNC_MQTT_UNIT_TEST_FOR_PACKET)
147 friend struct ::ut_packet::v5_disconnect;
148 friend struct ::ut_packet::v5_disconnect_no_arg;
149 friend struct ::ut_packet::v5_disconnect_pid_rc;
150 friend struct ::ut_packet::v5_disconnect_prop_len_last;
151 friend struct ::ut_packet::v5_disconnect_error;
152#endif // defined(ASYNC_MQTT_UNIT_TEST_FOR_PACKET)
153
154 // private constructor for internal use
155 explicit disconnect_packet(buffer buf, error_code& ec);
156
157 explicit disconnect_packet(
158 std::optional<disconnect_reason_code> reason_code,
160 );
161
162private:
163 std::uint8_t fixed_header_;
164 std::size_t remaining_length_;
165 static_vector<char, 4> remaining_length_buf_;
166
167 std::optional<disconnect_reason_code> reason_code_;
168
169 std::size_t property_length_ = 0;
170 static_vector<char, 4> property_length_buf_;
171 properties props_;
172};
173
186bool operator<(disconnect_packet const& lhs, disconnect_packet const& rhs);
187
200bool operator==(disconnect_packet const& lhs, disconnect_packet const& rhs);
201
202} // namespace async_mqtt::v5
203
204#if !defined(ASYNC_MQTT_SEPARATE_COMPILATION)
205#include <async_mqtt/packet/impl/v5_disconnect.ipp>
206#endif // !defined(ASYNC_MQTT_SEPARATE_COMPILATION)
207
208#endif // ASYNC_MQTT_PACKET_V5_DISCONNECT_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 DISCONNECT packet (v5)
Definition v5_disconnect.hpp:50
properties const & props() const
Get properties.
disconnect_reason_code code() const
Get reason code.
static constexpr control_packet_type type()
Get MQTT control packet type.
Definition v5_disconnect.hpp:85
std::size_t size() const
Get packet size.
disconnect_packet(disconnect_reason_code reason_code, properties props)
constructor
std::size_t num_of_const_buffer_sequence() const
Get number of element of const_buffer_sequence.
bool operator<(disconnect_packet const &lhs, disconnect_packet const &rhs)
less than operator
std::vector< as::const_buffer > const_buffer_sequence() const
Create const buffer sequence it is for boost asio APIs.
disconnect_packet(disconnect_reason_code reason_code)
constructor
bool operator==(disconnect_packet const &lhs, disconnect_packet const &rhs)
equal operator
friend std::ostream & operator<<(std::ostream &o, disconnect_packet const &v)
stream output operator
Definition v5_disconnect.hpp:127
disconnect_reason_code
disconnect reason code It is reported via DISCONNECT
Definition error.hpp:451
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