18 std::copy_n(
data.begin(), copy_len,
data_.begin());
19 length_ =
static_cast<uint8_t
>(copy_len);
27 size_t actual_length = std::min(length, max_length);
28 if (actual_length == 0)
34 std::random_device rd;
35 std::mt19937_64 gen(rd());
36 std::uniform_int_distribution<uint16_t> dist(0, 255);
38 for (
size_t i = 0; i < actual_length; ++i)
40 cid.
data_[i] =
static_cast<uint8_t
>(dist(gen));
42 cid.
length_ =
static_cast<uint8_t
>(actual_length);
64 if (length_ != other.length_)
68 return std::equal(data_.begin(), data_.begin() + length_,
74 return !(*
this == other);
80 if (length_ != other.length_)
82 return length_ < other.length_;
84 return std::lexicographical_compare(
85 data_.begin(), data_.begin() + length_,
86 other.data_.begin(), other.data_.begin() + other.length_);
96 std::ostringstream oss;
97 oss << std::hex << std::setfill(
'0');
98 for (
size_t i = 0; i <
length_; ++i)
100 oss << std::setw(2) << static_cast<unsigned>(
data_[i]);
QUIC Connection ID (RFC 9000 Section 5.1)
std::array< uint8_t, max_length > data_
auto length() const noexcept -> size_t
Get the length of the connection ID.
auto to_string() const -> std::string
Convert to hexadecimal string for debugging.
auto empty() const noexcept -> bool
Check if the connection ID is empty.
connection_id()=default
Default constructor creates an empty connection ID.
static auto generate(size_t length=8) -> connection_id
Generate a random connection ID.
static constexpr size_t max_length
Maximum length of a connection ID (RFC 9000)
auto operator==(const connection_id &other) const noexcept -> bool
Equality comparison.
auto operator!=(const connection_id &other) const noexcept -> bool
Inequality comparison.
auto data() const -> std::span< const uint8_t >
Get the raw bytes of the connection ID.
auto operator<(const connection_id &other) const noexcept -> bool
Less-than comparison for use in ordered containers.
QUIC connection identifier type.