Variable-length integer (VLQ) encoding and decoding.
More...
Go to the source code of this file.
|
#define | VARINTS_MAX_ENCODED_LEN (10u) |
| Maximum size of an encoded 64-bit VLQ/varint value.
|
|
Variable-length integer (VLQ) encoding and decoding.
- Author
- Erik K. Nyquist
◆ varint_decode_i64()
int varint_decode_i64 |
( |
uint8_t * |
input, |
|
|
int64_t * |
output, |
|
|
int * |
bytes_consumed |
|
) |
| |
Decode a VLQ/varint byte stream into a signed 64-bit integer.
- Parameters
-
input | Pointer to VLQ/varint byte stream to decode. |
output | Pointer to location to store decoded integer value. |
bytes_consumed | Pointer to location to store number of input bytes consumed before the end of the VLQ/varint value was found, may be NULL. |
- Returns
- 0 if successful, 1 if the end of the VLQ/varint byte stream was not found after VARINTS_MAX_ENCODED_LEN bytes, and -1 if a NULL pointer was provided for 'input' or 'output'.
◆ varint_decode_u64()
int varint_decode_u64 |
( |
uint8_t * |
input, |
|
|
uint64_t * |
output, |
|
|
int * |
bytes_consumed |
|
) |
| |
Decode a VLQ/varint byte stream into an unsigned 64-bit integer.
- Parameters
-
input | Pointer to VLQ/varint byte stream to decode. |
output | Pointer to location to store decoded integer value. |
bytes_consumed | Pointer to location to store number of input bytes consumed before the end of the VLQ/varint value was found, may be NULL. |
- Returns
- 0 if successful, 1 if the end of the VLQ/varint byte stream was not found after VARINTS_MAX_ENCODED_LEN bytes, and -1 if a NULL pointer was provided for 'input' or 'output'.
◆ varint_encode_i64()
int varint_encode_i64 |
( |
int64_t |
input, |
|
|
uint8_t * |
output, |
|
|
int * |
bytes_generated |
|
) |
| |
Encode a signed 64-bit integer into a VLQ/varint byte stream.
- Parameters
-
input | Input value to encode. |
output | Pointer to location to store encoded output bytes. At least VARINTS_MAX_ENCODED_LEN bytes are expected to be available. |
bytes_generated | Pointer to location to store number of output bytes generated, may be NULL. |
- Returns
- 0 if successful, and -1 if a NULL pointer was provided for 'output'.
◆ varint_encode_u64()
int varint_encode_u64 |
( |
uint64_t |
input, |
|
|
uint8_t * |
output, |
|
|
int * |
bytes_generated |
|
) |
| |
Encode an unsigned 64-bit integer into a VLQ/varint byte stream.
- Parameters
-
input | Input value to encode. |
output | Pointer to location to store encoded output bytes. At least VARINTS_MAX_ENCODED_LEN bytes are expected to be available. |
bytes_generated | Pointer to location to store number of output bytes generated, may be NULL. |
- Returns
- 0 if successful, and -1 if a NULL pointer was provided for 'output'.