args_utils.cc
Go to the documentation of this file.
1 // Copyright 2021 gRPC authors.
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 
16 
17 #include <string.h>
18 
19 #include <grpc/compression.h>
20 #include <grpc/support/log.h>
21 
24 
25 const grpc_channel_args*
29  grpc_arg tmp;
30  tmp.type = GRPC_ARG_INTEGER;
31  tmp.key = const_cast<char*>(GRPC_COMPRESSION_CHANNEL_DEFAULT_ALGORITHM);
32  tmp.value.integer = algorithm;
34 }
35 
40  int** states_arg) {
41  if (a != nullptr) {
42  size_t i;
43  for (i = 0; i < a->num_args; ++i) {
44  if (a->args[i].type == GRPC_ARG_INTEGER &&
46  a->args[i].key)) {
47  *states_arg = &a->args[i].value.integer;
48  **states_arg =
49  (**states_arg & ((1 << GRPC_COMPRESS_ALGORITHMS_COUNT) - 1)) |
50  0x1; /* forcefully enable support for no compression */
51  return 1;
52  }
53  }
54  }
55  return 0; /* GPR_FALSE */
56 }
57 
60  int state) {
61  int* states_arg = nullptr;
62  const grpc_channel_args* result = *a;
63  const int states_arg_found =
65 
67  state == 0) {
68  const char* algo_name = nullptr;
69  GPR_ASSERT(grpc_compression_algorithm_name(algorithm, &algo_name) != 0);
71  "Tried to disable default compression algorithm '%s'. The "
72  "operation has been ignored.",
73  algo_name);
74  } else if (states_arg_found) {
75  if (state != 0) {
76  grpc_core::SetBit(reinterpret_cast<unsigned*>(states_arg), algorithm);
77  } else if (algorithm != GRPC_COMPRESS_NONE) {
78  grpc_core::ClearBit(reinterpret_cast<unsigned*>(states_arg), algorithm);
79  }
80  } else {
81  /* create a new arg */
82  grpc_arg tmp;
83  tmp.type = GRPC_ARG_INTEGER;
84  tmp.key =
86  /* all enabled by default */
87  tmp.value.integer = (1u << GRPC_COMPRESS_ALGORITHMS_COUNT) - 1;
88  if (state != 0) {
89  grpc_core::SetBit(reinterpret_cast<unsigned*>(&tmp.value.integer),
90  algorithm);
91  } else if (algorithm != GRPC_COMPRESS_NONE) {
92  grpc_core::ClearBit(reinterpret_cast<unsigned*>(&tmp.value.integer),
93  algorithm);
94  }
97  *a = result;
98  }
99  return result;
100 }
grpc_arg
Definition: grpc_types.h:103
_gevent_test_main.result
result
Definition: _gevent_test_main.py:96
compression.h
log.h
grpc_channel_args_compression_algorithm_set_state
const grpc_channel_args * grpc_channel_args_compression_algorithm_set_state(const grpc_channel_args **a, grpc_compression_algorithm algorithm, int state)
Definition: args_utils.cc:58
GRPC_ARG_INTEGER
@ GRPC_ARG_INTEGER
Definition: grpc_types.h:81
args_utils.h
grpc_core::DefaultCompressionAlgorithmFromChannelArgs
absl::optional< grpc_compression_algorithm > DefaultCompressionAlgorithmFromChannelArgs(const grpc_channel_args *args)
Definition: compression_internal.cc:233
string.h
grpc_compression_algorithm
grpc_compression_algorithm
Definition: compression_types.h:60
useful.h
u
OPENSSL_EXPORT pem_password_cb void * u
Definition: pem.h:351
a
int a
Definition: abseil-cpp/absl/container/internal/hash_policy_traits_test.cc:88
GRPC_COMPRESSION_CHANNEL_ENABLED_ALGORITHMS_BITSET
#define GRPC_COMPRESSION_CHANNEL_ENABLED_ALGORITHMS_BITSET
Definition: compression_types.h:54
GRPC_COMPRESS_NONE
@ GRPC_COMPRESS_NONE
Definition: compression_types.h:61
grpc_channel_args
Definition: grpc_types.h:132
GPR_ASSERT
#define GPR_ASSERT(x)
Definition: include/grpc/impl/codegen/log.h:94
grpc_compression_algorithm_name
GRPCAPI int grpc_compression_algorithm_name(grpc_compression_algorithm algorithm, const char **name)
Definition: compression.cc:56
gpr_log
GPRAPI void gpr_log(const char *file, int line, gpr_log_severity severity, const char *format,...) GPR_PRINT_FORMAT_CHECK(4
grpc_channel_args_destroy
void grpc_channel_args_destroy(grpc_channel_args *a)
Definition: channel_args.cc:360
grpc_core::ClearBit
T ClearBit(T *i, size_t n)
Definition: useful.h:55
grpc_channel_args_set_channel_default_compression_algorithm
const grpc_channel_args * grpc_channel_args_set_channel_default_compression_algorithm(const grpc_channel_args *a, grpc_compression_algorithm algorithm)
Definition: args_utils.cc:26
GPR_ERROR
#define GPR_ERROR
Definition: include/grpc/impl/codegen/log.h:57
compression_internal.h
GRPC_COMPRESS_ALGORITHMS_COUNT
@ GRPC_COMPRESS_ALGORITHMS_COUNT
Definition: compression_types.h:65
find_compression_algorithm_states_bitset
static int find_compression_algorithm_states_bitset(const grpc_channel_args *a, int **states_arg)
Definition: args_utils.cc:39
state
Definition: bloaty/third_party/zlib/contrib/blast/blast.c:41
grpc_core::SetBit
T SetBit(T *i, size_t n)
Definition: useful.h:49
autogen_x86imm.tmp
tmp
Definition: autogen_x86imm.py:12
GRPC_COMPRESSION_CHANNEL_DEFAULT_ALGORITHM
#define GRPC_COMPRESSION_CHANNEL_DEFAULT_ALGORITHM
Definition: compression_types.h:42
grpc_channel_args_copy_and_add
grpc_channel_args * grpc_channel_args_copy_and_add(const grpc_channel_args *src, const grpc_arg *to_add, size_t num_to_add)
Definition: channel_args.cc:224
i
uint64_t i
Definition: abseil-cpp/absl/container/btree_benchmark.cc:230


grpc
Author(s):
autogenerated on Thu Mar 13 2025 02:58:33