6 #ifndef KAGOME_ADAPTERS_UVAR 7 #define KAGOME_ADAPTERS_UVAR 9 #include <boost/system/error_code.hpp> 24 static constexpr
size_t kMSBBit = (1ull << 63);
26 ((
sizeof(uint64_t) <<
size_t(3)) +
size_t(6)) /
size_t(7);
29 static size_t size(
const T & ) {
33 static std::vector<uint8_t>::iterator
write(
35 std::vector<uint8_t> &out,
36 std::vector<uint8_t>::iterator loaded) {
38 static_cast<size_t>(std::distance(out.begin(), loaded));
40 auto data_sz = out.size() - remains;
43 if (0 == (kMSBBit & data_sz)) {
44 data_sz <<= size_t(1ull);
46 data_sz <<= size_t(7ull);
49 auto sz_start = --loaded;
51 assert(std::distance(out.begin(), loaded) >= 1);
54 }
while ((data_sz <<=
size_t(7ull)) != 0);
60 static outcome::result<std::vector<uint8_t>::const_iterator>
read(
62 const std::vector<uint8_t> &src,
63 std::vector<uint8_t>::const_iterator from) {
67 const auto loaded = std::distance(src.begin(), from);
69 auto const *
const beg = from.base();
70 auto const *
const end = &src[std::min(loaded + kPayloadSize, src.size())];
71 auto const *ptr = beg;
76 << (
size_t(7) * counter++));
80 if (sz != src.size() - (loaded + counter))
83 std::advance(from, counter);
90 #endif // KAGOME_ADAPTERS_UVAR
static std::vector< uint8_t >::iterator write(const T &t, std::vector< uint8_t > &out, std::vector< uint8_t >::iterator loaded)
static constexpr size_t kPayloadSize
static constexpr size_t kSignificantBitsMaskMSB
static constexpr size_t kSignificantBitsMask
static outcome::result< std::vector< uint8_t >::const_iterator > read(T &, const std::vector< uint8_t > &src, std::vector< uint8_t >::const_iterator from)
static size_t size(const T &)
static constexpr size_t kContinuationBitMask
static constexpr size_t kMSBBit