| 333 | } |
| 334 | |
| 335 | const XpackLookupResult |
| 336 | XpackDynamicTable::insert_entry(const char *name, size_t name_len, const char *value, size_t value_len) |
| 337 | { |
| 338 | if (this->_max_entries == 0) { |
| 339 | return {UINT32_C(0), XpackLookupResult::MatchType::NONE}; |
| 340 | } |
| 341 | |
| 342 | // Make enough space to insert a new entry |
| 343 | uint64_t required_size = static_cast<uint64_t>(name_len) + static_cast<uint64_t>(value_len) + ADDITIONAL_32_BYTES; |
| 344 | if (required_size > this->_available) { |
| 345 | if (!this->_make_space(required_size - this->_available)) { |
| 346 | // We can't insert a new entry because some stream(s) refer an entry that need to be evicted or the header is too big to |
| 347 | // store. This is fine with HPACK, but not with QPACK. |
| 348 | return {UINT32_C(0), XpackLookupResult::MatchType::NONE}; |
| 349 | } |
| 350 | } |
| 351 | |
| 352 | // Insert |
| 353 | const char *wks = nullptr; |
| 354 | hdrtoken_tokenize(name, name_len, &wks); |
| 355 | this->_entries_head = this->_calc_index(this->_entries_head, 1); |
| 356 | this->_entries[this->_entries_head] = { |
| 357 | this->_entries_inserted++, |
| 358 | this->_storage.write(name, static_cast<uint32_t>(name_len), value, static_cast<uint32_t>(value_len)), |
| 359 | static_cast<uint32_t>(name_len), |
| 360 | static_cast<uint32_t>(value_len), |
| 361 | 0, |
| 362 | wks}; |
| 363 | this->_available -= required_size; |
| 364 | |
| 365 | XPACKDbg("Insert Entry: entry=%u, index=%u, size=%zu", this->_entries_head, this->_entries_inserted - 1, name_len + value_len); |
| 366 | XPACKDbg("Available size: %u", this->_available); |
| 367 | return {this->_entries_inserted, value_len ? XpackLookupResult::MatchType::EXACT : XpackLookupResult::MatchType::NAME}; |
| 368 | } |
| 369 | |
| 370 | const XpackLookupResult |
| 371 | XpackDynamicTable::insert_entry(const std::string_view name, const std::string_view value) |
no test coverage detected