|
Network System 0.1.1
High-performance modular networking library for scalable client-server applications
|
QUIC variable-length integer encoding/decoding (RFC 9000 Section 16) More...
#include <varint.h>

Static Public Member Functions | |
| static auto | encode (uint64_t value) -> std::vector< uint8_t > |
| Encode a value to variable-length format. | |
| static auto | encode_with_length (uint64_t value, size_t min_length) -> Result< std::vector< uint8_t > > |
| Encode with minimum length requirement. | |
| static auto | decode (std::span< const uint8_t > data) -> Result< std::pair< uint64_t, size_t > > |
| Decode variable-length integer from buffer. | |
| static constexpr auto | encoded_length (uint64_t value) noexcept -> size_t |
| Get the number of bytes needed to encode a value. | |
| static constexpr auto | length_from_prefix (uint8_t first_byte) noexcept -> size_t |
| Get encoded length from the first byte's prefix. | |
| static constexpr auto | is_valid (uint64_t value) noexcept -> bool |
| Check if a value can be encoded as a varint. | |
Static Public Attributes | |
| static constexpr uint64_t | max_1byte = 63 |
| Maximum value for each encoded length. | |
| static constexpr uint64_t | max_2byte = 16383 |
| static constexpr uint64_t | max_4byte = 1073741823 |
| static constexpr uint64_t | max_8byte = varint_max |
Static Private Attributes | |
| static constexpr uint8_t | prefix_1byte = 0x00 |
| static constexpr uint8_t | prefix_2byte = 0x40 |
| static constexpr uint8_t | prefix_4byte = 0x80 |
| static constexpr uint8_t | prefix_8byte = 0xC0 |
| static constexpr uint8_t | prefix_mask = 0xC0 |
| static constexpr uint8_t | value_mask = 0x3F |
QUIC variable-length integer encoding/decoding (RFC 9000 Section 16)
QUIC uses a variable-length integer encoding with 2-bit length prefix:
| 2-Bit Value | Length | Usable Bits | Range |
|---|---|---|---|
| 0b00 | 1 byte | 6 | 0-63 |
| 0b01 | 2 bytes | 14 | 0-16383 |
| 0b10 | 4 bytes | 30 | 0-1073741823 |
| 0b11 | 8 bytes | 62 | 0-4611686018427387903 |
The two most significant bits of the first byte indicate the length.
|
staticnodiscard |
Decode variable-length integer from buffer.
| data | Input buffer |
Definition at line 146 of file varint.cpp.
References kcenon::network::protocols::quic::error, kcenon::network::error_codes::common_errors::invalid_argument, and kcenon::network::ok().
Referenced by kcenon::network::protocols::quic::transport_parameters::decode(), kcenon::network::protocols::quic::frame_parser::parse(), kcenon::network::protocols::quic::frame_parser::parse_ack(), kcenon::network::protocols::quic::frame_parser::parse_connection_close(), kcenon::network::protocols::quic::frame_parser::parse_crypto(), kcenon::network::protocols::quic::frame_parser::parse_data_blocked(), kcenon::network::protocols::quic::packet_parser::parse_long_header(), kcenon::network::protocols::quic::frame_parser::parse_max_data(), kcenon::network::protocols::quic::frame_parser::parse_max_stream_data(), kcenon::network::protocols::quic::frame_parser::parse_max_streams(), kcenon::network::protocols::quic::frame_parser::parse_new_connection_id(), kcenon::network::protocols::quic::frame_parser::parse_new_token(), kcenon::network::protocols::quic::frame_parser::parse_reset_stream(), kcenon::network::protocols::quic::frame_parser::parse_retire_connection_id(), kcenon::network::protocols::quic::frame_parser::parse_stop_sending(), kcenon::network::protocols::quic::frame_parser::parse_stream(), kcenon::network::protocols::quic::frame_parser::parse_stream_data_blocked(), kcenon::network::protocols::quic::frame_parser::parse_streams_blocked(), and kcenon::network::protocols::quic::frame_parser::peek_type().


|
staticnodiscard |
Encode a value to variable-length format.
| value | Value to encode (must be <= varint_max) |
Definition at line 10 of file varint.cpp.
References kcenon::network::protocols::quic::varint_max.
Referenced by kcenon::network::protocols::quic::frame_builder::append_varint(), and kcenon::network::protocols::quic::packet_builder::build_initial().

|
staticnodiscard |
Encode with minimum length requirement.
| value | Value to encode |
| min_length | Minimum encoded length (1, 2, 4, or 8) |
Definition at line 57 of file varint.cpp.
References kcenon::network::protocols::quic::error, kcenon::network::error_codes::common_errors::invalid_argument, kcenon::network::ok(), and kcenon::network::protocols::quic::varint_max.

|
inlinestaticnodiscardconstexprnoexcept |
Get the number of bytes needed to encode a value.
| value | Value to check |
Definition at line 72 of file varint.h.
|
inlinestaticnodiscardconstexprnoexcept |
Check if a value can be encoded as a varint.
| value | Value to check |
Definition at line 104 of file varint.h.
References kcenon::network::protocols::quic::varint_max.
|
inlinestaticnodiscardconstexprnoexcept |
|
staticconstexpr |
|
staticconstexpr |
|
staticconstexpr |
|
staticconstexpr |
|
staticconstexprprivate |
|
staticconstexprprivate |
|
staticconstexprprivate |
|
staticconstexprprivate |
|
staticconstexprprivate |
|
staticconstexprprivate |