K-HHC
C++ Header-only Library for Hexahexacontadecimal Encoding/Decoding
Loading...
Searching...
No Matches
Namespaces | Functions | Variables
hhc Namespace Reference

Namespaces

namespace  detail
 

Functions

constexpr void hhc_32bit_encode_padded (uint32_t input, char *output_string)
 Encode a 32-bit integer into a 6-character string.
 
constexpr void hhc_unpad_string (char *output_string)
 Unpad a string by removing the leading '-' padding characters and moving the significant content to the beginning.
 
constexpr void hhc_32bit_encode_unpadded (uint32_t input, char *output_string)
 Encode a 32-bit integer into a 6-character string without padding.
 
constexpr uint32_t hhc_32bit_decode_unsafe (const char *input_string)
 Decode a 32-bit integer from a 6-character string.
 
constexpr void hhc_64bit_encode_padded (uint64_t input, char *output_string)
 Encode a 64-bit integer into a 11-character string.
 
constexpr void hhc_64bit_encode_unpadded (uint64_t input, char *output_string)
 Encode a 64-bit integer into a 11-character string without padding.
 
constexpr uint64_t hhc_64bit_decode_unsafe (const char *input_string)
 Decode a 64-bit integer from a 11-character string.
 
constexpr std::size_t hhc_validate_string (const char *input_string)
 Validate a string to ensure it is a valid HHC string.
 
constexpr bool hhc_bounds_check (const char *input_string, const char *max_string)
 Check if a string is within the bounds of a maximum string.
 
constexpr uint32_t hhc_32bit_decode (const char *input_string)
 Decode a 32-bit integer from a 6-character string.
 
constexpr uint64_t hhc_64bit_decode (const char *input_string)
 Decode a 64-bit integer from a 11-character string.
 
constexpr std::array< uint8_t, 256 > make_hhc_inverse_alphabet ()
 

Variables

constexpr uint32_t BASE = 66
 
constexpr std::array< char, BASEALPHABET
 
constexpr uint8_t HHC_INVALID_CHAR = 0xFF
 
constexpr auto INVERSE_ALPHABET = make_hhc_inverse_alphabet()
 
constexpr uint32_t BITS_PER_BYTE = 8
 
constexpr size_t HHC_32BIT_STRING_LENGTH = 8
 
constexpr size_t HHC_64BIT_STRING_LENGTH = 16
 
constexpr size_t HHC_32BIT_ENCODED_LENGTH = 6
 
constexpr size_t HHC_64BIT_ENCODED_LENGTH = 11
 
constexpr auto HHC_32BIT_ENCODED_MAX_STRING = "1QLCp1"
 
constexpr auto HHC_64BIT_ENCODED_MAX_STRING = "9lH9ebONzYD"
 

Function Documentation

◆ hhc_32bit_decode()

constexpr uint32_t hhc::hhc_32bit_decode ( const char *  input_string)
constexpr

Decode a 32-bit integer from a 6-character string.

Parameters
input_stringThe input string to decode
Returns
The decoded 32-bit integer
Exceptions
std::invalid_argumentif the string is invalid
std::out_of_rangeif the string exceeds 32-bit bounds
Here is the call graph for this function:

◆ hhc_32bit_decode_unsafe()

constexpr uint32_t hhc::hhc_32bit_decode_unsafe ( const char *  input_string)
constexpr

Decode a 32-bit integer from a 6-character string.

Note
Performs no validation: non-alphabet bytes produce a garbage value (but never out-of-bounds memory access). Use hhc_32bit_decode for untrusted input.
Parameters
input_stringThe input string to decode (must be at least HHC_32BIT_ENCODED_LENGTH bytes)
Returns
The decoded 32-bit integer
Here is the caller graph for this function:

◆ hhc_32bit_encode_padded()

constexpr void hhc::hhc_32bit_encode_padded ( uint32_t  input,
char *  output_string 
)
constexpr

Encode a 32-bit integer into a 6-character string.

Note
Writes exactly HHC_32BIT_ENCODED_LENGTH (6) bytes and does not null-terminate. Use a zero-initialized buffer of HHC_32BIT_STRING_LENGTH (8) bytes if a null-terminated result is needed.
Parameters
inputThe 32-bit integer to encode
output_stringThe output string to write the encoded result to
Here is the caller graph for this function:

◆ hhc_32bit_encode_unpadded()

constexpr void hhc::hhc_32bit_encode_unpadded ( uint32_t  input,
char *  output_string 
)
constexpr

Encode a 32-bit integer into a 6-character string without padding.

Note
The output string is null-terminated after unpadding
Zero encodes to a single padding character ("-")
This version is slower because it needs to unpad the string
Parameters
inputThe 32-bit integer to encode
output_stringThe output string to write the encoded result to (must be at least HHC_32BIT_STRING_LENGTH bytes and null-terminated)
Here is the call graph for this function:

◆ hhc_64bit_decode()

constexpr uint64_t hhc::hhc_64bit_decode ( const char *  input_string)
constexpr

Decode a 64-bit integer from a 11-character string.

