HikoGUI
A low latency retained GUI
Loading...
Searching...
No Matches
Typedefs | Functions | Variables
TT5.hpp File Reference

TT5 A 5 bit code designed for encoding identifiers. More...

#include "TTauri/Foundation/required.hpp"
#include "TTauri/Foundation/throw_exception.hpp"
#include "TTauri/Foundation/bigint.hpp"
#include <string>
#include <string_view>
#include <cstdint>

Go to the source code of this file.

Typedefs

using tt::tt5_64 = uint64_t
 
using tt::tt5_128 = ubig128
 

Functions

constexpr uint16_t tt::tt5_code (uint16_t page, uint16_t prefix, uint16_t value)
 Create a tt5_code.
 
constexpr uint16_t tt::tt5_code_table_generate_entry (uint8_t c) noexcept
 Convert a unicode character to a tt5-code.
 
constexpr auto tt::tt5_code_table_generator () noexcept
 
constexpr uint64_t tt::tt5_code_from_char (uint8_t c) noexcept
 
template<typename T >
constexpr ssize_t tt::tt5_add_code (T &r, uint16_t code) noexcept
 
constexpr bool tt::tt5_want_to_lock (uint64_t ring) noexcept
 Check if we want to use the lock command.
 
template<typename T >
constexpr T tt::tt5_encode (char const *str)
 Encode a UTF-8 string into an integer using TT5-encoding.
 
template<typename T >
constexpr T tt::tt5_encode (std::string const &s)
 Encode a UTF-8 string into an integer using TT5-encoding.
 
template<typename T >
constexpr T tt::tt5_reverse (T value) noexcept
 Reverse the character in a TT5-packet-integer.
 
constexpr uint8_t tt::char_from_tt5_page0 (char *&str, uint8_t code, uint8_t locked_page) noexcept
 
constexpr uint8_t tt::char_from_tt5_page1 (char *&str, uint8_t code, uint8_t locked_page) noexcept
 
constexpr uint8_t tt::char_from_tt5_page2 (char *&str, uint8_t code, uint8_t &locked_page) noexcept
 
constexpr uint8_t tt::char_from_tt5_binary (char *&str, uint8_t code, uint8_t locked_page, uint8_t high_bits) noexcept
 
template<typename T >
constexpr void tt::fill_buffer_from_tt5 (char *str, T const &value) noexcept
 Convert a tt5 value to a string.
 
template<typename T >
std::string tt::tt5_decode (T const &value) noexcept
 Decode a TT5-packed integer into a UTF-8 string.
 
constexpr auto tt::operator""_tt5 (char const *str, size_t) noexcept
 
constexpr auto tt::operator""_tt5_64 (char const *str, size_t) noexcept
 
constexpr auto tt::operator""_tt5_128 (char const *str, size_t) noexcept
 

Variables

constexpr auto tt::tt5_code_table = tt5_code_table_generator()
 

Detailed Description

TT5 A 5 bit code designed for encoding identifiers.

# P0 P1 P2
00 NUL NUL NUL
01 a A 0
02 b B 1
03 c C 2
04 d D 3
05 e E 4
06 f F 5
07 g G 6
08 h H 7
09 i I 8
0a j J 9
0b k K ,
0c l L :
0d m M ;
0e n M /
0f o O LF
10 p P B0
11 q Q B1
12 r R B2
13 s S B3
14 t T B4
15 u U B5
16 v V B6
17 w W B7
18 x X L0
19 y Y L1
1a z Z L2
1b _ _ _
1c . . .
1d - - -
1e S1 S0 S0
1f S2 S2 S1

Pages

There are three pages. The current- and locked page is page 0 at the start of the text.

By using the commands S0, S1 or S2 you can temporarilly switch the current page until a single character is emited, afterwards the current page is switched back to the locked page.

By using the command L0, L1 or L2 you can change the current- and locked page.

Binary

The page 2 commands B* are used to emit a single byte. The lower 3 bits of the B* command are used as the high 3-bits of the byte and the next 5 bits are used for the lower 5 bits of the byte.

End of text

End of text is denoted by the NUL character or when there is no more room in the integer that contains the text.

Function Documentation

◆ fill_buffer_from_tt5()

template<typename T >
constexpr void tt::fill_buffer_from_tt5 ( char * str,
T const & value )
constexprnoexcept

Convert a tt5 value to a string.

Parameters
strThe buffer to return the string into, there must be enough space.

◆ operator""_tt5()

constexpr auto tt::operator""_tt5 ( char const * str,
size_t  )
constexprnoexcept

_tt5 string literal

◆ operator""_tt5_128()

constexpr auto tt::operator""_tt5_128 ( char const * str,
size_t  )
constexprnoexcept

_tt5_128 string literal

◆ operator""_tt5_64()

constexpr auto tt::operator""_tt5_64 ( char const * str,
size_t  )
constexprnoexcept

_tt5_128 string literal

◆ tt5_code()

constexpr uint16_t tt::tt5_code ( uint16_t page,
uint16_t prefix,
uint16_t value )
constexpr

Create a tt5_code.

Returns
11:10 page_nr, 9:5 prefix-code, 4:0 data (pre-shifted by 48 bits)

◆ tt5_code_table_generate_entry()

constexpr uint16_t tt::tt5_code_table_generate_entry ( uint8_t c)
constexprnoexcept

Convert a unicode character to a tt5-code.

Returns
11:10 page_nr, 9:5 prefix-code, 4:0 data (pre-shifted by 48 bits)

◆ tt5_decode()

template<typename T >
std::string tt::tt5_decode ( T const & value)
noexcept

Decode a TT5-packed integer into a UTF-8 string.

Parameters
valueThe string packed into an integer, with the last character in the least significant bits.
Returns
An UTF-8 encoded string.

◆ tt5_encode() [1/2]

template<typename T >
constexpr T tt::tt5_encode ( char const * str)
constexpr

Encode a UTF-8 string into an integer using TT5-encoding.

Parameters
strNul terminated UTF-8 string.
Returns
The string packed into an integer, with the last character in the least significant bits.

◆ tt5_encode() [2/2]

template<typename T >
constexpr T tt::tt5_encode ( std::string const & s)
constexpr

Encode a UTF-8 string into an integer using TT5-encoding.

Parameters
strUTF-8 string.
Returns
The string packed into an integer, with the last character in the least significant bits.

◆ tt5_reverse()

template<typename T >
constexpr T tt::tt5_reverse ( T value)
constexprnoexcept

Reverse the character in a TT5-packet-integer.

Parameters
valueThe string packed into an integer, with the last character in the least significant bits.
Returns
The string packed into an integer, with the first character in the least significant bits.

◆ tt5_want_to_lock()

constexpr bool tt::tt5_want_to_lock ( uint64_t ring)
constexprnoexcept

Check if we want to use the lock command.

We need at least 4 consequtive characters in the same page. We ignore page 3 (character '.', '-', '_').