47 using packet_id_t =
typename packet_id_type<PacketIdBytes>::type;
102 "v5::pubrel_packet fixed_header doesn't exist"
105 fixed_header_ =
static_cast<std::uint8_t
>(buf.front());
106 buf.remove_prefix(1);
109 if (
auto vl_opt = insert_advance_variable_length(buf, remaining_length_buf_)) {
110 remaining_length_ = *
vl_opt;
113 throw make_error(errc::bad_message,
"v5::pubrel_packet remaining length is invalid");
117 if (!insert_advance(buf, packet_id_)) {
120 "v5::pubrel_packet packet_id doesn't exist"
124 if (remaining_length_ == PacketIdBytes) {
126 throw make_error(errc::bad_message,
"v5::pubrel_packet remaining length is invalid");
132 reason_code_.emplace(
static_cast<pubrel_reason_code
>(buf.front()));
133 buf.remove_prefix(1);
134 switch (*reason_code_) {
135 case pubrel_reason_code::success:
136 case pubrel_reason_code::packet_identifier_not_found:
141 "v5::pubrel_packet connect reason_code is invalid"
146 if (remaining_length_ == 3) {
148 throw make_error(errc::bad_message,
"v5::pubrel_packet remaining length is invalid");
154 auto it = buf.begin();
155 if (
auto pl_opt = variable_bytes_to_val(it, buf.end())) {
156 property_length_ = *pl_opt;
157 std::copy(buf.begin(), it, std::back_inserter(property_length_buf_));
158 buf.remove_prefix(std::size_t(std::distance(buf.begin(), it)));
159 if (buf.size() < property_length_) {
162 "v5::pubrel_packet properties don't match its length"
165 auto prop_buf = buf.
substr(0, property_length_);
166 props_ = make_properties(prop_buf, property_location::pubrel);
167 buf.remove_prefix(property_length_);
172 "v5::pubrel_packet property_length is invalid"
179 "v5::pubrel_packet properties don't match its length"
184 constexpr control_packet_type type()
const {
185 return control_packet_type::pubrel;
194 std::vector<as::const_buffer>
ret;
196 ret.emplace_back(as::buffer(&fixed_header_, 1));
197 ret.emplace_back(as::buffer(remaining_length_buf_.data(), remaining_length_buf_.size()));
199 ret.emplace_back(as::buffer(packet_id_.data(), packet_id_.size()));
202 ret.emplace_back(as::buffer(&*reason_code_, 1));
204 if (property_length_buf_.size() != 0) {
205 ret.emplace_back(as::buffer(property_length_buf_.data(), property_length_buf_.size()));
206 auto props_cbs = async_mqtt::const_buffer_sequence(props_);
221 remaining_length_buf_.size() +
234 [&] () -> std::size_t {
238 [&] () -> std::size_t {
239 if (property_length_buf_.size() == 0)
return 0;
242 async_mqtt::num_of_const_buffer_sequence(props_);
261 pubrel_reason_code
code()
const {
262 if (reason_code_)
return *reason_code_;
263 return pubrel_reason_code::success;
278 "pid:" <<
v.packet_id();
279 if (
v.reason_code_) {
280 o <<
",rc:" << *
v.reason_code_;
282 if (!
v.props().empty()) {
283 o <<
",ps:" <<
v.props();
292 optional<pubrel_reason_code> reason_code,
296 make_fixed_header(control_packet_type::pubrel, 0b0010)
301 packet_id_(packet_id_.capacity()),
302 reason_code_{reason_code},
303 property_length_(async_mqtt::
size(
props)),
304 props_(force_move(
props))
306 using namespace std::literals;
307 endian_store(
packet_id, packet_id_.data());
309 auto guard = unique_scope_guard(
311 auto rb = val_to_variable_bytes(boost::numeric_cast<std::uint32_t>(remaining_length_));
313 remaining_length_buf_.push_back(e);
318 if (!reason_code_)
return;
319 remaining_length_ += 1;
321 if (property_length_ == 0)
return;
323 auto pb = val_to_variable_bytes(boost::numeric_cast<std::uint32_t>(property_length_));
325 property_length_buf_.push_back(e);
328 for (
auto const& prop : props_) {
330 if (!validate_property(property_location::pubrel,
id)) {
333 "v5::pubrel_packet property "s + id_to_str(
id) +
" is not allowed"
338 remaining_length_ += property_length_buf_.size() + property_length_;
342 std::uint8_t fixed_header_;
343 std::size_t remaining_length_;
344 static_vector<char, 4> remaining_length_buf_;
345 static_vector<char, PacketIdBytes> packet_id_;
347 optional<pubrel_reason_code> reason_code_;
349 std::size_t property_length_ = 0;
350 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