Hex Class Reference

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

#include <Hex.h++>

List of all members.

Static Public Member Functions

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

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

Blob decode ( const String input  )  [static]

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

Parameters:
input The String to decode.
Returns:
The hex decoding of the String, as a Blob.
size_t decode ( const char *  input,
size_t  inputLen,
byte_t output,
size_t  outputLen 
) throw () [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:
input The input array.
inputLen The length of the input array.
output The output array.
outputLen The 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.
size_t decode ( CharBuffer input,
ByteBuffer output 
) throw () [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:
input The input buffer.
output The 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.
uint_t decodeDigit ( char  c  )  throw () [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:
c The hex digit to decode.
Returns:
The integer value. If c is not a valid hexadecimal digit, 0 is returned.
String encode ( const Blob input,
bool  lowercase = false 
) [static]

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

Parameters:
lowercase A flag indicating whether lowercase characters should be used for hexadecimal digits ('a' - 'f').
input The Blob to encode.
Returns:
The hex encoding of the Blob, as a String.
size_t encode ( const byte_t input,
size_t  inputLen,
char *  output,
size_t  outputLen,
bool  lowercase = false 
) throw () [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:
input The input array.
inputLen The length of the input array.
output The output array.
outputLen The length of the output array.
lowercase A 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.
size_t encode ( ByteBuffer input,
CharBuffer output,
bool  lowercase = false 
) throw () [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:
input The input buffer.
output The output buffer.
lowercase A 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.
char encodeDigit ( uint_t  i,
bool  lowercase = false 
) throw () [static]

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

Parameters:
i The value to encode.
lowercase A 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:
Generated on Sat Nov 26 16:49:09 2011 for libcommonc++ by  doxygen 1.6.3