

Signed little endian base 128 (LEB128) implementation, which stores arbitrarily large signed integers in a variable length format. This library is compatible with Arduino ARM and with CMake build systems. It would also be easy to include with other projects, since it is a header only library consisting of a single file.
Use the Arduino Library Manager to install this library or clone to your Arduino/libraries folder. This library is added as:
An example Arduino executable is located atexamples/arduino/leb128_example/leb128_example.ino. Teensy 3.x, 4.x, and LC devices are used for testing under Arduino and this library should be compatible with other ARM devices. This library isnot expected to work on AVR devices.
CMake is used to build this library, which is exported as a library target calledleb128. The header is added as:
The library can be also be compiled stand-alone using the CMake idiom of creating abuild directory and then, from within that directory issuing:
This will build the library, an example executable calledleb128_example, and an executable for testing using the Google Test framework, calledleb128_test. The example executable source file is located atexamples/cmake/leb128_example.cc.
This library is within the namespacebfs.
std::size_t EncodeLeb128(int64_t val, uint8_t * const data, const std::size_t len) Encodes an int64_tval into a LEB128 variable length format stored in the arraydata of lengthlen. Returns the number of bytes written if successful, otherwise, returns 0.
std::size_t DecodeLeb128(uint8_t const * const data, const std::size_t len, int64_t * const val) Decodes a LEB128 variable length value from the arraydata of lengthlen into an int64_t variableval. Returns the number of bytes read if successful, otherwise, returns 0.
uint8_t buf[100];int64_t read_val =0;int64_t orig_val = std::numeric_limits<int64_t>::max();std::size_t bytes_written = bfs::EncodeLeb128(orig_val, buf,sizeof(buf));std::size_t bytes_read = bfs::DecodeLeb128(buf,sizeof(buf), &read_val);