MCPcopy Create free account
hub / github.com/bitcoin/bitcoin / hex_string_to_byte_vec

Function hex_string_to_byte_vec

src/test/kernel/test_kernel.cpp:48–63  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

46}
47
48std::vector<std::byte> hex_string_to_byte_vec(std::string_view hex)
49{
50 std::vector<std::byte> bytes;
51 bytes.reserve(hex.length() / 2);
52
53 for (size_t i{0}; i < hex.length(); i += 2) {
54 uint8_t byte_value;
55 auto [ptr, ec] = std::from_chars(hex.data() + i, hex.data() + i + 2, byte_value, 16);
56
57 if (ec != std::errc{} || ptr != hex.data() + i + 2) {
58 throw std::invalid_argument("Invalid hex character");
59 }
60 bytes.push_back(static_cast<std::byte>(byte_value));
61 }
62 return bytes;
63}
64
65std::string byte_span_to_hex_string_reversed(std::span<const std::byte> bytes)
66{

Callers 2

BOOST_AUTO_TEST_CASEFunction · 0.70

Calls 3

reserveMethod · 0.45
dataMethod · 0.45
push_backMethod · 0.45

Tested by

no test coverage detected