summaryrefslogtreecommitdiff
path: root/chromium/net/third_party/quiche/src/spdy/core/hpack/hpack_static_table.cc
blob: e5a403d7162c34f816800581cbbd4b998f884e48 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "spdy/core/hpack/hpack_static_table.h"

#include "absl/strings/string_view.h"
#include "common/platform/api/quiche_logging.h"
#include "spdy/core/hpack/hpack_constants.h"
#include "spdy/core/hpack/hpack_entry.h"

namespace spdy {

HpackStaticTable::HpackStaticTable() = default;

HpackStaticTable::~HpackStaticTable() = default;

void HpackStaticTable::Initialize(const HpackStaticEntry* static_entry_table,
                                  size_t static_entry_count) {
  QUICHE_CHECK(!IsInitialized());

  static_entries_.reserve(static_entry_count);

  for (const HpackStaticEntry* it = static_entry_table;
       it != static_entry_table + static_entry_count; ++it) {
    std::string name(it->name, it->name_len);
    std::string value(it->value, it->value_len);
    static_entries_.push_back(HpackEntry(std::move(name), std::move(value)));
  }

  // |static_entries_| will not be mutated any more.  Therefore its entries will
  // remain stable even if the container does not have iterator stability.
  int insertion_count = 0;
  for (const auto& entry : static_entries_) {
    auto result = static_index_.insert(std::make_pair(
        HpackLookupEntry{entry.name(), entry.value()}, insertion_count));
    QUICHE_CHECK(result.second);

    // Multiple static entries may have the same name, so inserts may fail.
    static_name_index_.insert(std::make_pair(entry.name(), insertion_count));

    ++insertion_count;
  }
}

bool HpackStaticTable::IsInitialized() const {
  return !static_entries_.empty();
}

}  // namespace spdy