K-HHC
C++ Header-only Library for Hexahexacontadecimal Encoding/Decoding
Loading...
Searching...
No Matches
hhc_constants.hpp
Go to the documentation of this file.
1#ifndef HHC_CONSTANTS_HPP
2#define HHC_CONSTANTS_HPP
3
4#include <array>
5#include <cstdint>
6#include <cstddef>
7
8namespace hhc {
9 constexpr uint32_t BASE = 66;
10 constexpr std::array<char, BASE> ALPHABET = {
11 '-', '.', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9',
12 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L',
13 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X',
14 'Y', 'Z', '_', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i',
15 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u',
16 'v', 'w', 'x', 'y', 'z', '~'
17 };
18
19 // Sentinel marking bytes that are not part of the HHC alphabet
20 constexpr uint8_t HHC_INVALID_CHAR = 0xFF;
21
22 // Create an inverse alphabet for the HHC alphabet
23 // This is used to decode the HHC encoded data and to validate input.
24 // The table covers every possible byte value (256 entries) so that any
25 // byte - including ones outside the ASCII range - indexes it safely.
26 // Alphabet bytes map to their index; everything else maps to HHC_INVALID_CHAR.
27 // The alphabet is non-contiguous in ASCII, so membership must come from this
28 // table, not from a range check.
29 constexpr std::array<uint8_t, 256> make_hhc_inverse_alphabet() {
30 std::array<uint8_t, 256> inverse_alphabet{};
31 for (auto& entry : inverse_alphabet) {
32 entry = HHC_INVALID_CHAR;
33 }
34 for (uint32_t i = 0; i < BASE; i++) {
35 inverse_alphabet[static_cast<unsigned char>(ALPHABET[i])] = static_cast<uint8_t>(i);
36 }
37 return inverse_alphabet;
38 }
40
41 constexpr uint32_t BITS_PER_BYTE = 8;
42 constexpr size_t HHC_32BIT_STRING_LENGTH = 8;
43 constexpr size_t HHC_64BIT_STRING_LENGTH = 16;
44 constexpr size_t HHC_32BIT_ENCODED_LENGTH = 6;
45 constexpr size_t HHC_64BIT_ENCODED_LENGTH = 11;
46 constexpr auto HHC_32BIT_ENCODED_MAX_STRING = "1QLCp1";
47 constexpr auto HHC_64BIT_ENCODED_MAX_STRING = "9lH9ebONzYD";
48} // namespace hhc
49
50#endif
Definition hhc.hpp:10
constexpr auto HHC_64BIT_ENCODED_MAX_STRING
Definition hhc_constants.hpp:47
constexpr size_t HHC_64BIT_STRING_LENGTH
Definition hhc_constants.hpp:43
constexpr size_t HHC_32BIT_ENCODED_LENGTH
Definition hhc_constants.hpp:44
constexpr uint32_t BITS_PER_BYTE
Definition hhc_constants.hpp:41
constexpr auto HHC_32BIT_ENCODED_MAX_STRING
Definition hhc_constants.hpp:46
constexpr std::array< uint8_t, 256 > make_hhc_inverse_alphabet()
Definition hhc_constants.hpp:29
constexpr size_t HHC_32BIT_STRING_LENGTH
Definition hhc_constants.hpp:42
constexpr uint8_t HHC_INVALID_CHAR
Definition hhc_constants.hpp:20
constexpr std::array< char, BASE > ALPHABET
Definition hhc_constants.hpp:10
constexpr size_t HHC_64BIT_ENCODED_LENGTH
Definition hhc_constants.hpp:45
constexpr auto INVERSE_ALPHABET
Definition hhc_constants.hpp:39
constexpr uint32_t BASE
Definition hhc_constants.hpp:9