Utility for Varint encoding/decoding.
More...
#include <crunch_varint.hpp>
|
| static constexpr std::size_t | encode (uint64_t value, std::span< std::byte > output, std::size_t offset) noexcept |
| | Encodes a value as a Varint.
|
| |
| static constexpr std::optional< std::pair< uint64_t, std::size_t > > | decode (std::span< const std::byte > input, std::size_t offset) noexcept |
| | Decodes a Varint from a buffer.
|
| |
| static constexpr std::size_t | size (uint64_t value) noexcept |
| | Calculates the size requirement for a value encoded as Varint.
|
| |
| static consteval std::size_t | max_varint_size (std::size_t value_bits) |
| | Calculates the maximum varint size for a given number of bits.
|
| |
|
|
static constexpr std::size_t | max_size = 10 |
| | The maximum size required for a 64-bit integer encoded as Varint. ceil(64 / 7) = 10.
|
| |
Utility for Varint encoding/decoding.
Implemented as a header-only library to support constexpr evaluation.
◆ decode()
| static constexpr std::optional< std::pair< uint64_t, std::size_t > > Crunch::serdes::Varint::decode |
( |
std::span< const std::byte > |
input, |
|
|
std::size_t |
offset |
|
) |
| |
|
inlinestaticconstexprnoexcept |
Decodes a Varint from a buffer.
- Parameters
-
| input | The input buffer. |
| offset | The offset to start reading from. |
- Returns
- std::optional<std::pair<uint64_t, std::size_t>> The decoded value and bytes read, or nullopt on error.
◆ encode()
| static constexpr std::size_t Crunch::serdes::Varint::encode |
( |
uint64_t |
value, |
|
|
std::span< std::byte > |
output, |
|
|
std::size_t |
offset |
|
) |
| |
|
inlinestaticconstexprnoexcept |
Encodes a value as a Varint.
- Parameters
-
| value | The value to encode. |
| output | The output buffer. |
| offset | The current offset in the buffer. |
- Returns
- std::size_t The number of bytes written.
◆ max_varint_size()
| static consteval std::size_t Crunch::serdes::Varint::max_varint_size |
( |
std::size_t |
value_bits | ) |
|
|
inlinestatic |
Calculates the maximum varint size for a given number of bits.
- Parameters
-
| value_bits | The number of bits. |
- Returns
- The maximum number of bytes required.
◆ size()
| static constexpr std::size_t Crunch::serdes::Varint::size |
( |
uint64_t |
value | ) |
|
|
inlinestaticconstexprnoexcept |
Calculates the size requirement for a value encoded as Varint.
- Parameters
-
- Returns
- std::size_t The number of bytes required.
The documentation for this struct was generated from the following file: