diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/core/channel/channel_args.c | 42 | ||||
-rw-r--r-- | src/core/channel/channel_args.h | 14 |
2 files changed, 56 insertions, 0 deletions
diff --git a/src/core/channel/channel_args.c b/src/core/channel/channel_args.c index c430b56fa2..77449c0df5 100644 --- a/src/core/channel/channel_args.c +++ b/src/core/channel/channel_args.c @@ -37,6 +37,7 @@ #include <grpc/support/alloc.h> #include <grpc/support/string_util.h> +#include <grpc/support/useful.h> #include <string.h> @@ -146,3 +147,44 @@ grpc_channel_args *grpc_channel_args_set_compression_algorithm( tmp.value.integer = algorithm; return grpc_channel_args_copy_and_add(a, &tmp, 1); } + +static gpr_uint32 find_compression_algorithm_states_bitset( + const grpc_channel_args *a) { + size_t i; + gpr_uint32 states_bitset = 0; + if (a == NULL) return 0; + for (i = 0; i < a->num_args; ++i) { + if (a->args[i].type == GRPC_ARG_INTEGER && + !strcmp(GRPC_COMPRESSION_ALGORITHM_STATE_ARG, a->args[i].key)) { + states_bitset = a->args[i].value.integer; + break; + } + } + return states_bitset; +} + +grpc_channel_args *grpc_channel_args_compression_algorithm_set_state( + grpc_channel_args *a, + grpc_compression_algorithm algorithm, + int state) { + gpr_uint32 states_bitset = find_compression_algorithm_states_bitset(a); + grpc_arg tmp; + + if (state != 0) { + GPR_BITSET(&states_bitset, algorithm); + } else { + GPR_BITCLEAR(&states_bitset, algorithm); + } + + tmp.type = GRPC_ARG_INTEGER; + tmp.key = GRPC_COMPRESSION_ALGORITHM_STATE_ARG; + tmp.value.integer = states_bitset; + return grpc_channel_args_copy_and_add(a, &tmp, 1); +} + +int grpc_channel_args_compression_algorithm_get_state( + grpc_channel_args *a, + grpc_compression_algorithm algorithm) { + const gpr_uint32 states_bitset = find_compression_algorithm_states_bitset(a); + return GPR_BITGET(states_bitset, algorithm); +} diff --git a/src/core/channel/channel_args.h b/src/core/channel/channel_args.h index 7e6ddd3997..f1a75117af 100644 --- a/src/core/channel/channel_args.h +++ b/src/core/channel/channel_args.h @@ -67,4 +67,18 @@ grpc_compression_algorithm grpc_channel_args_get_compression_algorithm( grpc_channel_args *grpc_channel_args_set_compression_algorithm( grpc_channel_args *a, grpc_compression_algorithm algorithm); +/** Sets the support for the given compression algorithm. By default, all + * compression algorithms are enabled. Disabling an algorithm set by + * grpc_channel_args_set_compression_algorithm disables compression altogether + * */ +grpc_channel_args *grpc_channel_args_compression_algorithm_set_state( + grpc_channel_args *a, + grpc_compression_algorithm algorithm, + int enabled); + +/** Returns the state (true for enabled, false for disabled) for \a algorithm */ +int grpc_channel_args_compression_algorithm_get_state( + grpc_channel_args *a, + grpc_compression_algorithm algorithm); + #endif /* GRPC_INTERNAL_CORE_CHANNEL_CHANNEL_ARGS_H */ |