7#if !defined(ASYNC_MQTT_PACKET_COPY_TO_STATIC_VECTOR_HPP)
8#define ASYNC_MQTT_PACKET_COPY_TO_STATIC_VECTOR_HPP
12#include <async_mqtt/util/static_vector.hpp>
13#include <async_mqtt/util/optional.hpp>
14#include <async_mqtt/buffer.hpp>
15#include <async_mqtt/exception.hpp>
16#include <async_mqtt/variable_bytes.hpp>
20template <std::
size_t N>
21bool copy_advance(buffer& buf, static_vector<char, N>& sv) {
22 if (buf.size() < sv.capacity())
return false;
25 std::next(buf.begin(),
typename static_vector<char, N>::difference_type(sv.capacity())),
28 buf.remove_prefix(sv.capacity());
32template <std::
size_t N>
33bool insert_advance(buffer& buf, static_vector<char, N>& sv) {
34 if (buf.size() < sv.capacity())
return false;
37 std::next(buf.begin(),
typename static_vector<char, N>::difference_type(sv.capacity())),
38 std::back_inserter(sv)
40 buf.remove_prefix(sv.capacity());
45optional<std::uint32_t> insert_advance_variable_length(buffer& buf, static_vector<char, 4>& sv) {
46 if (buf.empty())
return nullopt;
47 std::uint32_t variable_length = 0;
48 auto it = buf.begin();
50 if (
auto len_opt = variable_bytes_to_val(it, buf.end())) {
51 variable_length = *len_opt;
59 std::back_inserter(sv));
60 buf.remove_prefix(std::size_t(std::distance(buf.begin(), it)));
61 return variable_length;