hpack_parser_table.h
Go to the documentation of this file.
1 /*
2  *
3  * Copyright 2015 gRPC authors.
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  *
17  */
18 
19 #ifndef GRPC_CORE_EXT_TRANSPORT_CHTTP2_TRANSPORT_HPACK_PARSER_TABLE_H
20 #define GRPC_CORE_EXT_TRANSPORT_CHTTP2_TRANSPORT_HPACK_PARSER_TABLE_H
21 
23 
24 #include <stdint.h>
25 
26 #include <vector>
27 
32 
33 namespace grpc_core {
34 
35 // HPACK header table
36 class HPackTable {
37  public:
38  HPackTable();
39  ~HPackTable();
40 
41  HPackTable(const HPackTable&) = delete;
42  HPackTable& operator=(const HPackTable&) = delete;
43 
44  void SetMaxBytes(uint32_t max_bytes);
46 
48 
49  // Lookup, but don't ref.
50  const Memento* Lookup(uint32_t index) const {
51  // Static table comes first, just return an entry from it.
52  // NB: This imposes the constraint that the first
53  // GRPC_CHTTP2_LAST_STATIC_ENTRY entries in the core static metadata table
54  // must follow the hpack standard. If that changes, we *must* not rely on
55  // reading the core static metadata table here; at that point we'd need our
56  // own singleton static metadata in the correct order.
58  return &static_metadata_.memento[index - 1];
59  } else {
60  return LookupDynamic(index);
61  }
62  }
63 
64  // add a table entry to the index
66 
67  // Current entry count in the table.
68  uint32_t num_entries() const { return entries_.num_entries(); }
69 
70  private:
71  struct StaticMementos {
74  };
76 
78  public:
79  // Rebuild this buffer with a new max_entries_ size.
80  void Rebuild(uint32_t max_entries);
81 
82  // Put a new memento.
83  // REQUIRES: num_entries < max_entries
84  void Put(Memento m);
85 
86  // Pop the oldest memento.
87  // REQUIRES: num_entries > 0
88  Memento PopOne();
89 
90  // Lookup the entry at index, or return nullptr if none exists.
91  const Memento* Lookup(uint32_t index) const;
92 
93  uint32_t max_entries() const { return max_entries_; }
94  uint32_t num_entries() const { return num_entries_; }
95 
96  private:
97  // The index of the first entry in the buffer. May be greater than
98  // max_entries_, in which case a wraparound has occurred.
99  uint32_t first_entry_ = 0;
100  // How many entries are in the table.
101  uint32_t num_entries_ = 0;
102  // Maximum number of entries we could possibly fit in the table, given
103  // defined overheads.
105 
106  std::vector<Memento> entries_;
107  };
108 
110  // Not static - find the value in the list of valid entries
111  const uint32_t tbl_index = index - (hpack_constants::kLastStaticEntry + 1);
112  return entries_.Lookup(tbl_index);
113  }
114 
115  void EvictOne();
116 
117  // The amount of memory used by the table, according to the hpack algorithm
119  // The max memory allowed to be used by the table, according to the hpack
120  // algorithm.
122  // The currently agreed size of the table, according to the hpack algorithm.
124  // HPack table entries
126  // Mementos for static data
128 };
129 
130 } // namespace grpc_core
131 
132 #endif /* GRPC_CORE_EXT_TRANSPORT_CHTTP2_TRANSPORT_HPACK_PARSER_TABLE_H */
metadata_batch.h
parsed_metadata.h
grpc_core
Definition: call_metric_recorder.h:31
grpc_core::HPackTable::HPackTable
HPackTable()
Definition: hpack_parser_table.cc:81
grpc_core::HPackTable::MementoRingBuffer::Lookup
const Memento * Lookup(uint32_t index) const
Definition: hpack_parser_table.cc:62
grpc_core::HPackTable::MementoRingBuffer::entries_
std::vector< Memento > entries_
Definition: hpack_parser_table.h:106
grpc_core::HPackTable::mem_used_
uint32_t mem_used_
Definition: hpack_parser_table.h:118
grpc_core::HPackTable::num_entries
uint32_t num_entries() const
Definition: hpack_parser_table.h:68
grpc_core::HPackTable::current_table_bytes_
uint32_t current_table_bytes_
Definition: hpack_parser_table.h:123
grpc_core::HPackTable::Memento
ParsedMetadata< grpc_metadata_batch > Memento
Definition: hpack_parser_table.h:47
grpc_core::HPackTable::StaticMementos
Definition: hpack_parser_table.h:71
uint32_t
unsigned int uint32_t
Definition: stdint-msvc2008.h:80
grpc_core::HPackTable::max_bytes_
uint32_t max_bytes_
Definition: hpack_parser_table.h:121
grpc_core::HPackTable::Add
grpc_error_handle Add(Memento md) GRPC_MUST_USE_RESULT
Definition: hpack_parser_table.cc:127
grpc_core::HPackTable::EvictOne
void EvictOne()
Definition: hpack_parser_table.cc:86
grpc_core::HPackTable::MementoRingBuffer
Definition: hpack_parser_table.h:77
grpc_core::HPackTable::GetStaticMementos
static const StaticMementos & GetStaticMementos() GPR_ATTRIBUTE_NOINLINE
Definition: hpack_parser_table.cc:244
error.h
grpc_core::HPackTable::~HPackTable
~HPackTable()
grpc_core::HPackTable::entries_
MementoRingBuffer entries_
Definition: hpack_parser_table.h:125
stdint.h
grpc_core::ParsedMetadata< grpc_metadata_batch >
grpc_core::HPackTable
Definition: hpack_parser_table.h:36
grpc_core::hpack_constants::kInitialTableEntries
static constexpr uint32_t kInitialTableEntries
Definition: hpack_constants.h:36
grpc_core::hpack_constants::kLastStaticEntry
static constexpr uint32_t kLastStaticEntry
Definition: hpack_constants.h:30
grpc_core::HPackTable::static_metadata_
const StaticMementos & static_metadata_
Definition: hpack_parser_table.h:127
grpc_core::HPackTable::StaticMementos::StaticMementos
StaticMementos()
Definition: hpack_parser_table.cc:249
benchmark.md
md
Definition: benchmark.py:86
GRPC_MUST_USE_RESULT
#define GRPC_MUST_USE_RESULT
Definition: impl/codegen/port_platform.h:584
bytes
uint8 bytes[10]
Definition: bloaty/third_party/protobuf/src/google/protobuf/io/coded_stream_unittest.cc:153
grpc_core::HPackTable::MementoRingBuffer::max_entries
uint32_t max_entries() const
Definition: hpack_parser_table.h:93
index
int index
Definition: bloaty/third_party/protobuf/php/ext/google/protobuf/protobuf.h:1184
grpc_core::HPackTable::SetCurrentTableSize
grpc_error_handle SetCurrentTableSize(uint32_t bytes)
Definition: hpack_parser_table.cc:105
hpack_constants.h
grpc_core::HPackTable::MementoRingBuffer::num_entries
uint32_t num_entries() const
Definition: hpack_parser_table.h:94
grpc_core::hpack_constants::kInitialTableSize
static constexpr uint32_t kInitialTableSize
Definition: hpack_constants.h:27
grpc_core::HPackTable::SetMaxBytes
void SetMaxBytes(uint32_t max_bytes)
Definition: hpack_parser_table.cc:92
grpc_core::HPackTable::operator=
HPackTable & operator=(const HPackTable &)=delete
grpc_error
Definition: error_internal.h:42
regress.m
m
Definition: regress/regress.py:25
grpc_core::HPackTable::StaticMementos::memento
Memento memento[hpack_constants::kLastStaticEntry]
Definition: hpack_parser_table.h:73
grpc_core::HPackTable::LookupDynamic
const Memento * LookupDynamic(uint32_t index) const
Definition: hpack_parser_table.h:109
grpc_core::HPackTable::Lookup
const Memento * Lookup(uint32_t index) const
Definition: hpack_parser_table.h:50
GPR_ATTRIBUTE_NOINLINE
#define GPR_ATTRIBUTE_NOINLINE
Definition: impl/codegen/port_platform.h:684
port_platform.h


grpc
Author(s):
autogenerated on Thu Mar 13 2025 03:00:13