absl::HexStringToBytes

Converts the hexadecimal encoded data in hex into raw bytes in the bytes output string. If hex does not consist of valid hexadecimal data, this function returns false and leaves bytes in an unspecified state. Returns true on success.

Synopsis

Declared in <absl/strings/escaping.h>

[[nodiscard]]
bool
HexStringToBytes(
    std::string_view hex,
    std::string* bytes);

Return Value

true on success, false if hex is not valid hexadecimal data.

NOTE

The return value should not be discarded.

Parameters

NameDescription
hexThe hexadecimal-encoded string to decode.
bytesThe output string that receives the decoded bytes.