Skip to content

ST::hex

Michael Hansen edited this page Nov 20, 2019 · 3 revisions

string_theory hex codec

Headers

#include <string_theory/codecs>

Public Functions

Name Summary
ST::hex_encode Encode a sequence of bytes as hex
ST::hex_decode Decode a hex string into a sequence of bytes

Function Documentation

ST::hex_decode

Signature
ST::char_buffer ST::hex_decode(const ST::string &hex) (1)
ST_ssize_t ST::hex_decode(const ST::string &hex, void *output, size_t output_size) noexcept (2)
  1. Decode the hexadecimal string (upper or lower case) in hex to a buffer. If the input string contains invalid hex data, an ST::codec_error is thrown with a message indicating the type of failure.

  2. If output is NULL, this function ignores output_size and returns the necessary size to store the entire decoded data from hex. If the data in hex is not a multiple of two characters, this will return -1 instead. However, no further checking of the input is done in this mode.

    If output is not NULL, this will convert the hexadecimal string data in hex (upper or lower case) and write it to output. If output_size is too small for the entire conversion, or if any part of the conversion fails, this will return -1 and output will be left in an indeterminate state.


ST::hex_encode

Signature
ST::string ST::hex_encode(const void *data, size_t size) (1)
ST::string ST::hex_encode(const ST::char_buffer &data) (2)
  1. Encode the first size bytes of data to a lower-case hexadecimal string representation. If size is 0, data may be NULL; otherwise, data must be non-NULL.
  2. Encode all data stored in data to a lower-case hexadecimal string representation.
Clone this wiki locally