7#if !defined(ASYNC_MQTT_VARIABLE_BYTES_HPP)
8#define ASYNC_MQTT_VARIABLE_BYTES_HPP
12#include <async_mqtt/util/static_vector.hpp>
13#include <async_mqtt/util/optional.hpp>
14#include <async_mqtt/util/is_iterator.hpp>
18inline static_vector<char, 4>
19val_to_variable_bytes(std::uint32_t val) {
20 static_vector<char, 4> bytes;
21 if (val > 0xfffffff)
return bytes;
23 bytes.push_back(
static_cast<char>((val & 0b01111111) | 0b10000000));
26 bytes.push_back(val & 0b01111111);
31template <
typename It,
typename End>
34 is_input_iterator<It>::value &&
35 is_input_iterator<End>::value,
36 optional<std::uint32_t>
38variable_bytes_to_val(It& it, End e) {
41 for (; it != e; ++it) {
42 val += (*it & 0b01111111) * mul;
44 if (mul > 128 * 128 * 128 * 128) {
48 if (!(*it & 0b10000000)) {
53 return std::uint32_t(val);