46 using packet_id_t =
typename packet_id_type<PacketIdBytes>::type;
101 "v5::pubcomp_packet fixed_header doesn't exist"
104 fixed_header_ =
static_cast<std::uint8_t
>(buf.front());
105 buf.remove_prefix(1);
108 if (
auto vl_opt = insert_advance_variable_length(buf, remaining_length_buf_)) {
109 remaining_length_ = *
vl_opt;
112 throw make_error(errc::bad_message,
"v5::pubcomp_packet remaining length is invalid");
116 if (!insert_advance(buf, packet_id_)) {
119 "v5::pubcomp_packet packet_id doesn't exist"
123 if (remaining_length_ == PacketIdBytes) {
125 throw make_error(errc::bad_message,
"v5::pubcomp_packet remaining length is invalid");
131 reason_code_.emplace(
static_cast<pubcomp_reason_code
>(buf.front()));
132 buf.remove_prefix(1);
133 switch (*reason_code_) {
134 case pubcomp_reason_code::success:
135 case pubcomp_reason_code::packet_identifier_not_found:
140 "v5::pubcomp_packet connect reason_code is invalid"
145 if (remaining_length_ == 3) {
147 throw make_error(errc::bad_message,
"v5::pubcomp_packet remaining length is invalid");
153 auto it = buf.begin();
154 if (
auto pl_opt = variable_bytes_to_val(it, buf.end())) {
155 property_length_ = *pl_opt;
156 std::copy(buf.begin(), it, std::back_inserter(property_length_buf_));
157 buf.remove_prefix(std::size_t(std::distance(buf.begin(), it)));
158 if (buf.size() < property_length_) {
161 "v5::pubcomp_packet properties_don't match its length"
164 auto prop_buf = buf.
substr(0, property_length_);
165 props_ = make_properties(prop_buf, property_location::pubcomp);
166 buf.remove_prefix(property_length_);
171 "v5::pubcomp_packet property_length is invalid"
178 "v5::pubcomp_packet properties don't match its length"
183 constexpr control_packet_type type()
const {
184 return control_packet_type::pubcomp;
193 std::vector<as::const_buffer>
ret;
195 ret.emplace_back(as::buffer(&fixed_header_, 1));
196 ret.emplace_back(as::buffer(remaining_length_buf_.data(), remaining_length_buf_.size()));
198 ret.emplace_back(as::buffer(packet_id_.data(), packet_id_.size()));
201 ret.emplace_back(as::buffer(&*reason_code_, 1));
203 if (property_length_buf_.size() != 0) {
204 ret.emplace_back(as::buffer(property_length_buf_.data(), property_length_buf_.size()));
205 auto props_cbs = async_mqtt::const_buffer_sequence(props_);
220 remaining_length_buf_.size() +
233 [&] () -> std::size_t {
237 [&] () -> std::size_t {
238 if (property_length_buf_.size() == 0)
return 0;
241 async_mqtt::num_of_const_buffer_sequence(props_);
260 pubcomp_reason_code
code()
const {
261 if (reason_code_)
return *reason_code_;
262 return pubcomp_reason_code::success;
277 "pid:" <<
v.packet_id();
278 if (
v.reason_code_) {
279 o <<
",rc:" << *
v.reason_code_;
281 if (!
v.props().empty()) {
282 o <<
",ps:" <<
v.props();
291 optional<pubcomp_reason_code> reason_code,
295 make_fixed_header(control_packet_type::pubcomp, 0b0000)
300 packet_id_(packet_id_.capacity()),
301 reason_code_{reason_code},
302 property_length_(async_mqtt::
size(
props)),
303 props_(force_move(
props))
305 using namespace std::literals;
306 endian_store(
packet_id, packet_id_.data());
308 auto guard = unique_scope_guard(
310 auto rb = val_to_variable_bytes(boost::numeric_cast<std::uint32_t>(remaining_length_));
312 remaining_length_buf_.push_back(e);
317 if (!reason_code_)
return;
318 remaining_length_ += 1;
320 if (property_length_ == 0)
return;
322 auto pb = val_to_variable_bytes(boost::numeric_cast<std::uint32_t>(property_length_));
324 property_length_buf_.push_back(e);
327 for (
auto const& prop : props_) {
329 if (!validate_property(property_location::pubcomp,
id)) {
332 "v5::pubcomp_packet property "s + id_to_str(
id) +
" is not allowed"
337 remaining_length_ += property_length_buf_.size() + property_length_;
341 std::uint8_t fixed_header_;
342 std::size_t remaining_length_;
343 static_vector<char, 4> remaining_length_buf_;
344 static_vector<char, PacketIdBytes> packet_id_;
346 optional<pubcomp_reason_code> reason_code_;
348 std::size_t property_length_ = 0;
349 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