38 using packet_id_t =
typename packet_id_type<PacketIdBytes>::type;
49 std::vector<suback_reason_code>
params,
52 : fixed_header_{make_fixed_header(control_packet_type::suback, 0b0000)},
53 entries_{force_move(
params)},
55 property_length_(async_mqtt::
size(
props)),
56 props_(force_move(
props))
58 using namespace std::literals;
59 endian_store(
packet_id, packet_id_.data());
61 auto pb = val_to_variable_bytes(boost::numeric_cast<std::uint32_t>(property_length_));
63 property_length_buf_.push_back(
e);
66 for (
auto const&
prop : props_) {
68 if (!validate_property(property_location::suback,
id)) {
71 "v5::suback_packet property "s + id_to_str(
id) +
" is not allowed"
76 remaining_length_ += property_length_buf_.size() + property_length_;
77 remaining_length_buf_ = val_to_variable_bytes(boost::numeric_cast<std::uint32_t>(remaining_length_));
85 "v5::suback_packet fixed_header doesn't exist"
88 fixed_header_ =
static_cast<std::uint8_t
>(buf.front());
90 auto cpt_opt = get_control_packet_type_with_check(
static_cast<std::uint8_t
>(fixed_header_));
91 if (!cpt_opt || *cpt_opt != control_packet_type::suback) {
94 "v5::suback_packet fixed_header is invalid"
99 if (
auto vl_opt = insert_advance_variable_length(buf, remaining_length_buf_)) {
100 remaining_length_ = *vl_opt;
103 throw make_error(errc::bad_message,
"v5::suback_packet remaining length is invalid");
105 if (remaining_length_ != buf.size()) {
106 throw make_error(errc::bad_message,
"v5::suback_packet remaining length doesn't match buf.size()");
110 if (!copy_advance(buf, packet_id_)) {
113 "v5::suback_packet packet_id doesn't exist"
118 auto it = buf.begin();
119 if (
auto pl_opt = variable_bytes_to_val(it, buf.end())) {
120 property_length_ = *pl_opt;
121 std::copy(buf.begin(), it, std::back_inserter(property_length_buf_));
122 buf.remove_prefix(std::size_t(std::distance(buf.begin(), it)));
123 if (buf.size() < property_length_) {
126 "v5::suback_packet properties_don't match its length"
129 auto prop_buf = buf.substr(0, property_length_);
130 props_ = make_properties(prop_buf, property_location::suback);
131 buf.remove_prefix(property_length_);
136 "v5::suback_packet property_length is invalid"
140 if (remaining_length_ == 0) {
141 throw make_error(errc::bad_message,
"v5::suback_packet doesn't have entries");
144 while (!buf.empty()) {
149 "v5::suback_packet suback_reason_code doesn't exist"
152 auto rc =
static_cast<suback_reason_code
>(buf.front());
153 entries_.emplace_back(rc);
154 buf.remove_prefix(1);
158 constexpr control_packet_type type()
const {
159 return control_packet_type::suback;
168 std::vector<as::const_buffer>
ret;
171 ret.emplace_back(as::buffer(&fixed_header_, 1));
173 ret.emplace_back(as::buffer(remaining_length_buf_.data(), remaining_length_buf_.size()));
175 ret.emplace_back(as::buffer(packet_id_.data(), packet_id_.size()));
177 ret.emplace_back(as::buffer(property_length_buf_.data(), property_length_buf_.size()));
178 auto props_cbs = async_mqtt::const_buffer_sequence(props_);
181 ret.emplace_back(as::buffer(entries_.data(), entries_.size()));
193 remaining_length_buf_.size() +
206 [&] () -> std::size_t {
207 if (property_length_buf_.size() == 0)
return 0;
210 async_mqtt::num_of_const_buffer_sequence(props_);
227 std::vector<suback_reason_code>
const&
entries()
const {
240 std::uint8_t fixed_header_;
241 std::vector<suback_reason_code> entries_;
243 std::size_t remaining_length_;
246 std::size_t property_length_ = 0;