MCPcopy Create free account
hub / github.com/78/tenbox / HexDecode

Function HexDecode

src/daemon/rpc_server.cpp:56–72  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

54}
55
56std::vector<uint8_t> HexDecode(const std::string& value) {
57 auto digit = [](char ch) -> int {
58 if (ch >= '0' && ch <= '9') return ch - '0';
59 if (ch >= 'a' && ch <= 'f') return 10 + (ch - 'a');
60 if (ch >= 'A' && ch <= 'F') return 10 + (ch - 'A');
61 return -1;
62 };
63 if ((value.size() % 2) != 0) return {};
64 std::vector<uint8_t> out(value.size() / 2);
65 for (size_t i = 0; i < out.size(); ++i) {
66 int hi = digit(value[i * 2]);
67 int lo = digit(value[i * 2 + 1]);
68 if (hi < 0 || lo < 0) return {};
69 out[i] = static_cast<uint8_t>((hi << 4) | lo);
70 }
71 return out;
72}
73
74} // namespace
75

Callers 1

HandleRequestMethod · 0.70

Calls 1

sizeMethod · 0.45

Tested by

no test coverage detected