MCPcopy Create free account
hub / github.com/brainboxdotcc/DPP / from_hex

Function from_hex

mlspp/lib/bytes/src/bytes.cpp:105–120  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

103}
104
105bytes
106from_hex(const std::string& hex)
107{
108 if (hex.length() % 2 == 1) {
109 throw std::invalid_argument("Odd-length hex string");
110 }
111
112 auto len = hex.length() / 2;
113 auto out = bytes(len);
114 for (size_t i = 0; i < len; i += 1) {
115 const std::string byte = hex.substr(2 * i, 2);
116 out.at(i) = static_cast<uint8_t>(strtol(byte.c_str(), nullptr, 16));
117 }
118
119 return out;
120}
121
122std::ostream&
123operator<<(std::ostream& out, const bytes& data)

Callers

nothing calls this directly

Calls 1

bytesClass · 0.50

Tested by

no test coverage detected