GRPC Core  9.0.0
hpack_encoder.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_ENCODER_H
20 #define GRPC_CORE_EXT_TRANSPORT_CHTTP2_TRANSPORT_HPACK_ENCODER_H
21 
23 
24 #include <grpc/slice.h>
25 #include <grpc/slice_buffer.h>
30 
31 // This should be <= 8. We use 6 to save space.
32 #define GRPC_CHTTP2_HPACKC_NUM_VALUES_BITS 6
33 #define GRPC_CHTTP2_HPACKC_NUM_VALUES (1 << GRPC_CHTTP2_HPACKC_NUM_VALUES_BITS)
34 /* initial table size, per spec */
35 #define GRPC_CHTTP2_HPACKC_INITIAL_TABLE_SIZE 4096
36 /* maximum table size we'll actually use */
37 #define GRPC_CHTTP2_HPACKC_MAX_TABLE_SIZE (1024 * 1024)
38 
40 
42  uint32_t max_table_size;
43  uint32_t max_table_elems;
44  uint32_t cap_table_elems;
47  uint32_t max_usable_size;
48  /* one before the lowest usable table index */
50  uint32_t table_size;
51  uint32_t table_elems;
52  uint16_t* table_elem_size;
56 
57  /* filter tables for elems: this tables provides an approximate
58  popularity count for particular hashes, and are used to determine whether
59  a new literal should be added to the compression table or not.
60  They track a single integer that counts how often a particular value has
61  been seen. When that count reaches max (255), all values are halved. */
62  uint32_t filter_elems_sum;
64 
65  /* entry tables for keys & elems: these tables track values that have been
66  seen and *may* be in the decompressor table */
67  struct {
68  struct {
70  uint32_t index;
72  } elem_table; /* Metadata table management */
73  struct {
74  struct {
75  /* Only store the slice refcount - we do not need the byte buffer or
76  length of the slice since we only need to store a mapping between the
77  identity of the slice and the corresponding HPACK index. Since the
78  slice *must* be static or interned, the refcount is sufficient to
79  establish identity. */
81  uint32_t index;
83  } key_table; /* Key table management */
84 };
85 
89  grpc_chttp2_hpack_compressor* c, uint32_t max_table_size);
91  grpc_chttp2_hpack_compressor* c, uint32_t max_table_size);
92 
93 typedef struct {
94  uint32_t stream_id;
95  bool is_eof;
100 
102  grpc_mdelem** extra_headers,
103  size_t extra_headers_size,
104  grpc_metadata_batch* metadata,
105  const grpc_encode_header_options* options,
106  grpc_slice_buffer* outbuf);
107 
108 #endif /* GRPC_CORE_EXT_TRANSPORT_CHTTP2_TRANSPORT_HPACK_ENCODER_H */
Definition: trace.h:61
void grpc_chttp2_hpack_compressor_destroy(grpc_chttp2_hpack_compressor *c)
Definition: hpack_encoder.cc:760
#define GRPC_CHTTP2_HPACKC_NUM_VALUES
Definition: hpack_encoder.h:33
void grpc_chttp2_hpack_compressor_set_max_usable_size(grpc_chttp2_hpack_compressor *c, uint32_t max_table_size)
Definition: hpack_encoder.cc:771
void grpc_chttp2_hpack_compressor_init(grpc_chttp2_hpack_compressor *c)
Definition: hpack_encoder.cc:749
grpc_core::TraceFlag grpc_http_trace
void grpc_chttp2_encode_header(grpc_chttp2_hpack_compressor *c, grpc_mdelem **extra_headers, size_t extra_headers_size, grpc_metadata_batch *metadata, const grpc_encode_header_options *options, grpc_slice_buffer *outbuf)
Definition: hpack_encoder.cc:822
void grpc_chttp2_hpack_compressor_set_max_table_size(grpc_chttp2_hpack_compressor *c, uint32_t max_table_size)
Definition: hpack_encoder.cc:797
Definition: hpack_encoder.h:41
struct grpc_chttp2_hpack_compressor::@3 elem_table
uint32_t table_elems
Definition: hpack_encoder.h:51
uint16_t * table_elem_size
Definition: hpack_encoder.h:52
uint32_t cap_table_elems
Definition: hpack_encoder.h:44
uint32_t index
Definition: hpack_encoder.h:70
uint32_t max_table_elems
Definition: hpack_encoder.h:43
uint32_t table_size
Definition: hpack_encoder.h:50
uint32_t tail_remote_index
Definition: hpack_encoder.h:49
uint32_t filter_elems_sum
Definition: hpack_encoder.h:62
grpc_mdelem value
Definition: hpack_encoder.h:69
uint32_t max_usable_size
maximum number of bytes we'll use for the decode table (to guard against peers ooming us by setting d...
Definition: hpack_encoder.h:47
uint8_t filter_elems[(1<< 6)]
Definition: hpack_encoder.h:63
struct grpc_chttp2_hpack_compressor::@4 key_table
uint32_t max_table_size
Definition: hpack_encoder.h:42
struct grpc_chttp2_hpack_compressor::@3::@5 entries[(1<< 6)]
grpc_slice_refcount * value
Definition: hpack_encoder.h:80
uint8_t advertise_table_size_change
if non-zero, advertise to the decoder that we'll start using a table of this size
Definition: hpack_encoder.h:55
Definition: hpack_encoder.h:93
uint32_t stream_id
Definition: hpack_encoder.h:94
bool is_eof
Definition: hpack_encoder.h:95
bool use_true_binary_metadata
Definition: hpack_encoder.h:96
grpc_transport_one_way_stats * stats
Definition: hpack_encoder.h:98
size_t max_frame_size
Definition: hpack_encoder.h:97
Definition: metadata.h:98
Definition: metadata_batch.h:49
Represents an expandable array of slices, to be interpreted as a single item.
Definition: slice.h:78
Definition: slice_internal.h:100
Definition: transport.h:122