async_mqtt 9.0.1
Loading...
Searching...
No Matches
v5_connect.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_CONNECT_HPP)
8#define ASYNC_MQTT_PACKET_V5_CONNECT_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/will.hpp>
18#include <async_mqtt/packet/property_variant.hpp>
19
20#include <async_mqtt/util/buffer.hpp>
21#include <async_mqtt/util/variable_bytes.hpp>
22#include <async_mqtt/util/static_vector.hpp>
23
29namespace async_mqtt::v5 {
30
31namespace as = boost::asio;
32
50public:
80 bool clean_start,
81 std::uint16_t keep_alive_sec,
82 std::string client_id,
83 std::optional<std::string> user_name = std::nullopt,
84 std::optional<std::string> password = std::nullopt,
85 properties props = {}
86 );
87
119 bool clean_start,
120 std::uint16_t keep_alive_sec,
121 std::string client_id,
122 std::optional<will> w,
123 std::optional<std::string> user_name = std::nullopt,
124 std::optional<std::string> password = std::nullopt,
125 properties props = {}
126 );
127
132 static constexpr control_packet_type type() {
134 }
135
141 std::vector<as::const_buffer> const_buffer_sequence() const;
142
147 std::size_t size() const;
148
153 std::size_t num_of_const_buffer_sequence() const;
154
159 bool clean_start() const;
160
165 std::uint16_t keep_alive() const;
166
171 std::string client_id() const;
172
177 std::optional<std::string> user_name() const;
178
183 std::optional<std::string> password() const;
184
189 std::optional<will> get_will() const;
190
195 properties const& props() const;
196
197private:
198
199 template <std::size_t PacketIdBytesArg>
202
203#if defined(ASYNC_MQTT_UNIT_TEST_FOR_PACKET)
204 friend struct ::ut_packet::v5_connect;
205 friend struct ::ut_packet::v5_connect_error;
206#endif // defined(ASYNC_MQTT_UNIT_TEST_FOR_PACKET)
207
208 // private constructor for internal use
209 explicit connect_packet(buffer buf, error_code& ec);
210
211private:
212 std::uint8_t fixed_header_;
213 char connect_flags_;
214
215 std::size_t remaining_length_;
216 static_vector<char, 4> remaining_length_buf_;
217
218 static_vector<char, 7> protocol_name_and_level_;
219 buffer client_id_;
220 static_vector<char, 2> client_id_length_buf_;
221
222 buffer will_topic_;
223 static_vector<char, 2> will_topic_length_buf_;
224 buffer will_message_;
225 static_vector<char, 2> will_message_length_buf_;
226 std::size_t will_property_length_;
227 static_vector<char, 4> will_property_length_buf_;
228 properties will_props_;
229
230 buffer user_name_;
231 static_vector<char, 2> user_name_length_buf_;
232 buffer password_;
233 static_vector<char, 2> password_length_buf_;
234
235 static_vector<char, 2> keep_alive_buf_;
236
237 std::size_t property_length_;
238 static_vector<char, 4> property_length_buf_;
239 properties props_;
240};
241
254bool operator<(connect_packet const& lhs, connect_packet const& rhs);
255
268bool operator==(connect_packet const& lhs, connect_packet const& rhs);
269
282std::ostream& operator<<(std::ostream& o, connect_packet const& v);
283
284} // namespace async_mqtt::v5
285
286#if !defined(ASYNC_MQTT_SEPARATE_COMPILATION)
287#include <async_mqtt/packet/impl/v5_connect.ipp>
288#endif // !defined(ASYNC_MQTT_SEPARATE_COMPILATION)
289
290#endif // ASYNC_MQTT_PACKET_V5_CONNECT_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 CONNECT packet (v5)
Definition v5_connect.hpp:49
bool operator<(connect_packet const &lhs, connect_packet const &rhs)
less than operator
connect_packet(bool clean_start, std::uint16_t keep_alive_sec, std::string client_id, std::optional< std::string > user_name=std::nullopt, std::optional< std::string > password=std::nullopt, properties props={})
constructor
connect_packet(bool clean_start, std::uint16_t keep_alive_sec, std::string client_id, std::optional< will > w, std::optional< std::string > user_name=std::nullopt, std::optional< std::string > password=std::nullopt, properties props={})
constructor
std::size_t size() const
Get packet size.
properties const & props() const
Get properties.
std::optional< std::string > user_name() const
Get user_name.
std::uint16_t keep_alive() const
Get keep_alive.
std::vector< as::const_buffer > const_buffer_sequence() const
Create const buffer sequence it is for boost asio APIs.
bool clean_start() const
Get clean_start.
bool operator==(connect_packet const &lhs, connect_packet const &rhs)
equal operator
std::ostream & operator<<(std::ostream &o, connect_packet const &v)
stream output operator
std::string client_id() const
Get client_id.
std::optional< will > get_will() const
Get will.
static constexpr control_packet_type type()
Get MQTT control packet type.
Definition v5_connect.hpp:132
std::size_t num_of_const_buffer_sequence() const
Get number of element of const_buffer_sequence.
std::optional< std::string > password() const
Get password.
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