1 /* 2 * 3 * Copyright 2016 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_IMPL_COMPRESSION_TYPES_H 20 #define GRPC_IMPL_COMPRESSION_TYPES_H 21 22 // IWYU pragma: private, include <grpc/compression.h> 23 // IWYU pragma: friend "src/.*" 24 25 #include <grpc/support/port_platform.h> 26 27 #ifdef __cplusplus 28 extern "C" { 29 #endif 30 31 /** To be used as initial metadata key for the request of a concrete compression 32 * algorithm */ 33 #define GRPC_COMPRESSION_REQUEST_ALGORITHM_MD_KEY \ 34 "grpc-internal-encoding-request" 35 36 /** To be used in channel arguments. 37 * 38 * \addtogroup grpc_arg_keys 39 * \{ */ 40 /** Default compression algorithm for the channel. 41 * Its value is an int from the \a grpc_compression_algorithm enum. */ 42 #define GRPC_COMPRESSION_CHANNEL_DEFAULT_ALGORITHM \ 43 "grpc.default_compression_algorithm" 44 /** Default compression level for the channel. 45 * Its value is an int from the \a grpc_compression_level enum. */ 46 #define GRPC_COMPRESSION_CHANNEL_DEFAULT_LEVEL "grpc.default_compression_level" 47 /** Compression algorithms supported by the channel. 48 * Its value is a bitset (an int). Bits correspond to algorithms in \a 49 * grpc_compression_algorithm. For example, its LSB corresponds to 50 * GRPC_COMPRESS_NONE, the next bit to GRPC_COMPRESS_DEFLATE, etc. 51 * Unset bits disable support for the algorithm. By default all algorithms are 52 * supported. It's not possible to disable GRPC_COMPRESS_NONE (the attempt will 53 * be ignored). */ 54 #define GRPC_COMPRESSION_CHANNEL_ENABLED_ALGORITHMS_BITSET \ 55 "grpc.compression_enabled_algorithms_bitset" 56 /** \} */ 57 58 /** The various compression algorithms supported by gRPC (not sorted by 59 * compression level) */ 60 typedef enum { 61 GRPC_COMPRESS_NONE = 0, 62 GRPC_COMPRESS_DEFLATE, 63 GRPC_COMPRESS_GZIP, 64 /* TODO(ctiller): snappy */ 65 GRPC_COMPRESS_ALGORITHMS_COUNT 66 } grpc_compression_algorithm; 67 68 /** Compression levels allow a party with knowledge of its peer's accepted 69 * encodings to request compression in an abstract way. The level-algorithm 70 * mapping is performed internally and depends on the peer's supported 71 * compression algorithms. */ 72 typedef enum { 73 GRPC_COMPRESS_LEVEL_NONE = 0, 74 GRPC_COMPRESS_LEVEL_LOW, 75 GRPC_COMPRESS_LEVEL_MED, 76 GRPC_COMPRESS_LEVEL_HIGH, 77 GRPC_COMPRESS_LEVEL_COUNT 78 } grpc_compression_level; 79 80 typedef struct grpc_compression_options { 81 /** All algs are enabled by default. This option corresponds to the channel 82 * argument key behind \a GRPC_COMPRESSION_CHANNEL_ENABLED_ALGORITHMS_BITSET 83 */ 84 uint32_t enabled_algorithms_bitset; 85 86 /** The default compression level. It'll be used in the absence of call 87 * specific settings. This option corresponds to the channel 88 * argument key behind \a GRPC_COMPRESSION_CHANNEL_DEFAULT_LEVEL. If present, 89 * takes precedence over \a default_algorithm. 90 * TODO(dgq): currently only available for server channels. */ 91 struct grpc_compression_options_default_level { 92 int is_set; 93 grpc_compression_level level; 94 } default_level; 95 96 /** The default message compression algorithm. It'll be used in the absence of 97 * call specific settings. This option corresponds to the channel argument key 98 * behind \a GRPC_COMPRESSION_CHANNEL_DEFAULT_ALGORITHM. */ 99 struct grpc_compression_options_default_algorithm { 100 int is_set; 101 grpc_compression_algorithm algorithm; 102 } default_algorithm; 103 } grpc_compression_options; 104 105 #ifdef __cplusplus 106 } 107 #endif 108 109 #endif /* GRPC_IMPL_COMPRESSION_TYPES_H */ 110