/varint

Use most-significant bit to create integer values of varying sizes.

Primary LanguageC++

SYNOPSIS

Use msb to create integer values of varying sizes.

USAGE

This module is designed to work with the datcxx build tool. To add this module to your project us the following command...

build add datcxx/varint

TEST

build test

API

struct Encoded {
  std::vector<uint8_t> value;
  unsigned bytes;
};

struct Decoded {
  unsigned value;
  unsigned bytes;
};
Encoded encode (unsigned num);
Encoded encode (unsigned num, std::vector<uint8_t> out, unsigned offset = 0);
Decoded decode (std::vector<uint8_t> buf, unsigned offset = 0);

SEE ALSO

  • This is a nice visual illustration of how varints work.
  • This is a port of Chris Dickinson's varint implementation.
  • This also references Dat Rust varint implementation.
  • A quick summary of how varint encoding works.
  • See this guide to efficiently encoding variable-length integers in C/C++.