Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 1 | /* |
| 2 | * |
Craig Tiller | 0605995 | 2015-02-18 08:34:56 -0800 | [diff] [blame] | 3 | * Copyright 2015, Google Inc. |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 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 | |
David Garcia Quintas | ca28137 | 2015-06-08 20:07:39 -0700 | [diff] [blame] | 34 | #ifndef GRPC_COMPRESSION_H |
| 35 | #define GRPC_COMPRESSION_H |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 36 | |
David Garcia Quintas | 1c604fd | 2015-07-21 16:22:58 -0700 | [diff] [blame] | 37 | #include <stdlib.h> |
| 38 | |
David Garcia Quintas | beac88c | 2015-08-10 13:39:52 -0700 | [diff] [blame^] | 39 | #include <grpc/support/port_platform.h> |
| 40 | |
David Garcia Quintas | d7d9ce2 | 2015-06-30 23:29:03 -0700 | [diff] [blame] | 41 | #ifdef __cplusplus |
| 42 | extern "C" { |
| 43 | #endif |
| 44 | |
David Garcia Quintas | e29feb2 | 2015-06-15 18:08:13 -0700 | [diff] [blame] | 45 | /** To be used in channel arguments */ |
David Garcia Quintas | cadbf22 | 2015-07-17 15:33:13 -0700 | [diff] [blame] | 46 | #define GRPC_COMPRESSION_ALGORITHM_ARG "grpc.compression_algorithm" |
David Garcia Quintas | b58b346 | 2015-08-09 13:52:19 -0700 | [diff] [blame] | 47 | #define GRPC_COMPRESSION_ALGORITHM_STATE_ARG "grpc.compression_algorithm_state" |
David Garcia Quintas | e29feb2 | 2015-06-15 18:08:13 -0700 | [diff] [blame] | 48 | |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 49 | /* The various compression algorithms supported by GRPC */ |
| 50 | typedef enum { |
| 51 | GRPC_COMPRESS_NONE = 0, |
| 52 | GRPC_COMPRESS_DEFLATE, |
| 53 | GRPC_COMPRESS_GZIP, |
| 54 | /* TODO(ctiller): snappy */ |
| 55 | GRPC_COMPRESS_ALGORITHMS_COUNT |
| 56 | } grpc_compression_algorithm; |
| 57 | |
David Garcia Quintas | e29feb2 | 2015-06-15 18:08:13 -0700 | [diff] [blame] | 58 | typedef enum { |
| 59 | GRPC_COMPRESS_LEVEL_NONE = 0, |
| 60 | GRPC_COMPRESS_LEVEL_LOW, |
| 61 | GRPC_COMPRESS_LEVEL_MED, |
David Garcia Quintas | fc0fa33 | 2015-06-25 18:11:07 -0700 | [diff] [blame] | 62 | GRPC_COMPRESS_LEVEL_HIGH, |
| 63 | GRPC_COMPRESS_LEVEL_COUNT |
David Garcia Quintas | e29feb2 | 2015-06-15 18:08:13 -0700 | [diff] [blame] | 64 | } grpc_compression_level; |
| 65 | |
David Garcia Quintas | beac88c | 2015-08-10 13:39:52 -0700 | [diff] [blame^] | 66 | typedef struct grpc_compression_options { |
| 67 | gpr_uint32 enabled_algorithms_bitset; /**< All algs are enabled by default */ |
| 68 | grpc_compression_algorithm default_compression_algorithm; /**< for channel */ |
| 69 | } grpc_compression_options; |
| 70 | |
David Garcia Quintas | 1c604fd | 2015-07-21 16:22:58 -0700 | [diff] [blame] | 71 | /** Parses the first \a name_length bytes of \a name as a |
| 72 | * grpc_compression_algorithm instance, updating \a algorithm. Returns 1 upon |
| 73 | * success, 0 otherwise. */ |
| 74 | int grpc_compression_algorithm_parse(const char *name, size_t name_length, |
David Garcia Quintas | fc0fa33 | 2015-06-25 18:11:07 -0700 | [diff] [blame] | 75 | grpc_compression_algorithm *algorithm); |
| 76 | |
| 77 | /** Updates \a name with the encoding name corresponding to a valid \a |
| 78 | * algorithm. Returns 1 upon success, 0 otherwise. */ |
| 79 | int grpc_compression_algorithm_name(grpc_compression_algorithm algorithm, |
| 80 | char **name); |
| 81 | |
| 82 | /** Returns the compression level corresponding to \a algorithm. |
| 83 | * |
| 84 | * It abort()s for unknown algorithms. */ |
| 85 | grpc_compression_level grpc_compression_level_for_algorithm( |
Nicolas Noble | b7ebd3b | 2014-11-26 16:33:03 -0800 | [diff] [blame] | 86 | grpc_compression_algorithm algorithm); |
| 87 | |
David Garcia Quintas | fc0fa33 | 2015-06-25 18:11:07 -0700 | [diff] [blame] | 88 | /** Returns the compression algorithm corresponding to \a level. |
| 89 | * |
| 90 | * It abort()s for unknown levels . */ |
David Garcia Quintas | e29feb2 | 2015-06-15 18:08:13 -0700 | [diff] [blame] | 91 | grpc_compression_algorithm grpc_compression_algorithm_for_level( |
| 92 | grpc_compression_level level); |
| 93 | |
David Garcia Quintas | beac88c | 2015-08-10 13:39:52 -0700 | [diff] [blame^] | 94 | void grpc_compression_options_init(grpc_compression_options *opts); |
| 95 | |
| 96 | /** Mark \a algorithm as enabled in \a opts. */ |
| 97 | void grpc_compression_options_enable_algorithm( |
| 98 | grpc_compression_options *opts, grpc_compression_algorithm algorithm); |
| 99 | |
| 100 | /** Mark \a algorithm as disabled in \a opts. */ |
| 101 | void grpc_compression_options_disable_algorithm( |
| 102 | grpc_compression_options *opts, grpc_compression_algorithm algorithm); |
| 103 | |
| 104 | /** Returns true if \a algorithm is marked as enabled in \a opts. */ |
| 105 | int grpc_compression_options_is_algorithm_enabled( |
| 106 | const grpc_compression_options *opts, grpc_compression_algorithm algorithm); |
| 107 | |
David Garcia Quintas | d7d9ce2 | 2015-06-30 23:29:03 -0700 | [diff] [blame] | 108 | #ifdef __cplusplus |
| 109 | } |
| 110 | #endif |
| 111 | |
Craig Tiller | 9a57633 | 2015-06-17 10:21:49 -0700 | [diff] [blame] | 112 | #endif /* GRPC_COMPRESSION_H */ |