Network System 0.1.1
High-performance modular networking library for scalable client-server applications
Loading...
Searching...
No Matches
connection_id.h
Go to the documentation of this file.
1// BSD 3-Clause License
2// Copyright (c) 2024, 🍀☀🌕🌥 🌊
3// See the LICENSE file in the project root for full license information.
4
11#pragma once
12
21#include <array>
22#include <cstdint>
23#include <span>
24#include <string>
25
27{
28
44{
45public:
47 static constexpr size_t max_length = 20;
48
52 connection_id() = default;
53
60 explicit connection_id(std::span<const uint8_t> data);
61
67 [[nodiscard]] static auto generate(size_t length = 8) -> connection_id;
68
73 [[nodiscard]] auto data() const -> std::span<const uint8_t>;
74
79 [[nodiscard]] auto length() const noexcept -> size_t;
80
85 [[nodiscard]] auto empty() const noexcept -> bool;
86
92 [[nodiscard]] auto operator==(const connection_id& other) const noexcept -> bool;
93
99 [[nodiscard]] auto operator!=(const connection_id& other) const noexcept -> bool;
100
106 [[nodiscard]] auto operator<(const connection_id& other) const noexcept -> bool;
107
112 [[nodiscard]] auto to_string() const -> std::string;
113
114private:
115 std::array<uint8_t, max_length> data_{};
116 uint8_t length_{0};
117};
118
119} // namespace kcenon::network::protocols::quic
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 data() const -> std::span< const uint8_t >
Get the raw bytes of the connection ID.