35 std::byte *
const destination) -> std::size_t {
37 constexpr std::uint8_t PAYLOAD_MASK{0b01111111};
38 constexpr std::uint8_t CONTINUATION_BIT{0b10000000};
39 constexpr std::uint8_t PAYLOAD_BITS{7};
40 std::uint64_t accumulator{value};
42 if (accumulator <= PAYLOAD_MASK) {
43 destination[index] =
static_cast<std::byte
>(accumulator);
47 destination[index] =
static_cast<std::byte
>(
48 static_cast<std::uint8_t
>(accumulator & PAYLOAD_MASK) |
50 accumulator >>= PAYLOAD_BITS;
70inline auto varint_decode(
const std::byte *
const source,
const std::size_t size)
73 constexpr std::uint8_t PAYLOAD_MASK{0b01111111};
74 constexpr std::uint8_t CONTINUATION_BIT{0b10000000};
75 constexpr std::uint8_t PAYLOAD_BITS{7};
80 const auto last{
static_cast<std::uint8_t
>(source[size - 1])};
81 if ((last & CONTINUATION_BIT) != 0) {
91 std::uint64_t result{0};
92 for (std::size_t index = 0; index < size; index++) {
93 const auto byte{
static_cast<std::uint8_t
>(source[index])};
94 if (index + 1 != size && (
byte & CONTINUATION_BIT) == 0) {
98 result |=
static_cast<std::uint64_t
>(
byte & PAYLOAD_MASK)
99 << (PAYLOAD_BITS * index);