• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 #include "quiche/spdy/core/hpack/hpack_static_table.h"
6 
7 #include "absl/strings/string_view.h"
8 #include "quiche/common/platform/api/quiche_logging.h"
9 #include "quiche/spdy/core/hpack/hpack_constants.h"
10 #include "quiche/spdy/core/hpack/hpack_entry.h"
11 
12 namespace spdy {
13 
14 HpackStaticTable::HpackStaticTable() = default;
15 
16 HpackStaticTable::~HpackStaticTable() = default;
17 
Initialize(const HpackStaticEntry * static_entry_table,size_t static_entry_count)18 void HpackStaticTable::Initialize(const HpackStaticEntry* static_entry_table,
19                                   size_t static_entry_count) {
20   QUICHE_CHECK(!IsInitialized());
21 
22   static_entries_.reserve(static_entry_count);
23 
24   for (const HpackStaticEntry* it = static_entry_table;
25        it != static_entry_table + static_entry_count; ++it) {
26     std::string name(it->name, it->name_len);
27     std::string value(it->value, it->value_len);
28     static_entries_.push_back(HpackEntry(std::move(name), std::move(value)));
29   }
30 
31   // |static_entries_| will not be mutated any more.  Therefore its entries will
32   // remain stable even if the container does not have iterator stability.
33   int insertion_count = 0;
34   for (const auto& entry : static_entries_) {
35     auto result = static_index_.insert(std::make_pair(
36         HpackLookupEntry{entry.name(), entry.value()}, insertion_count));
37     QUICHE_CHECK(result.second);
38 
39     // Multiple static entries may have the same name, so inserts may fail.
40     static_name_index_.insert(std::make_pair(entry.name(), insertion_count));
41 
42     ++insertion_count;
43   }
44 }
45 
IsInitialized() const46 bool HpackStaticTable::IsInitialized() const {
47   return !static_entries_.empty();
48 }
49 
50 }  // namespace spdy
51