xref: /aosp_15_r20/external/cronet/net/third_party/quiche/src/quiche/spdy/core/hpack/hpack_static_table.h (revision 6777b5387eb2ff775bb5750e3f5d96f37fb7352b)
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 #ifndef QUICHE_SPDY_CORE_HPACK_HPACK_STATIC_TABLE_H_
6 #define QUICHE_SPDY_CORE_HPACK_HPACK_STATIC_TABLE_H_
7 
8 #include <cstddef>
9 
10 #include "quiche/common/platform/api/quiche_export.h"
11 #include "quiche/spdy/core/hpack/hpack_header_table.h"
12 
13 namespace spdy {
14 
15 struct HpackStaticEntry;
16 
17 // Number of entries in the HPACK static table.
18 inline constexpr size_t kStaticTableSize = 61;
19 
20 // HpackStaticTable provides |static_entries_| and |static_index_| for HPACK
21 // encoding and decoding contexts.  Once initialized, an instance is read only
22 // and may be accessed only through its const interface.  Such an instance may
23 // be shared accross multiple HPACK contexts.
24 class QUICHE_EXPORT HpackStaticTable {
25  public:
26   HpackStaticTable();
27   ~HpackStaticTable();
28 
29   // Prepares HpackStaticTable by filling up static_entries_ and static_index_
30   // from an array of struct HpackStaticEntry.  Must be called exactly once.
31   void Initialize(const HpackStaticEntry* static_entry_table,
32                   size_t static_entry_count);
33 
34   // Returns whether Initialize() has been called.
35   bool IsInitialized() const;
36 
37   // Accessors.
GetStaticEntries()38   const HpackHeaderTable::StaticEntryTable& GetStaticEntries() const {
39     return static_entries_;
40   }
GetStaticIndex()41   const HpackHeaderTable::NameValueToEntryMap& GetStaticIndex() const {
42     return static_index_;
43   }
GetStaticNameIndex()44   const HpackHeaderTable::NameToEntryMap& GetStaticNameIndex() const {
45     return static_name_index_;
46   }
47 
48  private:
49   HpackHeaderTable::StaticEntryTable static_entries_;
50   // The following two members have string_views that point to strings stored in
51   // |static_entries_|.
52   HpackHeaderTable::NameValueToEntryMap static_index_;
53   HpackHeaderTable::NameToEntryMap static_name_index_;
54 };
55 
56 }  // namespace spdy
57 
58 #endif  // QUICHE_SPDY_CORE_HPACK_HPACK_STATIC_TABLE_H_
59