Parameters
input_stringThe input string to decode
Returns
The decoded 64-bit integer
Exceptions
std::invalid_argumentif the string is invalid
std::out_of_rangeif the string exceeds 64-bit bounds
Here is the call graph for this function:

◆ hhc_64bit_decode_unsafe()

constexpr uint64_t hhc::hhc_64bit_decode_unsafe ( const char *  input_string)
constexpr

Decode a 64-bit integer from a 11-character string.

Note
Performs no validation: non-alphabet bytes produce a garbage value (but never out-of-bounds memory access). Use hhc_64bit_decode for untrusted input.
Parameters
input_stringThe input string to decode (must be at least HHC_64BIT_ENCODED_LENGTH bytes)
Returns
The decoded 64-bit integer
Here is the caller graph for this function:

◆ hhc_64bit_encode_padded()

constexpr void hhc::hhc_64bit_encode_padded ( uint64_t  input,
char *  output_string 
)
constexpr

Encode a 64-bit integer into a 11-character string.

Note
Writes exactly HHC_64BIT_ENCODED_LENGTH (11) bytes and does not null-terminate. Use a zero-initialized buffer of HHC_64BIT_STRING_LENGTH (16) bytes if a null-terminated result is needed.
Parameters
inputThe 64-bit integer to encode
output_stringThe output string to write the encoded result to
Here is the caller graph for this function:

◆ hhc_64bit_encode_unpadded()

constexpr void hhc::hhc_64bit_encode_unpadded ( uint64_t  input,
char *  output_string 
)
constexpr

Encode a 64-bit integer into a 11-character string without padding.

Note
The output string is null-terminated after unpadding
Zero encodes to a single padding character ("-")
This version is slower because it needs to unpad the string
Parameters
inputThe 64-bit integer to encode
output_stringThe output string to write the encoded result to (must be at least HHC_64BIT_STRING_LENGTH bytes and null-terminated)
Here is the call graph for this function:

◆ hhc_bounds_check()

constexpr bool hhc::hhc_bounds_check ( const char *  input_string,
const char *  max_string 
)
constexpr

Check if a string is within the bounds of a maximum string.

Parameters
input_stringThe input string to check
max_stringThe maximum string to check against
Returns
True if the string is within the bounds, false otherwise
Here is the caller graph for this function:

◆ hhc_unpad_string()

constexpr void hhc::hhc_unpad_string ( char *  output_string)
constexpr

Unpad a string by removing the leading '-' padding characters and moving the significant content to the beginning.

Note
The output string is null-terminated after unpadding
A string consisting entirely of padding represents zero and unpads to a single padding character ("-"), so the result always round-trips through decode
Parameters
output_stringThe output string to unpad (must be null-terminated)
Here is the caller graph for this function:

◆ hhc_validate_string()

constexpr std::size_t hhc::hhc_validate_string ( const char *  input_string)
constexpr

Validate a string to ensure it is a valid HHC string.

Note
Validity is alphabet membership via INVERSE_ALPHABET, not an ASCII range check: the alphabet is non-contiguous, so bytes such as '/' ':' '@' '‘’ '{' fall between alphabet characters and are invalid.
Parameters
input_stringThe input string to validate
Returns
The length of the valid string, 0 if the string is invalid
Here is the caller graph for this function:

◆ make_hhc_inverse_alphabet()

constexpr std::array< uint8_t, 256 > hhc::make_hhc_inverse_alphabet ( )
constexpr

Variable Documentation

◆ ALPHABET

constexpr std::array<char, BASE> hhc::ALPHABET
constexpr
Initial value:
= {
'-', '.', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9',
'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L',
'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X',
'Y', 'Z', '_', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i',
'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u',
'v', 'w', 'x', 'y', 'z', '~'
}

◆ BASE

constexpr uint32_t hhc::BASE = 66
constexpr

◆ BITS_PER_BYTE

constexpr uint32_t hhc::BITS_PER_BYTE = 8
constexpr

◆ HHC_32BIT_ENCODED_LENGTH

constexpr size_t hhc::HHC_32BIT_ENCODED_LENGTH = 6
constexpr

◆ HHC_32BIT_ENCODED_MAX_STRING

constexpr auto hhc::HHC_32BIT_ENCODED_MAX_STRING = "1QLCp1"
constexpr

◆ HHC_32BIT_STRING_LENGTH

constexpr size_t hhc::HHC_32BIT_STRING_LENGTH = 8
constexpr

◆ HHC_64BIT_ENCODED_LENGTH

constexpr size_t hhc::HHC_64BIT_ENCODED_LENGTH = 11
constexpr

◆ HHC_64BIT_ENCODED_MAX_STRING

constexpr auto hhc::HHC_64BIT_ENCODED_MAX_STRING = "9lH9ebONzYD"
constexpr

◆ HHC_64BIT_STRING_LENGTH

constexpr size_t hhc::HHC_64BIT_STRING_LENGTH = 16
constexpr

◆ HHC_INVALID_CHAR

constexpr uint8_t hhc::HHC_INVALID_CHAR = 0xFF
constexpr

◆ INVERSE_ALPHABET

constexpr auto hhc::INVERSE_ALPHABET = make_hhc_inverse_alphabet()
constexpr