libcommonc++  0.7
Hex Class Reference

Routines for ASCII hex encoding and decoding. More...

#include <Hex.h++>

Static Public Member Functions

static size_t encode (ByteBuffer &input, CharBuffer &output, bool lowercase=false)
 Hex-encode a buffer of data. More...
 
static size_t encode (const byte_t *input, size_t inputLen, char *output, size_t outputLen, bool lowercase=false)
 Hex-encode an array of bytes. More...
 
static String encode (const Blob &input, bool lowercase=false)
 Hex-encode a Blob, returning the result as a String. More...
 
static size_t decode (CharBuffer &input, ByteBuffer &output)
 Hex-decode a buffer of data. More...
 
static size_t decode (const char *input, size_t inputLen, byte_t *output, size_t outputLen)
 Hex-decode an array of bytes. More...
 
static Blob decode (const String &input)
 Hex-decode a String, returning the result as a Blob. More...
 
static char encodeDigit (uint_t i, bool lowercase=false)
 Encode an integer value (which should be in the range 0 - 15) to a hexadecimal digit. More...
 
static uint_t decodeDigit (char c)
 Decode a hexadecimal digit (one of the characters '0' - '9', 'A' - 'F', or 'a' - 'f') to an integer value in the range 0 - 15. More...
 
static uint_t decodeDigit (char16_t c)
 Decode a hexadecimal digit (one of the characters '0' - '9', 'A' - 'F', or 'a' - 'f') to an integer value in the range 0 - 15. More...
 

Detailed Description

Routines for ASCII hex encoding and decoding.

Hex encoding consists of encoding each byte as two ASCII characters that represent its value in hexadecimal; for example the value 0x3B would be encoded as the characters "3B".

Author
Mark Lindner

Member Function Documentation

◆ decode() [1/3]

size_t decode ( CharBuffer input,
ByteBuffer output 
)
static

Hex-decode a buffer of data.

If the output buffer is too small, no decoding is done, and the required size of the output buffer is returned.

Parameters
inputThe input buffer.
outputThe output buffer.
Returns
The number of bytes written to the output buffer. If the value returned is greater than the size of the output buffer, it indicates that the output buffer is too small.

◆ decode() [2/3]

size_t decode ( const char *  input,
size_t  inputLen,
byte_t output,
size_t  outputLen 
)
static

Hex-decode an array of bytes.

If the output array is too small, no decoding is done, and the required length of the output array is returned.

Parameters
inputThe input array.
inputLenThe length of the input array.
outputThe output array.
outputLenThe length of the output array.
Returns
The number of bytes written to the output array. If the value returned is greater than outputLen, it indicates that the output array is too small.

◆ decode() [3/3]

Blob decode ( const String input)
static

Hex-decode a String, returning the result as a Blob.

Parameters
inputThe String to decode.
Returns
The hex decoding of the String, as a Blob, or Blob::null if the input is invalid.

◆ decodeDigit() [1/2]

uint_t decodeDigit ( char  c)
static

Decode a hexadecimal digit (one of the characters '0' - '9', 'A' - 'F', or 'a' - 'f') to an integer value in the range 0 - 15.

Parameters
cThe hex digit to decode.
Returns
The integer value. If c is not a valid hexadecimal digit, 0 is returned.

◆ decodeDigit() [2/2]

uint_t decodeDigit ( char16_t  c)
static

Decode a hexadecimal digit (one of the characters '0' - '9', 'A' - 'F', or 'a' - 'f') to an integer value in the range 0 - 15.

Parameters
cThe hex digit to decode.
Returns
The integer value. If c is not a valid hexadecimal digit, 0 is returned.

◆ encode() [1/3]

size_t encode ( ByteBuffer input,
CharBuffer output,
bool  lowercase = false 
)
static

Hex-encode a buffer of data.

If the output buffer is too small, no encoding is done, and the required size of the output buffer is returned.

Parameters
inputThe input buffer.
outputThe output buffer.
lowercaseA flag indicating whether lowercase characters should be used for hexadecimal digits ('a' - 'f').
Returns
The number of characters written to the output buffer. If the value returned is greater than the size of the output buffer, it indicates that the output buffer is too small.

◆ encode() [2/3]

size_t encode ( const byte_t input,
size_t  inputLen,
char *  output,
size_t  outputLen,
bool  lowercase = false 
)
static

Hex-encode an array of bytes.

If the output array is too small, no decoding is done, and the required length of the output array is returned.

Parameters
inputThe input array.
inputLenThe length of the input array.
outputThe output array.
outputLenThe length of the output array.
lowercaseA flag indicating whether lowercase characters should be used for hexadecimal digits ('a' - 'f').
Returns
The number of bytes written to the output array. If the value returned is greater than outputLen, it indicates that the output array is too small.

◆ encode() [3/3]

String encode ( const Blob input,
bool  lowercase = false 
)
static

Hex-encode a Blob, returning the result as a String.

Parameters
lowercaseA flag indicating whether lowercase characters should be used for hexadecimal digits ('a' - 'f').
inputThe Blob to encode.
Returns
The hex encoding of the Blob, as a String.

◆ encodeDigit()

char encodeDigit ( uint_t  i,
bool  lowercase = false 
)
static

Encode an integer value (which should be in the range 0 - 15) to a hexadecimal digit.

Parameters
iThe value to encode.
lowercaseA flag indicating whether the hex digits A - F should be encoded in upper- or lower-case.
Returns
The hex digit, as a character. If i is out of range, '0' is returned.

The documentation for this class was generated from the following files: