MCPcopy Create free account
hub / github.com/QuipNetwork/cpp-sdk / fromHex

Function fromHex

include/common.hpp:65–86  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

63}
64
65inline vector<uint8_t> fromHex(const string &hex, size_t expected_length = 0) {
66 string hex_str = hex;
67 if (hex.substr(0, 2) == "0x") {
68 hex_str = hex.substr(2);
69 }
70
71 if (expected_length > 0 && hex_str.length() != expected_length * 2) {
72 throw runtime_error("Invalid hex string length: expected " +
73 std::to_string(expected_length) + " bytes, got " +
74 std::to_string(hex_str.length() / 2) + " bytes");
75 }
76
77 vector<uint8_t> result;
78 result.reserve(hex_str.length() / 2);
79 for (size_t i = 0; i < hex_str.length(); i += 2) {
80 string byteString = hex_str.substr(i, 2);
81 uint8_t byte =
82 static_cast<uint8_t>(strtol(byteString.c_str(), nullptr, 16));
83 result.push_back(byte);
84 }
85 return result;
86}
87
88inline array<uint8_t, 32> fromHex32(const string &hex) {
89 vector<uint8_t> bytes = fromHex(hex, 32);

Callers 15

parsePublicKeyFromHexFunction · 0.85
parseSignatureFromHexFunction · 0.85
handleDepositMethod · 0.85
handleTransferMethod · 0.85
handleExecuteMethod · 0.85
handleChangePqOwnerMethod · 0.85
handleGenerateKeypairMethod · 0.85
handleSignMethod · 0.85
parseOpDataMethod · 0.85
parsePublicKeyMethod · 0.85
parseSignatureMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected