46 using packet_id_t =
typename packet_id_type<PacketIdBytes>::type;
104 "v5::puback_packet fixed_header doesn't exist"
107 fixed_header_ =
static_cast<std::uint8_t
>(buf.front());
108 buf.remove_prefix(1);
111 if (
auto vl_opt = insert_advance_variable_length(buf, remaining_length_buf_)) {
112 remaining_length_ = *
vl_opt;
115 throw make_error(errc::bad_message,
"v5::puback_packet remaining length is invalid");
119 if (!insert_advance(buf, packet_id_)) {
122 "v5::puback_packet packet_id doesn't exist"
126 if (remaining_length_ == PacketIdBytes) {
128 throw make_error(errc::bad_message,
"v5::puback_packet remaining length is invalid");
134 reason_code_.emplace(
static_cast<puback_reason_code
>(buf.front()));
135 buf.remove_prefix(1);
136 switch (*reason_code_) {
137 case puback_reason_code::success:
138 case puback_reason_code::no_matching_subscribers:
139 case puback_reason_code::unspecified_error:
140 case puback_reason_code::implementation_specific_error:
141 case puback_reason_code::not_authorized:
142 case puback_reason_code::topic_name_invalid:
143 case puback_reason_code::packet_identifier_in_use:
144 case puback_reason_code::quota_exceeded:
145 case puback_reason_code::payload_format_invalid:
150 "v5::puback_packet connect reason_code is invalid"
155 if (remaining_length_ == 3) {
157 throw make_error(errc::bad_message,
"v5::puback_packet remaining length is invalid");
163 auto it = buf.begin();
164 if (
auto pl_opt = variable_bytes_to_val(it, buf.end())) {
165 property_length_ = *pl_opt;
166 std::copy(buf.begin(), it, std::back_inserter(property_length_buf_));
167 buf.remove_prefix(std::size_t(std::distance(buf.begin(), it)));
168 if (buf.size() < property_length_) {
171 "v5::puback_packet properties_don't match its length"
174 auto prop_buf = buf.
substr(0, property_length_);
175 props_ = make_properties(prop_buf, property_location::puback);
176 buf.remove_prefix(property_length_);
181 "v5::puback_packet property_length is invalid"
188 "v5::puback_packet properties don't match its length"
193 constexpr control_packet_type type()
const {
194 return control_packet_type::puback;
203 std::vector<as::const_buffer>
ret;
205 ret.emplace_back(as::buffer(&fixed_header_, 1));
206 ret.emplace_back(as::buffer(remaining_length_buf_.data(), remaining_length_buf_.size()));
208 ret.emplace_back(as::buffer(packet_id_.data(), packet_id_.size()));
211 ret.emplace_back(as::buffer(&*reason_code_, 1));
212 if (property_length_buf_.size() != 0) {
213 ret.emplace_back(as::buffer(property_length_buf_.data(), property_length_buf_.size()));
214 auto props_cbs = async_mqtt::const_buffer_sequence(props_);
229 remaining_length_buf_.size() +
242 [&] () -> std::size_t {
246 [&] () -> std::size_t {
247 if (property_length_buf_.size() == 0)
return 0;
250 async_mqtt::num_of_const_buffer_sequence(props_);
269 puback_reason_code
code()
const {
270 if (reason_code_)
return *reason_code_;
271 return puback_reason_code::success;
286 "pid:" <<
v.packet_id();
287 if (
v.reason_code_) {
288 o <<
",rc:" << *
v.reason_code_;
290 if (!
v.props().empty()) {
291 o <<
",ps:" <<
v.props();
300 optional<puback_reason_code> reason_code,
304 make_fixed_header(control_packet_type::puback, 0b0000)
309 packet_id_(packet_id_.capacity()),
310 reason_code_{reason_code},
311 property_length_(async_mqtt::
size(
props)),
312 props_(force_move(
props))
314 using namespace std::literals;
315 endian_store(
packet_id, packet_id_.data());
317 auto guard = unique_scope_guard(
319 auto rb = val_to_variable_bytes(boost::numeric_cast<std::uint32_t>(remaining_length_));
321 remaining_length_buf_.push_back(e);
326 if (!reason_code_)
return;
327 remaining_length_ += 1;
329 if (property_length_ == 0)
return;
331 auto pb = val_to_variable_bytes(boost::numeric_cast<std::uint32_t>(property_length_));
333 property_length_buf_.push_back(e);
336 for (
auto const& prop : props_) {
338 if (!validate_property(property_location::puback,
id)) {
341 "v5::puback_packet property "s + id_to_str(
id) +
" is not allowed"
346 remaining_length_ += property_length_buf_.size() + property_length_;
350 std::uint8_t fixed_header_;
351 std::size_t remaining_length_;
352 static_vector<char, 4> remaining_length_buf_;
353 static_vector<char, PacketIdBytes> packet_id_;
355 optional<puback_reason_code> reason_code_;
357 std::size_t property_length_ = 0;
358 static_vector<char, 4> property_length_buf_;