gRPC  0.6.0
 All Classes Namespaces Functions Variables Enumerations Properties Pages
stream_encoder.h
1 /*
2  *
3  * Copyright 2015, Google Inc.
4  * All rights reserved.
5  *
6  * Redistribution and use in source and binary forms, with or without
7  * modification, are permitted provided that the following conditions are
8  * met:
9  *
10  * * Redistributions of source code must retain the above copyright
11  * notice, this list of conditions and the following disclaimer.
12  * * Redistributions in binary form must reproduce the above
13  * copyright notice, this list of conditions and the following disclaimer
14  * in the documentation and/or other materials provided with the
15  * distribution.
16  * * Neither the name of Google Inc. nor the names of its
17  * contributors may be used to endorse or promote products derived from
18  * this software without specific prior written permission.
19  *
20  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
23  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
24  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
26  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31  *
32  */
33 
34 #ifndef GRPC_INTERNAL_CORE_TRANSPORT_CHTTP2_STREAM_ENCODER_H
35 #define GRPC_INTERNAL_CORE_TRANSPORT_CHTTP2_STREAM_ENCODER_H
36 
37 #include "src/core/transport/chttp2/frame.h"
38 #include "src/core/transport/metadata.h"
39 #include "src/core/transport/stream_op.h"
40 #include <grpc/support/port_platform.h>
41 #include <grpc/support/slice.h>
42 #include <grpc/support/slice_buffer.h>
43 
44 #define GRPC_CHTTP2_HPACKC_NUM_FILTERS 256
45 #define GRPC_CHTTP2_HPACKC_NUM_VALUES 256
46 #define GRPC_CHTTP2_HPACKC_MAX_TABLE_ELEMS (4096 / 32)
47 
48 typedef struct {
49  gpr_uint32 filter_elems_sum;
50  /* one before the lowest usable table index */
51  gpr_uint32 tail_remote_index;
52  gpr_uint16 table_size;
53  gpr_uint16 table_elems;
54 
55  /* filter tables for elems: this tables provides an approximate
56  popularity count for particular hashes, and are used to determine whether
57  a new literal should be added to the compression table or not.
58  They track a single integer that counts how often a particular value has
59  been seen. When that count reaches max (255), all values are halved. */
60  gpr_uint8 filter_elems[GRPC_CHTTP2_HPACKC_NUM_FILTERS];
61 
62  /* metadata context */
63  grpc_mdctx *mdctx;
64  /* the string 'grpc-timeout' */
65  grpc_mdstr *timeout_key_str;
66 
67  /* entry tables for keys & elems: these tables track values that have been
68  seen and *may* be in the decompressor table */
69  grpc_mdstr *entries_keys[GRPC_CHTTP2_HPACKC_NUM_VALUES];
70  grpc_mdelem *entries_elems[GRPC_CHTTP2_HPACKC_NUM_VALUES];
71  gpr_uint32 indices_keys[GRPC_CHTTP2_HPACKC_NUM_VALUES];
72  gpr_uint32 indices_elems[GRPC_CHTTP2_HPACKC_NUM_VALUES];
73 
74  gpr_uint16 table_elem_size[GRPC_CHTTP2_HPACKC_MAX_TABLE_ELEMS];
76 
77 void grpc_chttp2_hpack_compressor_init(grpc_chttp2_hpack_compressor *c,
78  grpc_mdctx *mdctx);
79 void grpc_chttp2_hpack_compressor_destroy(grpc_chttp2_hpack_compressor *c);
80 
81 /* select stream ops to be encoded, moving them from inops to outops, and
82  moving subsequent ops in inops forward in the queue */
83 gpr_uint32 grpc_chttp2_preencode(grpc_stream_op *inops, size_t *inops_count,
84  gpr_uint32 max_flow_controlled_bytes,
85  grpc_stream_op_buffer *outops);
86 
87 /* encode stream ops to output */
88 void grpc_chttp2_encode(grpc_stream_op *ops, size_t ops_count, int eof,
89  gpr_uint32 stream_id,
90  grpc_chttp2_hpack_compressor *compressor,
91  gpr_slice_buffer *output);
92 
93 #endif /* GRPC_INTERNAL_CORE_TRANSPORT_CHTTP2_STREAM_ENCODER_H */
Definition: stream_encoder.h:48
Definition: metadata.h:70
Definition: slice_buffer.h:48
Definition: metadata.c:83
Definition: metadata.h:78
Definition: stream_op.h:117
Definition: stream_op.h:133