1 // Copyright 2021 gRPC authors.
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
7 // http://www.apache.org/licenses/LICENSE-2.0
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
15 #ifndef GRPC_CORE_EXT_TRANSPORT_CHTTP2_TRANSPORT_HPACK_ENCODER_TABLE_H
16 #define GRPC_CORE_EXT_TRANSPORT_CHTTP2_TRANSPORT_HPACK_ENCODER_TABLE_H
18 #include <grpc/support/port_platform.h>
20 #include "absl/container/inlined_vector.h"
22 #include "src/core/ext/transport/chttp2/transport/hpack_constants.h"
26 // Tracks the values available in the remote HPACK header table, and their
28 class HPackEncoderTable {
30 HPackEncoderTable() : elem_size_(hpack_constants::kInitialTableEntries) {}
32 // Reserve space in table for the new element, evict entries if needed.
33 // Return the new index of the element. Return 0 to indicate not adding to
35 uint32_t AllocateIndex(size_t element_size);
36 // Set the maximum table size. Return true if it changed.
37 bool SetMaxSize(uint32_t max_table_size);
38 // Get the current max table size
39 uint32_t max_size() const { return max_table_size_; }
40 // Get the current table size
41 uint32_t test_only_table_size() const { return table_size_; }
43 // Convert an element index into a dynamic index
44 uint32_t DynamicIndex(uint32_t index) const {
45 return 1 + hpack_constants::kLastStaticEntry + tail_remote_index_ +
48 // Check if an element index is convertable to a dynamic index
49 bool ConvertableToDynamicIndex(uint32_t index) const {
50 return index > tail_remote_index_;
55 void Rebuild(uint32_t capacity);
57 // one before the lowest usable table index
58 uint32_t tail_remote_index_ = 0;
59 uint32_t max_table_size_ = hpack_constants::kInitialTableSize;
60 uint32_t table_elems_ = 0;
61 uint32_t table_size_ = 0;
62 // The size of each element in the HPACK table.
63 absl::InlinedVector<uint16_t, hpack_constants::kInitialTableEntries>
67 } // namespace grpc_core
69 #endif // GRPC_CORE_EXT_TRANSPORT_CHTTP2_TRANSPORT_HPACK_ENCODER_TABLE_H