async_mqtt 9.0.1
Loading...
Searching...
No Matches
v3_1_1_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_V3_1_1_CONNECT_HPP)
8#define ASYNC_MQTT_PACKET_V3_1_1_CONNECT_HPP
9
10#include <async_mqtt/buffer_to_packet_variant.hpp>
11#include <async_mqtt/util/buffer.hpp>
12
13#include <async_mqtt/util/static_vector.hpp>
14
15#include <async_mqtt/packet/control_packet_type.hpp>
16#include <async_mqtt/packet/will.hpp>
17
23namespace async_mqtt::v3_1_1 {
24
25namespace as = boost::asio;
26
43public:
71 bool clean_session,
72 std::uint16_t keep_alive_sec,
73 std::string client_id,
74 std::optional<std::string> user_name = std::nullopt,
75 std::optional<std::string> password = std::nullopt
76 );
77
107 bool clean_session,
108 std::uint16_t keep_alive_sec,
109 std::string client_id,
110 std::optional<will> w,
111 std::optional<std::string> user_name = std::nullopt,
112 std::optional<std::string> password = std::nullopt
113 );
114
119 static constexpr control_packet_type type() {
121 }
122
128 std::vector<as::const_buffer> const_buffer_sequence() const;
129
134 std::size_t size() const;
135
140 std::size_t num_of_const_buffer_sequence() const;
141
146 bool clean_session() const;
147
152 std::uint16_t keep_alive() const;
153
158 std::string client_id() const;
159
164 std::optional<std::string> user_name() const;
165
170 std::optional<std::string> password() const;
171
176 std::optional<will> get_will() const;
177
178private:
179
180 template <std::size_t PacketIdBytesArg>
183
184#if defined(ASYNC_MQTT_UNIT_TEST_FOR_PACKET)
185 friend struct ::ut_packet::v311_connect;
186 friend struct ::ut_packet::v311_connect_error;
187#endif // defined(ASYNC_MQTT_UNIT_TEST_FOR_PACKET)
188
189 // private constructor for internal use
190 explicit connect_packet(buffer buf, error_code& ec);
191
192private:
193 std::uint8_t fixed_header_;
194 char connect_flags_;
195
196 std::size_t remaining_length_;
197 static_vector<char, 4> remaining_length_buf_;
198
199 static_vector<char, 7> protocol_name_and_level_;
200 buffer client_id_;
201 static_vector<char, 2> client_id_length_buf_;
202
203 buffer will_topic_;
204 static_vector<char, 2> will_topic_length_buf_;
205 buffer will_message_;
206 static_vector<char, 2> will_message_length_buf_;
207
208 buffer user_name_;
209 static_vector<char, 2> user_name_length_buf_;
210 buffer password_;
211 static_vector<char, 2> password_length_buf_;
212
213 static_vector<char, 2> keep_alive_buf_;
214};
215
227bool operator<(connect_packet const& lhs, connect_packet const& rhs);
228
240bool operator==(connect_packet const& lhs, connect_packet const& rhs);
241
253std::ostream& operator<<(std::ostream& o, connect_packet const& v);
254
255} // namespace async_mqtt::v3_1_1
256
257#if !defined(ASYNC_MQTT_SEPARATE_COMPILATION)
258#include <async_mqtt/packet/impl/v3_1_1_connect.ipp>
259#endif // !defined(ASYNC_MQTT_SEPARATE_COMPILATION)
260
261#endif // ASYNC_MQTT_PACKET_V3_1_1_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 (v3.1.1)
Definition v3_1_1_connect.hpp:42
std::optional< std::string > password() const
Get password.
bool operator<(connect_packet const &lhs, connect_packet const &rhs)
less than operator
static constexpr control_packet_type type()
Get MQTT control packet type.
Definition v3_1_1_connect.hpp:119
std::size_t size() const
Get packet size.
std::optional< will > get_will() const
Get will.
std::string client_id() const
Get client_id.
std::vector< as::const_buffer > const_buffer_sequence() const
Create const buffer sequence it is for boost asio APIs.
bool clean_session() const
Get clean_session.
bool operator==(connect_packet const &lhs, connect_packet const &rhs)
equal operator
connect_packet(bool clean_session, 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)
constructor
std::uint16_t keep_alive() const
Get keep_alive.
std::optional< std::string > user_name() const
Get user_name.
std::size_t num_of_const_buffer_sequence() const
Get number of element of const_buffer_sequence.
std::ostream & operator<<(std::ostream &o, connect_packet const &v)
stream output operator
connect_packet(bool clean_session, 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)
constructor
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