diff options
Diffstat (limited to 'src/core/compression/algorithm.c')
-rw-r--r-- | src/core/compression/algorithm.c | 46 |
1 files changed, 38 insertions, 8 deletions
diff --git a/src/core/compression/algorithm.c b/src/core/compression/algorithm.c index 4db48df6cb..e426241d0a 100644 --- a/src/core/compression/algorithm.c +++ b/src/core/compression/algorithm.c @@ -32,21 +32,39 @@ */ #include <stdlib.h> +#include <string.h> #include <grpc/compression.h> -const char *grpc_compression_algorithm_name( - grpc_compression_algorithm algorithm) { +int grpc_compression_algorithm_parse(const char* name, + grpc_compression_algorithm *algorithm) { + if (strcmp(name, "none") == 0) { + *algorithm = GRPC_COMPRESS_NONE; + } else if (strcmp(name, "gzip") == 0) { + *algorithm = GRPC_COMPRESS_GZIP; + } else if (strcmp(name, "deflate") == 0) { + *algorithm = GRPC_COMPRESS_DEFLATE; + } else { + return 0; + } + return 1; +} + +int grpc_compression_algorithm_name(grpc_compression_algorithm algorithm, + char **name) { switch (algorithm) { case GRPC_COMPRESS_NONE: - return "none"; + *name = "none"; + break; case GRPC_COMPRESS_DEFLATE: - return "deflate"; + *name = "deflate"; + break; case GRPC_COMPRESS_GZIP: - return "gzip"; - case GRPC_COMPRESS_ALGORITHMS_COUNT: - return "error"; + *name = "gzip"; + break; + default: + return 0; } - return "error"; + return 1; } /* TODO(dgq): Add the ability to specify parameters to the individual @@ -65,3 +83,15 @@ grpc_compression_algorithm grpc_compression_algorithm_for_level( abort(); } } + +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; + } + } + abort(); +} |