86 "v5::auth_packet fixed_header doesn't exist"
89 fixed_header_ =
static_cast<std::uint8_t
>(buf.front());
93 if (
auto vl_opt = insert_advance_variable_length(buf, remaining_length_buf_)) {
94 remaining_length_ = *
vl_opt;
97 throw make_error(errc::bad_message,
"v5::auth_packet remaining length is invalid");
100 if (remaining_length_ == 0) {
102 throw make_error(errc::bad_message,
"v5::auth_packet remaining length is invalid");
108 reason_code_.emplace(
static_cast<auth_reason_code
>(buf.front()));
109 buf.remove_prefix(1);
110 switch (*reason_code_) {
111 case auth_reason_code::success:
112 case auth_reason_code::continue_authentication:
113 case auth_reason_code::re_authenticate:
118 "v5::auth_packet connect reason_code is invalid"
123 if (remaining_length_ == 1) {
125 throw make_error(errc::bad_message,
"v5::auth_packet remaining length is invalid");
131 auto it = buf.begin();
132 if (
auto pl_opt = variable_bytes_to_val(it, buf.end())) {
133 property_length_ = *pl_opt;
134 std::copy(buf.begin(), it, std::back_inserter(property_length_buf_));
135 buf.remove_prefix(std::size_t(std::distance(buf.begin(), it)));
136 if (buf.size() < property_length_) {
139 "v5::auth_packet properties_don't match its length"
142 auto prop_buf = buf.
substr(0, property_length_);
143 props_ = make_properties(prop_buf, property_location::auth);
144 buf.remove_prefix(property_length_);
149 "v5::auth_packet property_length is invalid"
156 "v5::auth_packet properties don't match its length"
161 constexpr control_packet_type type()
const {
162 return control_packet_type::auth;
171 std::vector<as::const_buffer>
ret;
173 ret.emplace_back(as::buffer(&fixed_header_, 1));
174 ret.emplace_back(as::buffer(remaining_length_buf_.data(), remaining_length_buf_.size()));
177 ret.emplace_back(as::buffer(&*reason_code_, 1));
179 if (property_length_buf_.size() != 0) {
180 ret.emplace_back(as::buffer(property_length_buf_.data(), property_length_buf_.size()));
181 auto props_cbs = async_mqtt::const_buffer_sequence(props_);
196 remaining_length_buf_.size() +
208 [&] () -> std::size_t {
212 [&] () -> std::size_t {
213 if (property_length_buf_.size() == 0)
return 0;
216 async_mqtt::num_of_const_buffer_sequence(props_);
227 auth_reason_code
code()
const {
228 if (reason_code_)
return *reason_code_;
229 return auth_reason_code::success;
244 if (
v.reason_code_) {
245 o <<
"rc:" << *
v.reason_code_;
247 if (!
v.props().empty()) {
248 o <<
",ps:" <<
v.props();
256 optional<auth_reason_code> reason_code,
260 make_fixed_header(control_packet_type::auth, 0b0000)
265 reason_code_{reason_code},
266 property_length_(async_mqtt::
size(
props)),
267 props_(force_move(
props))
269 using namespace std::literals;
271 auto guard = unique_scope_guard(
273 auto rb = val_to_variable_bytes(boost::numeric_cast<std::uint32_t>(remaining_length_));
275 remaining_length_buf_.push_back(e);
280 if (!reason_code_)
return;
281 remaining_length_ += 1;
283 if (property_length_ == 0)
return;
285 auto pb = val_to_variable_bytes(boost::numeric_cast<std::uint32_t>(property_length_));
287 property_length_buf_.push_back(e);
290 for (
auto const& prop : props_) {
292 if (!validate_property(property_location::auth,
id)) {
295 "v5::auth_packet property "s + id_to_str(
id) +
" is not allowed"
300 remaining_length_ += property_length_buf_.size() + property_length_;
304 std::uint8_t fixed_header_;
305 std::size_t remaining_length_;
306 static_vector<char, 4> remaining_length_buf_;
308 optional<auth_reason_code> reason_code_;
310 std::size_t property_length_ = 0;
311 static_vector<char, 4> property_length_buf_;
buffer substr(size_type pos=0, size_type count=npos) const &
get substring The returned buffer ragnge is the same as string_view::substr(). In addition the lifeti...
Definition buffer.hpp:201