The Tiny HTM Library
|
Variable length integer encoding/decoding. More...
#include "common.h"
Go to the source code of this file.
Functions | |
HTM_INLINE unsigned int | htm_varint_len (uint64_t val) |
Returns the number of bytes required to represent val. | |
HTM_INLINE unsigned int | htm_varint_nfollow (unsigned char leadbyte) |
Returns the number of bytes following the specified leading byte (in a variable length coding of an unsigned integer). | |
HTM_INLINE uint64_t | htm_varint_decode (const unsigned char *buf) |
Decodes the variable length integer encoded at buf. | |
HTM_INLINE unsigned int | htm_varint_encode (unsigned char *buf, const uint64_t val) |
Variable-length encodes val into the given buffer, which must point to a buffer of at least 8 bytes. | |
HTM_INLINE unsigned int | htm_varint_rencode (unsigned char *buf, const uint64_t val) |
Variable-length encodes val into the given buffer, which must point to a buffer of at least 8 bytes. |
Variable length integer encoding/decoding.
The scheme employed here is as follows: an unsigned integer is mapped to a sequence of bytes. The 3 MSBs of the first byte contain the number of subsequent bytes in the sequence, and the 5 LSBs contain the 5 MSBs of the value. Bytes after the first contain the remaining bits of the value, from most to least significant. The smallest representable integer is 0, the largest 2^61 - 1.
Definition in file varint.h.