1#ifndef PROTOZERO_VARINT_HPP
2#define PROTOZERO_VARINT_HPP
34 inline uint64_t decode_varint_impl(
const char** data,
const char* end) {
35 const auto* begin =
reinterpret_cast<const int8_t*
>(*data);
36 const auto* iend =
reinterpret_cast<const int8_t*
>(end);
37 const int8_t* p = begin;
43 val = ((uint64_t(b) & 0x7fU) );
if (b >= 0) {
break; }
44 b = *p++; val |= ((uint64_t(b) & 0x7fU) << 7U);
if (b >= 0) {
break; }
45 b = *p++; val |= ((uint64_t(b) & 0x7fU) << 14U);
if (b >= 0) {
break; }
46 b = *p++; val |= ((uint64_t(b) & 0x7fU) << 21U);
if (b >= 0) {
break; }
47 b = *p++; val |= ((uint64_t(b) & 0x7fU) << 28U);
if (b >= 0) {
break; }
48 b = *p++; val |= ((uint64_t(b) & 0x7fU) << 35U);
if (b >= 0) {
break; }
49 b = *p++; val |= ((uint64_t(b) & 0x7fU) << 42U);
if (b >= 0) {
break; }
50 b = *p++; val |= ((uint64_t(b) & 0x7fU) << 49U);
if (b >= 0) {
break; }
51 b = *p++; val |= ((uint64_t(b) & 0x7fU) << 56U);
if (b >= 0) {
break; }
52 b = *p++; val |= ((uint64_t(b) & 0x01U) << 63U);
if (b >= 0) {
break; }
56 unsigned int shift = 0;
57 while (p != iend && *p < 0) {
58 val |= (uint64_t(*p++) & 0x7fU) << shift;
64 val |= uint64_t(*p++) << shift;
67 *data =
reinterpret_cast<const char*
>(p);
92 if (end != *data && ((
static_cast<uint64_t
>(**data) & 0x80U) == 0)) {
93 const auto val =
static_cast<uint64_t
>(**data);
98 return detail::decode_varint_impl(data, end);
114 const auto* begin =
reinterpret_cast<const int8_t*
>(*data);
115 const auto* iend =
reinterpret_cast<const int8_t*
>(end);
116 const int8_t* p = begin;
118 while (p != iend && *p < 0) {
132 *data =
reinterpret_cast<const char*
>(p);
150 while (value >= 0x80U) {
151 *data++ = char((value & 0x7fU) | 0x80U);
169template <
typename TBuffer>
171 while (value >= 0x80U) {
172 buffer_customization<TBuffer>::push_back(buffer,
char((value & 0x7fU) | 0x80U));
175 buffer_customization<TBuffer>::push_back(buffer,
char(value));
188 while (value >= 0x80U) {
189 *data++ = char((value & 0x7fU) | 0x80U);
207 while (value >= 0x80U) {
219 return (
static_cast<uint32_t
>(value) << 1U) ^
static_cast<uint32_t
>(-
static_cast<int32_t
>(
static_cast<uint32_t
>(value) >> 31U));
226 return (
static_cast<uint64_t
>(value) << 1U) ^
static_cast<uint64_t
>(-
static_cast<int64_t
>(
static_cast<uint64_t
>(value) >> 63U));
233 return static_cast<int32_t
>((value >> 1U) ^
static_cast<uint32_t
>(-
static_cast<int32_t
>(value & 1U)));
240 return static_cast<int64_t
>((value >> 1U) ^
static_cast<uint64_t
>(-
static_cast<int64_t
>(value & 1U)));
Contains the customization points for buffer implementations.
Contains the exceptions used in the protozero library.
All parts of the protozero header-only library are in this namespace.
Definition basic_pbf_builder.hpp:24
constexpr int32_t decode_zigzag32(uint32_t value) noexcept
Definition varint.hpp:232
void add_varint_to_buffer(TBuffer *buffer, uint64_t value)
Definition varint.hpp:170
int length_of_varint(uint64_t value) noexcept
Definition varint.hpp:204
constexpr uint32_t encode_zigzag32(int32_t value) noexcept
Definition varint.hpp:218
constexpr int64_t decode_zigzag64(uint64_t value) noexcept
Definition varint.hpp:239
constexpr uint64_t encode_zigzag64(int64_t value) noexcept
Definition varint.hpp:225
constexpr const int8_t max_varint_length
Definition varint.hpp:29
void skip_varint(const char **data, const char *end)
Definition varint.hpp:113
uint64_t decode_varint(const char **data, const char *end)
Definition varint.hpp:90
int write_varint(T data, uint64_t value)
Definition varint.hpp:147
Definition exception.hpp:67
Definition exception.hpp:41