parse_hexstring.cc
Go to the documentation of this file.
1 /*
2  *
3  * Copyright 2015 gRPC authors.
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  *
17  */
18 
20 
21 #include <grpc/support/log.h>
22 
23 grpc_slice parse_hexstring(const char* hexstring) {
24  size_t nibbles = 0;
25  const char* p = nullptr;
26  uint8_t* out;
27  uint8_t temp;
29 
30  for (p = hexstring; *p; p++) {
31  nibbles += (*p >= '0' && *p <= '9') || (*p >= 'a' && *p <= 'f');
32  }
33 
34  GPR_ASSERT((nibbles & 1) == 0);
35 
36  slice = grpc_slice_malloc(nibbles / 2);
38 
39  nibbles = 0;
40  temp = 0;
41  for (p = hexstring; *p; p++) {
42  if (*p >= '0' && *p <= '9') {
43  temp = static_cast<uint8_t>(temp << 4) | static_cast<uint8_t>(*p - '0');
44  nibbles++;
45  } else if (*p >= 'a' && *p <= 'f') {
46  temp =
47  static_cast<uint8_t>(temp << 4) | static_cast<uint8_t>(*p - 'a' + 10);
48  nibbles++;
49  }
50  if (nibbles == 2) {
51  *out++ = temp;
52  nibbles = 0;
53  }
54  }
55 
56  return slice;
57 }
fix_build_deps.temp
temp
Definition: fix_build_deps.py:488
gen_build_yaml.out
dictionary out
Definition: src/benchmark/gen_build_yaml.py:24
log.h
xds_manager.p
p
Definition: xds_manager.py:60
uint8_t
unsigned char uint8_t
Definition: stdint-msvc2008.h:78
grpc_slice_malloc
GPRAPI grpc_slice grpc_slice_malloc(size_t length)
Definition: slice/slice.cc:227
GPR_ASSERT
#define GPR_ASSERT(x)
Definition: include/grpc/impl/codegen/log.h:94
slice
grpc_slice slice
Definition: src/core/lib/surface/server.cc:467
GRPC_SLICE_START_PTR
#define GRPC_SLICE_START_PTR(slice)
Definition: include/grpc/impl/codegen/slice.h:101
grpc_slice
Definition: include/grpc/impl/codegen/slice.h:65
parse_hexstring.h
parse_hexstring
grpc_slice parse_hexstring(const char *hexstring)
Definition: parse_hexstring.cc:23


grpc
Author(s):
autogenerated on Thu Mar 13 2025 03:00:49