diff options
Diffstat (limited to 'src/core')
-rw-r--r-- | src/core/lib/compression/compression.cc | 28 | ||||
-rw-r--r-- | src/core/lib/compression/compression_internal.cc | 54 | ||||
-rw-r--r-- | src/core/lib/compression/compression_internal.h | 34 | ||||
-rw-r--r-- | src/core/lib/surface/channel.cc | 8 |
4 files changed, 24 insertions, 100 deletions
diff --git a/src/core/lib/compression/compression.cc b/src/core/lib/compression/compression.cc index 88fb37ffe2..a5b123b4e2 100644 --- a/src/core/lib/compression/compression.cc +++ b/src/core/lib/compression/compression.cc @@ -87,22 +87,18 @@ grpc_compression_algorithm grpc_compression_algorithm_for_level( grpc_compression_algorithm algo; if (level == GRPC_COMPRESS_LEVEL_NONE) { return GRPC_COMPRESS_NONE; - } else if (level <= GRPC_COMPRESS_LEVEL_MESSAGE_HIGH) { - GPR_ASSERT( - grpc_compression_algorithm_from_message_stream_compression_algorithm( - &algo, - grpc_message_compression_algorithm_for_level( - grpc_compression_level_to_message_compression_level(level), - grpc_compression_bitset_to_message_bitset(accepted_encodings)), - (grpc_stream_compression_algorithm)0)); - return algo; - } else if (level <= GRPC_COMPRESS_LEVEL_STREAM_HIGH) { - GPR_ASSERT( - grpc_compression_algorithm_from_message_stream_compression_algorithm( - &algo, (grpc_message_compression_algorithm)0, - grpc_stream_compression_algorithm_for_level( - grpc_compression_level_to_stream_compression_level(level), - grpc_compression_bitset_to_stream_bitset(accepted_encodings)))); + } else if (level <= GRPC_COMPRESS_LEVEL_HIGH) { + // TODO(mxyan): Design algorithm to select from all algorithms, including + // stream compression algorithm + if (!grpc_compression_algorithm_from_message_stream_compression_algorithm( + &algo, + grpc_message_compression_algorithm_for_level( + level, + grpc_compression_bitset_to_message_bitset(accepted_encodings)), + static_cast<grpc_stream_compression_algorithm>(0))){ + gpr_log(GPR_ERROR, "Parse compression level error"); + return GRPC_COMPRESS_NONE; + } return algo; } else { gpr_log(GPR_ERROR, "Unknown compression level: %d", level); diff --git a/src/core/lib/compression/compression_internal.cc b/src/core/lib/compression/compression_internal.cc index 8352ad255e..263cdf06eb 100644 --- a/src/core/lib/compression/compression_internal.cc +++ b/src/core/lib/compression/compression_internal.cc @@ -76,29 +76,6 @@ grpc_mdelem grpc_stream_compression_encoding_mdelem( /* Interfaces performing transformation between compression algorithms and * levels. */ -grpc_message_compression_level -grpc_compression_level_to_message_compression_level( - grpc_compression_level level) { - if (level >= GRPC_COMPRESS_LEVEL_COUNT) { - return GRPC_MESSAGE_COMPRESS_LEVEL_NONE; - } - return (grpc_message_compression_level)( - (uint32_t)(level - GRPC_COMPRESS_LEVEL_NONE) + - (uint32_t)GRPC_MESSAGE_COMPRESS_LEVEL_NONE); -} - -grpc_stream_compression_level -grpc_compression_level_to_stream_compression_level( - grpc_compression_level level) { - if (level >= GRPC_COMPRESS_LEVEL_COUNT) { - return GRPC_STREAM_COMPRESS_LEVEL_NONE; - } - return (grpc_stream_compression_level)( - (uint32_t)(level - (GRPC_MESSAGE_COMPRESS_LEVEL_COUNT - 1) - - GRPC_COMPRESS_LEVEL_NONE) + - (uint32_t)GRPC_STREAM_COMPRESS_LEVEL_NONE); -} - grpc_message_compression_algorithm grpc_compression_algorithm_to_message_compression_algorithm( grpc_compression_algorithm algo) { @@ -209,17 +186,17 @@ int grpc_message_compression_algorithm_name( /* TODO(dgq): Add the ability to specify parameters to the individual * compression algorithms */ grpc_message_compression_algorithm grpc_message_compression_algorithm_for_level( - grpc_message_compression_level level, uint32_t accepted_encodings) { + grpc_compression_level level, uint32_t accepted_encodings) { GRPC_API_TRACE("grpc_message_compression_algorithm_for_level(level=%d)", 1, ((int)level)); - if (level > GRPC_MESSAGE_COMPRESS_LEVEL_HIGH) { + if (level > GRPC_COMPRESS_LEVEL_HIGH) { gpr_log(GPR_ERROR, "Unknown message compression level %d.", (int)level); abort(); } const size_t num_supported = GPR_BITCOUNT(accepted_encodings) - 1; /* discard NONE */ - if (level == GRPC_MESSAGE_COMPRESS_LEVEL_NONE || num_supported == 0) { + if (level == GRPC_COMPRESS_LEVEL_NONE || num_supported == 0) { return GRPC_MESSAGE_COMPRESS_NONE; } @@ -249,13 +226,13 @@ grpc_message_compression_algorithm grpc_message_compression_algorithm_for_level( } switch (level) { - case GRPC_MESSAGE_COMPRESS_LEVEL_NONE: + case GRPC_COMPRESS_LEVEL_NONE: abort(); /* should have been handled already */ - case GRPC_MESSAGE_COMPRESS_LEVEL_LOW: + case GRPC_COMPRESS_LEVEL_LOW: return sorted_supported_algos[0]; - case GRPC_MESSAGE_COMPRESS_LEVEL_MED: + case GRPC_COMPRESS_LEVEL_MED: return sorted_supported_algos[num_supported / 2]; - case GRPC_MESSAGE_COMPRESS_LEVEL_HIGH: + case GRPC_COMPRESS_LEVEL_HIGH: return sorted_supported_algos[num_supported - 1]; default: abort(); @@ -281,23 +258,6 @@ int grpc_message_compression_algorithm_parse( /* Interfaces for stream compression. */ -grpc_stream_compression_algorithm grpc_stream_compression_algorithm_for_level( - grpc_stream_compression_level level, uint32_t accepted_encodings) { - GRPC_API_TRACE("grpc_stream_compression_algorithm_for_level(level=%d)", 1, - ((int)level)); - if (level > GRPC_STREAM_COMPRESS_LEVEL_HIGH) { - gpr_log(GPR_ERROR, "Unknown stream compression level %d.", (int)level); - abort(); - } - - /* TODO(mxyan): Use more sophisticated scheme when more algorithms added. */ - if (level != GRPC_STREAM_COMPRESS_LEVEL_NONE && - GPR_BITGET(accepted_encodings, GRPC_STREAM_COMPRESS_GZIP)) { - return GRPC_STREAM_COMPRESS_GZIP; - } - return GRPC_STREAM_COMPRESS_NONE; -} - int grpc_stream_compression_algorithm_parse( grpc_slice value, grpc_stream_compression_algorithm* algorithm) { if (grpc_slice_eq(value, GRPC_MDSTR_IDENTITY)) { diff --git a/src/core/lib/compression/compression_internal.h b/src/core/lib/compression/compression_internal.h index 4279d4f697..72f01dd1b7 100644 --- a/src/core/lib/compression/compression_internal.h +++ b/src/core/lib/compression/compression_internal.h @@ -40,38 +40,9 @@ typedef enum { GRPC_STREAM_COMPRESS_ALGORITHMS_COUNT } grpc_stream_compression_algorithm; -/** Compression levels allow a party with knowledge of its peer's accepted - * encodings to request compression in an abstract way. The level-algorithm - * mapping is performed internally and depends on the peer's supported - * compression algorithms. */ -typedef enum { - GRPC_MESSAGE_COMPRESS_LEVEL_NONE = 0, - GRPC_MESSAGE_COMPRESS_LEVEL_LOW, - GRPC_MESSAGE_COMPRESS_LEVEL_MED, - GRPC_MESSAGE_COMPRESS_LEVEL_HIGH, - GRPC_MESSAGE_COMPRESS_LEVEL_COUNT -} grpc_message_compression_level; - -/** Compression levels for stream compression algorithms */ -typedef enum { - GRPC_STREAM_COMPRESS_LEVEL_NONE = 0, - GRPC_STREAM_COMPRESS_LEVEL_LOW, - GRPC_STREAM_COMPRESS_LEVEL_MED, - GRPC_STREAM_COMPRESS_LEVEL_HIGH, - GRPC_STREAM_COMPRESS_LEVEL_COUNT -} grpc_stream_compression_level; - /* Interfaces performing transformation between compression algorithms and * levels. */ -grpc_message_compression_level -grpc_compression_level_to_message_compression_level( - grpc_compression_level level); - -grpc_stream_compression_level -grpc_compression_level_to_stream_compression_level( - grpc_compression_level level); - grpc_message_compression_algorithm grpc_compression_algorithm_to_message_compression_algorithm( grpc_compression_algorithm algo); @@ -98,16 +69,13 @@ int grpc_message_compression_algorithm_name( grpc_message_compression_algorithm algorithm, const char** name); grpc_message_compression_algorithm grpc_message_compression_algorithm_for_level( - grpc_message_compression_level level, uint32_t accepted_encodings); + grpc_compression_level level, uint32_t accepted_encodings); int grpc_message_compression_algorithm_parse( grpc_slice value, grpc_message_compression_algorithm* algorithm); /* Interfaces for stream compression. */ -grpc_stream_compression_algorithm grpc_stream_compression_algorithm_for_level( - grpc_stream_compression_level level, uint32_t accepted_encodings); - int grpc_stream_compression_algorithm_parse( grpc_slice value, grpc_stream_compression_algorithm* algorithm); diff --git a/src/core/lib/surface/channel.cc b/src/core/lib/surface/channel.cc index 826006f9b6..0936f9251b 100644 --- a/src/core/lib/surface/channel.cc +++ b/src/core/lib/surface/channel.cc @@ -143,17 +143,17 @@ grpc_channel* grpc_channel_create_with_builder( GRPC_COMPRESSION_CHANNEL_DEFAULT_LEVEL)) { channel->compression_options.default_level.is_set = true; channel->compression_options.default_level.level = - (grpc_compression_level)grpc_channel_arg_get_integer( + static_cast<grpc_compression_level>(grpc_channel_arg_get_integer( &args->args[i], {GRPC_COMPRESS_LEVEL_NONE, GRPC_COMPRESS_LEVEL_NONE, - GRPC_COMPRESS_LEVEL_COUNT - 1}); + GRPC_COMPRESS_LEVEL_COUNT - 1})); } else if (0 == strcmp(args->args[i].key, GRPC_COMPRESSION_CHANNEL_DEFAULT_ALGORITHM)) { channel->compression_options.default_algorithm.is_set = true; channel->compression_options.default_algorithm.algorithm = - (grpc_compression_algorithm)grpc_channel_arg_get_integer( + static_cast<grpc_compression_algorithm>(grpc_channel_arg_get_integer( &args->args[i], {GRPC_COMPRESS_NONE, GRPC_COMPRESS_NONE, - GRPC_COMPRESS_ALGORITHMS_COUNT - 1}); + GRPC_COMPRESS_ALGORITHMS_COUNT - 1})); } else if (0 == strcmp(args->args[i].key, GRPC_COMPRESSION_CHANNEL_ENABLED_ALGORITHMS_BITSET)) { |