7#if !defined(ASYNC_MQTT_PACKET_V3_1_1_CONNACK_HPP)
8#define ASYNC_MQTT_PACKET_V3_1_1_CONNACK_HPP
13#include <async_mqtt/exception.hpp>
14#include <async_mqtt/buffer.hpp>
16#include <async_mqtt/util/move.hpp>
17#include <async_mqtt/util/static_vector.hpp>
19#include <async_mqtt/packet/fixed_header.hpp>
20#include <async_mqtt/packet/session_present.hpp>
21#include <async_mqtt/packet/connect_return_code.hpp>
23namespace async_mqtt::v3_1_1 {
25namespace as = boost::asio;
48 static_cast<
char>(make_fixed_header(control_packet_type::connack, 0b0000)),
61 "v3_1_1::connack_packet fixed_header doesn't exist"
64 all_.push_back(buf.front());
66 auto cpt_opt = get_control_packet_type_with_check(
static_cast<std::uint8_t
>(all_.back()));
70 "v3_1_1::connack_packet fixed_header is invalid"
78 "v3_1_1::connack_packet remaining_length doesn't exist"
81 all_.push_back(buf.front());
83 if (
static_cast<std::uint8_t
>(all_.back()) != 0b00000010) {
86 "v3_1_1::connack_packet remaining_length is invalid"
91 if (buf.size() != 2) {
94 "v3_1_1::connack_packet variable header doesn't match its length"
97 all_.push_back(buf.front());
99 if ((
static_cast<std::uint8_t
>(all_.back()) & 0b11111110)!= 0) {
102 "v3_1_1::connack_packet connect acknowledge flags is invalid"
105 all_.push_back(buf.front());
106 if (
static_cast<std::uint8_t
>(all_.back()) > 5) {
109 "v3_1_1::connack_packet connect_return_code is invalid"
114 constexpr control_packet_type type()
const {
115 return control_packet_type::connack;
124 std::vector<as::const_buffer>
ret;
126 ret.emplace_back(as::buffer(all_.data(), all_.size()));
151 return is_session_present(all_[2]);
158 connect_return_code
code()
const {
159 return static_cast<connect_return_code
>(all_[3]);
166inline std::ostream&
operator<<(std::ostream&
o, connack_packet
const&
v) {
168 "v3_1_1::connack{" <<
169 "rc:" <<
v.code() <<
"," <<
170 "sp:" <<
v.session_present() <<
Definition packet_variant.hpp:49
buffer that has string_view interface This class provides string_view interface. This class hold stri...
Definition buffer.hpp:30
Definition v3_1_1_connack.hpp:33
static constexpr std::size_t num_of_const_buffer_sequence()
Get number of element of const_buffer_sequence.
Definition v3_1_1_connack.hpp:142
bool session_present() const
Get session_present.
Definition v3_1_1_connack.hpp:150
std::size_t size() const
Get packet size.
Definition v3_1_1_connack.hpp:134
connect_return_code code() const
Get connect_return_code.
Definition v3_1_1_connack.hpp:158
connack_packet(bool session_present, connect_return_code return_code)
Definition v3_1_1_connack.hpp:43
std::vector< as::const_buffer > const_buffer_sequence() const
Create const buffer sequence. it is for boost asio APIs.
Definition v3_1_1_connack.hpp:123