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