| 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 (not sorted by |
| 56 | * compression level) */ |
| 57 | typedef enum { |
| 58 | GRPC_COMPRESS_NONE = 0, |
| 59 | GRPC_COMPRESS_DEFLATE, |
| 60 | GRPC_COMPRESS_GZIP, |
| 61 | /* EXPERIMENTAL: Stream compression is currently experimental. */ |
| 62 | GRPC_COMPRESS_STREAM_GZIP, |
| 63 | /* TODO(ctiller): snappy */ |
| 64 | GRPC_COMPRESS_ALGORITHMS_COUNT |
| 65 | } grpc_compression_algorithm; |
| 66 | |
| 67 | /** Compression levels allow a party with knowledge of its peer's accepted |
| 68 | * encodings to request compression in an abstract way. The level-algorithm |
| 69 | * mapping is performed internally and depends on the peer's supported |
| 70 | * compression algorithms. */ |
| 71 | typedef enum { |
| 72 | GRPC_COMPRESS_LEVEL_NONE = 0, |
| 73 | GRPC_COMPRESS_LEVEL_LOW, |
| 74 | GRPC_COMPRESS_LEVEL_MED, |
| 75 | GRPC_COMPRESS_LEVEL_HIGH, |
| 76 | GRPC_COMPRESS_LEVEL_COUNT |
| 77 | } grpc_compression_level; |
| 78 | |
| 79 | typedef struct grpc_compression_options { |
| 80 | /** All algs are enabled by default. This option corresponds to the channel |
| 81 | * argument key behind \a GRPC_COMPRESSION_CHANNEL_ENABLED_ALGORITHMS_BITSET |
| 82 | */ |
| 83 | uint32_t enabled_algorithms_bitset; |
| 84 | |
| 85 | /** The default compression level. It'll be used in the absence of call |
| 86 | * specific settings. This option corresponds to the channel |
| 87 | * argument key behind \a GRPC_COMPRESSION_CHANNEL_DEFAULT_LEVEL. If present, |
| 88 | * takes precedence over \a default_algorithm. |
| 89 | * TODO(dgq): currently only available for server channels. */ |
| 90 | struct grpc_compression_options_default_level { |
| 91 | int is_set; |
| 92 | grpc_compression_level level; |
| 93 | } default_level; |
| 94 | |
| 95 | /** The default message compression algorithm. It'll be used in the absence of |
| 96 | * call specific settings. This option corresponds to the channel argument key |
| 97 | * behind \a GRPC_COMPRESSION_CHANNEL_DEFAULT_ALGORITHM. */ |
| 98 | struct grpc_compression_options_default_algorithm { |
| 99 | int is_set; |
| 100 | grpc_compression_algorithm algorithm; |
| 101 | } default_algorithm; |
| 102 | } grpc_compression_options; |
| 103 | |
| 104 | #ifdef __cplusplus |
| 105 | } |
| 106 | #endif |
| 107 | |
| 108 | #endif /* GRPC_IMPL_CODEGEN_COMPRESSION_TYPES_H */ |
| 109 | |