40 using packet_id_t =
typename packet_id_type<PacketIdBytes>::type;
50 std::vector<topic_sharename>
params
52 : fixed_header_{make_fixed_header(control_packet_type::unsubscribe, 0b0010)},
53 entries_{force_move(
params)},
56 topic_length_buf_entries_.reserve(entries_.size());
57 for (
auto const&
e : entries_) {
58 topic_length_buf_entries_.push_back(
60 boost::numeric_cast<std::uint16_t>(
e.all_topic().size())
65 endian_store(
packet_id, packet_id_.data());
68 for (
auto const&
e : entries_) {
69 auto size =
e.all_topic().size();
73 "v3_1_1::unsubscribe_packet length of topic is invalid"
80 if (!utf8string_check(
e.all_topic())) {
83 "v3_1_1::unsubscribe_packet topic filter invalid utf8"
88 remaining_length_buf_ = val_to_variable_bytes(boost::numeric_cast<std::uint32_t>(remaining_length_));
96 "v3_1_1::unsubscribe_packet fixed_header doesn't exist"
99 fixed_header_ =
static_cast<std::uint8_t
>(buf.front());
100 buf.remove_prefix(1);
101 auto cpt_opt = get_control_packet_type_with_check(
static_cast<std::uint8_t
>(fixed_header_));
105 "v3_1_1::unsubscribe_packet fixed_header is invalid"
110 if (
auto vl_opt = insert_advance_variable_length(buf, remaining_length_buf_)) {
111 remaining_length_ = *vl_opt;
114 throw make_error(errc::bad_message,
"v3_1_1::unsubscribe_packet remaining length is invalid");
116 if (remaining_length_ != buf.size()) {
117 throw make_error(errc::bad_message,
"v3_1_1::unsubscribe_packet remaining length doesn't match buf.size()");
121 if (!copy_advance(buf, packet_id_)) {
124 "v3_1_1::unsubscribe_packet packet_id doesn't exist"
128 if (remaining_length_ == 0) {
129 throw make_error(errc::bad_message,
"v3_1_1::unsubscribe_packet doesn't have entries");
132 while (!buf.empty()) {
134 static_vector<char, 2> topic_length_buf;
135 if (!insert_advance(buf, topic_length_buf)) {
138 "v3_1_1::unsubscribe_packet length of topic is invalid"
141 auto topic_length = endian_load<std::uint16_t>(topic_length_buf.data());
142 topic_length_buf_entries_.push_back(topic_length_buf);
145 if (buf.size() < topic_length) {
148 "v3_1_1::unsubscribe_packet topic doesn't match its length"
151 auto topic = buf.
substr(0, topic_length);
152 if (!utf8string_check(topic)) {
155 "v3_1_1::unsubscribe_packet topic filter invalid utf8"
158 entries_.emplace_back(force_move(topic));
159 buf.remove_prefix(topic_length);
163 constexpr control_packet_type type()
const {
164 return control_packet_type::unsubscribe;
173 std::vector<as::const_buffer>
ret;
176 ret.emplace_back(as::buffer(&fixed_header_, 1));
178 ret.emplace_back(as::buffer(remaining_length_buf_.data(), remaining_length_buf_.size()));
180 ret.emplace_back(as::buffer(packet_id_.data(), packet_id_.size()));
182 BOOST_ASSERT(entries_.size() == topic_length_buf_entries_.size());
183 auto it = topic_length_buf_entries_.begin();
184 for (
auto const&
e : entries_) {
185 ret.emplace_back(as::buffer(
it->data(),
it->size()));
186 ret.emplace_back(as::buffer(
e.all_topic()));
200 remaining_length_buf_.size() +
228 std::vector<topic_sharename>
const&
entries()
const {
233 std::uint8_t fixed_header_;
234 std::vector<static_vector<char, 2>> topic_length_buf_entries_;
235 std::vector<topic_sharename> entries_;
237 std::size_t remaining_length_;
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