aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/core/compression/algorithm.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/core/compression/algorithm.c')
-rw-r--r--src/core/compression/algorithm.c103
1 files changed, 42 insertions, 61 deletions
diff --git a/src/core/compression/algorithm.c b/src/core/compression/algorithm.c
index 2627761d90..8adde13b1e 100644
--- a/src/core/compression/algorithm.c
+++ b/src/core/compression/algorithm.c
@@ -37,41 +37,30 @@
#include <grpc/compression.h>
#include <grpc/support/useful.h>
-int
-grpc_compression_algorithm_parse (const char *name, size_t name_length, grpc_compression_algorithm * algorithm)
-{
+int grpc_compression_algorithm_parse(const char *name, size_t name_length,
+ grpc_compression_algorithm *algorithm) {
/* we use strncmp not only because it's safer (even though in this case it
* doesn't matter, given that we are comparing against string literals, but
* because this way we needn't have "name" nil-terminated (useful for slice
* data, for example) */
- if (name_length == 0)
- {
- return 0;
- }
- if (strncmp (name, "identity", name_length) == 0)
- {
- *algorithm = GRPC_COMPRESS_NONE;
- }
- else if (strncmp (name, "gzip", name_length) == 0)
- {
- *algorithm = GRPC_COMPRESS_GZIP;
- }
- else if (strncmp (name, "deflate", name_length) == 0)
- {
- *algorithm = GRPC_COMPRESS_DEFLATE;
- }
- else
- {
- return 0;
- }
+ if (name_length == 0) {
+ return 0;
+ }
+ if (strncmp(name, "identity", name_length) == 0) {
+ *algorithm = GRPC_COMPRESS_NONE;
+ } else if (strncmp(name, "gzip", name_length) == 0) {
+ *algorithm = GRPC_COMPRESS_GZIP;
+ } else if (strncmp(name, "deflate", name_length) == 0) {
+ *algorithm = GRPC_COMPRESS_DEFLATE;
+ } else {
+ return 0;
+ }
return 1;
}
-int
-grpc_compression_algorithm_name (grpc_compression_algorithm algorithm, char **name)
-{
- switch (algorithm)
- {
+int grpc_compression_algorithm_name(grpc_compression_algorithm algorithm,
+ char **name) {
+ switch (algorithm) {
case GRPC_COMPRESS_NONE:
*name = "identity";
break;
@@ -83,17 +72,15 @@ grpc_compression_algorithm_name (grpc_compression_algorithm algorithm, char **na
break;
default:
return 0;
- }
+ }
return 1;
}
/* TODO(dgq): Add the ability to specify parameters to the individual
* compression algorithms */
-grpc_compression_algorithm
-grpc_compression_algorithm_for_level (grpc_compression_level level)
-{
- switch (level)
- {
+grpc_compression_algorithm grpc_compression_algorithm_for_level(
+ grpc_compression_level level) {
+ switch (level) {
case GRPC_COMPRESS_LEVEL_NONE:
return GRPC_COMPRESS_NONE;
case GRPC_COMPRESS_LEVEL_LOW:
@@ -102,45 +89,39 @@ grpc_compression_algorithm_for_level (grpc_compression_level level)
return GRPC_COMPRESS_DEFLATE;
default:
/* we shouldn't be making it here */
- abort ();
- }
+ abort();
+ }
}
-grpc_compression_level
-grpc_compression_level_for_algorithm (grpc_compression_algorithm algorithm)
-{
+grpc_compression_level grpc_compression_level_for_algorithm(
+ grpc_compression_algorithm algorithm) {
grpc_compression_level clevel;
- for (clevel = GRPC_COMPRESS_LEVEL_NONE; clevel < GRPC_COMPRESS_LEVEL_COUNT; ++clevel)
- {
- if (grpc_compression_algorithm_for_level (clevel) == algorithm)
- {
- return clevel;
- }
+ for (clevel = GRPC_COMPRESS_LEVEL_NONE; clevel < GRPC_COMPRESS_LEVEL_COUNT;
+ ++clevel) {
+ if (grpc_compression_algorithm_for_level(clevel) == algorithm) {
+ return clevel;
}
- abort ();
+ }
+ abort();
}
-void
-grpc_compression_options_init (grpc_compression_options * opts)
-{
+void grpc_compression_options_init(grpc_compression_options *opts) {
opts->enabled_algorithms_bitset = (1u << GRPC_COMPRESS_ALGORITHMS_COUNT) - 1;
opts->default_compression_algorithm = GRPC_COMPRESS_NONE;
}
-void
-grpc_compression_options_enable_algorithm (grpc_compression_options * opts, grpc_compression_algorithm algorithm)
-{
- GPR_BITSET (&opts->enabled_algorithms_bitset, algorithm);
+void grpc_compression_options_enable_algorithm(
+ grpc_compression_options *opts, grpc_compression_algorithm algorithm) {
+ GPR_BITSET(&opts->enabled_algorithms_bitset, algorithm);
}
-void
-grpc_compression_options_disable_algorithm (grpc_compression_options * opts, grpc_compression_algorithm algorithm)
-{
- GPR_BITCLEAR (&opts->enabled_algorithms_bitset, algorithm);
+void grpc_compression_options_disable_algorithm(
+ grpc_compression_options *opts, grpc_compression_algorithm algorithm) {
+ GPR_BITCLEAR(&opts->enabled_algorithms_bitset, algorithm);
}
-int
-grpc_compression_options_is_algorithm_enabled (const grpc_compression_options * opts, grpc_compression_algorithm algorithm)
-{
- return GPR_BITGET (opts->enabled_algorithms_bitset, algorithm);
+int grpc_compression_options_is_algorithm_enabled(
+ const grpc_compression_options *opts,
+ grpc_compression_algorithm algorithm) {
+ return GPR_BITGET(opts->enabled_algorithms_bitset, algorithm);
}