Network System 0.1.1
High-performance modular networking library for scalable client-server applications
Loading...
Searching...
No Matches
kcenon::network::protocols::http2::dynamic_table Class Reference

HPACK dynamic table for header compression. More...

#include <hpack.h>

Collaboration diagram for kcenon::network::protocols::http2::dynamic_table:
Collaboration graph

Public Member Functions

 dynamic_table (size_t max_size=4096)
 Construct dynamic table with max size.
 
auto insert (std::string_view name, std::string_view value) -> void
 Insert header at beginning of table.
 
auto get (size_t index) const -> std::optional< http_header >
 Get header by dynamic table index.
 
auto find (std::string_view name, std::string_view value="") const -> std::optional< size_t >
 Find header in dynamic table.
 
auto set_max_size (size_t size) -> void
 Set maximum table size.
 
auto current_size () const -> size_t
 Get current table size.
 
auto max_size () const -> size_t
 Get maximum table size.
 
auto entry_count () const -> size_t
 Get number of entries.
 
auto clear () -> void
 Clear all entries.
 

Private Member Functions

auto evict_to_size (size_t target_size) -> void
 

Private Attributes

std::deque< http_headerentries_
 
size_t current_size_ = 0
 
size_t max_size_
 

Detailed Description

HPACK dynamic table for header compression.

The dynamic table maintains recently used headers for compression. Entries are added at the beginning and evicted from the end when the table exceeds max_size.

Definition at line 83 of file hpack.h.

Constructor & Destructor Documentation

◆ dynamic_table()

kcenon::network::protocols::http2::dynamic_table::dynamic_table ( size_t max_size = 4096)
explicit

Construct dynamic table with max size.

Parameters
max_sizeMaximum table size in bytes (default 4096)

Definition at line 110 of file hpack.cpp.

112 {
113 }
auto max_size() const -> size_t
Get maximum table size.
Definition hpack.cpp:165

Member Function Documentation

◆ clear()

auto kcenon::network::protocols::http2::dynamic_table::clear ( ) -> void

Clear all entries.

Definition at line 175 of file hpack.cpp.

176 {
177 entries_.clear();
178 current_size_ = 0;
179 }

◆ current_size()

auto kcenon::network::protocols::http2::dynamic_table::current_size ( ) const -> size_t

Get current table size.

Returns
Current size in bytes

Definition at line 160 of file hpack.cpp.

161 {
162 return current_size_;
163 }

References current_size_.

Referenced by kcenon::network::protocols::http2::hpack_decoder::table_size(), and kcenon::network::protocols::http2::hpack_encoder::table_size().

Here is the caller graph for this function:

◆ entry_count()

auto kcenon::network::protocols::http2::dynamic_table::entry_count ( ) const -> size_t

Get number of entries.

Returns
Entry count

Definition at line 170 of file hpack.cpp.

171 {
172 return entries_.size();
173 }

References entries_.

◆ evict_to_size()

auto kcenon::network::protocols::http2::dynamic_table::evict_to_size ( size_t target_size) -> void
private

Definition at line 181 of file hpack.cpp.

182 {
183 while (current_size_ > target_size && !entries_.empty())
184 {
185 current_size_ -= entries_.back().size();
186 entries_.pop_back();
187 }
188 }

◆ find()

auto kcenon::network::protocols::http2::dynamic_table::find ( std::string_view name,
std::string_view value = "" ) const -> std::optional<size_t>

Find header in dynamic table.

Parameters
nameHeader name
valueHeader value (empty to match name only)
Returns
Dynamic table index if found, or empty

Definition at line 137 of file hpack.cpp.

139 {
140 for (size_t i = 0; i < entries_.size(); ++i)
141 {
142 const auto& entry = entries_[i];
143 if (entry.name == name)
144 {
145 if (value.empty() || entry.value == value)
146 {
147 return i;
148 }
149 }
150 }
151 return std::nullopt;
152 }

◆ get()

auto kcenon::network::protocols::http2::dynamic_table::get ( size_t index) const -> std::optional<http_header>

Get header by dynamic table index.

Parameters
indexDynamic table index (0-based)
Returns
Header if found

Definition at line 128 of file hpack.cpp.

129 {
130 if (index >= entries_.size())
131 {
132 return std::nullopt;
133 }
134 return entries_[index];
135 }

◆ insert()

auto kcenon::network::protocols::http2::dynamic_table::insert ( std::string_view name,
std::string_view value ) -> void

Insert header at beginning of table.

Parameters
nameHeader name
valueHeader value

Definition at line 115 of file hpack.cpp.

116 {
117 http_header header{std::string(name), std::string(value)};
118 size_t entry_size = header.size();
119
120 // Evict entries if needed
121 evict_to_size(max_size_ - entry_size);
122
123 // Insert at beginning
124 entries_.push_front(std::move(header));
125 current_size_ += entry_size;
126 }
auto evict_to_size(size_t target_size) -> void
Definition hpack.cpp:181

References kcenon::network::protocols::http2::http_header::size().

Here is the call graph for this function:

◆ max_size()

auto kcenon::network::protocols::http2::dynamic_table::max_size ( ) const -> size_t

Get maximum table size.

Returns
Maximum size in bytes

Definition at line 165 of file hpack.cpp.

166 {
167 return max_size_;
168 }

References max_size_.

◆ set_max_size()

auto kcenon::network::protocols::http2::dynamic_table::set_max_size ( size_t size) -> void

Set maximum table size.

Parameters
sizeNew maximum size in bytes

Definition at line 154 of file hpack.cpp.

155 {
156 max_size_ = size;
158 }

Member Data Documentation

◆ current_size_

size_t kcenon::network::protocols::http2::dynamic_table::current_size_ = 0
private

Definition at line 148 of file hpack.h.

Referenced by current_size().

◆ entries_

std::deque<http_header> kcenon::network::protocols::http2::dynamic_table::entries_
private

Definition at line 147 of file hpack.h.

Referenced by entry_count().

◆ max_size_

size_t kcenon::network::protocols::http2::dynamic_table::max_size_
private

Definition at line 149 of file hpack.h.

Referenced by max_size().


The documentation for this class was generated from the following files: