MCPcopy Create free account
hub / github.com/Snapchat/Valdi / hexStringToBytes

Function hexStringToBytes

valdi/src/valdi/runtime/Utils/HexUtils.cpp:15–33  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

13namespace Valdi {
14
15size_t hexStringToBytes(const std::string_view& hexString, Byte* output, size_t outputLength) {
16 size_t strIndex = 0;
17
18 for (size_t i = 0; i < outputLength; i++) {
19 if (strIndex + 2 > hexString.size()) {
20 return 0;
21 }
22
23 std::string tok;
24 tok.append(hexString.data() + strIndex, 2);
25 uint8_t byte = strtol(tok.data(), nullptr, 16);
26
27 output[i] = byte;
28
29 strIndex += 2;
30 }
31
32 return strIndex;
33}
34
35std::string bytesToHexString(const Byte* input, size_t inputLength) {
36 std::stringstream stream;

Callers 1

TESTFunction · 0.85

Calls 3

appendMethod · 0.65
sizeMethod · 0.45
dataMethod · 0.45

Tested by 1

TESTFunction · 0.68