grpc_channel_args *grpc_channel_args_compression_algorithm_set_state( grpc_channel_args **a, grpc_compression_algorithm algorithm, int state) { int *states_arg; grpc_channel_args *result = *a; const int states_arg_found = find_compression_algorithm_states_bitset(*a, &states_arg); if (states_arg_found) { if (state != 0) { GPR_BITSET((unsigned *)states_arg, algorithm); } else { GPR_BITCLEAR((unsigned *)states_arg, algorithm); } } else { /* create a new arg */ grpc_arg tmp; tmp.type = GRPC_ARG_INTEGER; tmp.key = GRPC_COMPRESSION_ALGORITHM_STATE_ARG; /* all enabled by default */ tmp.value.integer = (1u << GRPC_COMPRESS_ALGORITHMS_COUNT) - 1; if (state != 0) { GPR_BITSET((unsigned *)&tmp.value.integer, algorithm); } else { GPR_BITCLEAR((unsigned *)&tmp.value.integer, algorithm); } result = grpc_channel_args_copy_and_add(*a, &tmp, 1); grpc_channel_args_destroy(*a); *a = result; } return result; }
int main(int argc, char **argv) { int four[4]; int five[5]; uint32_t bitset = 0; grpc_test_init(argc, argv); GPR_ASSERT(GPR_MIN(1, 2) == 1); GPR_ASSERT(GPR_MAX(1, 2) == 2); GPR_ASSERT(GPR_MIN(2, 1) == 1); GPR_ASSERT(GPR_MAX(2, 1) == 2); GPR_ASSERT(GPR_CLAMP(1, 0, 2) == 1); GPR_ASSERT(GPR_CLAMP(0, 0, 2) == 0); GPR_ASSERT(GPR_CLAMP(2, 0, 2) == 2); GPR_ASSERT(GPR_CLAMP(-1, 0, 2) == 0); GPR_ASSERT(GPR_CLAMP(3, 0, 2) == 2); GPR_ASSERT(GPR_ROTL((uint32_t)0x80000001, 1) == 3); GPR_ASSERT(GPR_ROTR((uint32_t)0x80000001, 1) == 0xc0000000); GPR_ASSERT(GPR_ARRAY_SIZE(four) == 4); GPR_ASSERT(GPR_ARRAY_SIZE(five) == 5); GPR_ASSERT(GPR_BITCOUNT((1u << 31) - 1) == 31); GPR_ASSERT(GPR_BITCOUNT(1u << 3) == 1); GPR_ASSERT(GPR_BITCOUNT(0) == 0); GPR_ASSERT(GPR_BITSET(&bitset, 3) == 8); GPR_ASSERT(GPR_BITCOUNT(bitset) == 1); GPR_ASSERT(GPR_BITGET(bitset, 3) == 1); GPR_ASSERT(GPR_BITSET(&bitset, 1) == 10); GPR_ASSERT(GPR_BITCOUNT(bitset) == 2); GPR_ASSERT(GPR_BITCLEAR(&bitset, 3) == 2); GPR_ASSERT(GPR_BITCOUNT(bitset) == 1); GPR_ASSERT(GPR_BITGET(bitset, 3) == 0); return 0; }
grpc_channel_args *grpc_channel_args_stream_compression_algorithm_set_state( grpc_exec_ctx *exec_ctx, grpc_channel_args **a, grpc_stream_compression_algorithm algorithm, int state) { int *states_arg = NULL; grpc_channel_args *result = *a; const int states_arg_found = find_stream_compression_algorithm_states_bitset(*a, &states_arg); if (grpc_channel_args_get_stream_compression_algorithm(*a) == algorithm && state == 0) { const char *algo_name = NULL; GPR_ASSERT(grpc_stream_compression_algorithm_name(algorithm, &algo_name) != 0); gpr_log(GPR_ERROR, "Tried to disable default stream compression algorithm '%s'. The " "operation has been ignored.", algo_name); } else if (states_arg_found) { if (state != 0) { GPR_BITSET((unsigned *)states_arg, algorithm); } else if (algorithm != GRPC_STREAM_COMPRESS_NONE) { GPR_BITCLEAR((unsigned *)states_arg, algorithm); } } else { /* create a new arg */ grpc_arg tmp; tmp.type = GRPC_ARG_INTEGER; tmp.key = (char *)GRPC_STREAM_COMPRESSION_CHANNEL_ENABLED_ALGORITHMS_BITSET; /* all enabled by default */ tmp.value.integer = (1u << GRPC_STREAM_COMPRESS_ALGORITHMS_COUNT) - 1; if (state != 0) { GPR_BITSET((unsigned *)&tmp.value.integer, algorithm); } else if (algorithm != GRPC_STREAM_COMPRESS_NONE) { GPR_BITCLEAR((unsigned *)&tmp.value.integer, algorithm); } result = grpc_channel_args_copy_and_add(*a, &tmp, 1); grpc_channel_args_destroy(exec_ctx, *a); *a = result; } return result; }
void grpc_compression_options_disable_algorithm( grpc_compression_options *opts, grpc_compression_algorithm algorithm) { GPR_BITCLEAR(&opts->enabled_algorithms_bitset, algorithm); }