absl::HexStringToBytes

HexStringToBytes overloads

Synopses

Declared in <absl/strings/escaping.h>

Converts an ASCII hex string into bytes, returning binary data of length from.size()/2. The input must be valid hexadecimal data, otherwise the return value is unspecified.

[[deprecated("Use the HexStringToBytes() that returns a bool")]]
std::string
HexStringToBytes(std::string_view from);
» more...

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.

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

Return Value

  • The decoded binary data.
  • true on success, false if hex is not valid hexadecimal data.

Parameters

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