Direct-BT v3.3.0-1-gc2d430c
Direct-BT - Direct Bluetooth Programming.
Classes | Functions
Codec

Data Stream Encoder and Decoder. More...

Classes

class  jau::codec::base::alphabet
 Base Alphabet Specification providing the alphabet for encode() and decode(). More...
 
class  jau::codec::base::ascii38_alphabet
 Safe base 38 alphabet with ASCII code-point sorting order. More...
 
class  jau::codec::base::ascii64_alphabet
 Safe base 64 alphabet with ASCII code-point sorting order. More...
 
class  jau::codec::base::ascii86_alphabet
 Base 86 alphabet with ASCII code-point sorting order. More...
 
class  jau::codec::base::base64_alphabet
 Safe canonical base64 alphabet, without ASCII code-point sorting order. More...
 
class  jau::codec::base::base64url_alphabet
 Safe canonical base64url alphabet, without ASCII code-point sorting order. More...
 
class  jau::codec::base::natural64_alphabet
 Safe natural base 64 alphabet, both without ASCII code-point sorting order. More...
 
class  jau::codec::base::natural86_alphabet
 Natural base 86 alphabet, without ASCII code-point sorting order. More...
 

Functions

int64_t jau::codec::base::decode (const std::string_view &str, const alphabet &aspec) noexcept
 Decodes a given symbolic string representing a given alphabet and its base to a positive decimal number. More...
 
std::vector< uint8_t > jau::codec::base::decode64 (const std::string_view &str, const alphabet &aspec) noexcept
 Decodes a given symbolic string representing using given alphabet and fixed base 64 to octets according to base64 RFC 4648. More...
 
std::vector< uint8_t > jau::codec::base::decode64_lf (const std::string_view &str, const alphabet &aspec) noexcept
 Decodes a given symbolic string representing using given alphabet and fixed base 64 to octets according to base64 RFC 4648 and removes all linefeeds before decoding as required for PEM and MIME. More...
 
std::vector< uint8_t > jau::codec::base::decode64_lf (std::string &str, const alphabet &aspec) noexcept
 Decodes a given symbolic string representing using given alphabet and fixed base 64 to octets according to base64 RFC 4648 and removes all linefeeds before decoding as required for PEM and MIME. More...
 
std::string jau::codec::base::encode (int num, const alphabet &aspec, const unsigned int min_width=0) noexcept
 Encodes a given positive decimal number to a symbolic string representing a given alphabet and its base. More...
 
std::string jau::codec::base::encode (int64_t num, const alphabet &aspec, const unsigned int min_width=0) noexcept
 Encodes a given positive decimal number to a symbolic string representing a given alphabet and its base. More...
 
std::string jau::codec::base::encode64 (const void *in_octets, size_t in_len, const alphabet &aspec) noexcept
 Encodes given octets using the given alphabet and fixed base 64 encoding according to base64 RFC 4648. More...
 
std::string jau::codec::base::encode64_mime (const void *in_octets, size_t in_len, const alphabet &aspec) noexcept
 Encodes given octets using the given alphabet and fixed base 64 encoding according to base64 RFC 4648 and adds line-feeds every 76 characters as required for MIME. More...
 
std::string jau::codec::base::encode64_pem (const void *in_octets, size_t in_len, const alphabet &aspec) noexcept
 Encodes given octets using the given alphabet and fixed base 64 encoding according to base64 RFC 4648 and adds line-feeds every 64 characters as required for PEM. More...
 
size_t jau::codec::base::insert_lf (std::string &str, const size_t period) noexcept
 Inserts a line feed (LF) character \n (ASCII 0x0a) after every period of characters. More...
 
bool jau::codec::base::operator!= (const alphabet &lhs, const alphabet &rhs) noexcept
 
bool jau::codec::base::operator== (const alphabet &lhs, const alphabet &rhs) noexcept
 
size_t jau::codec::base::remove_lf (std::string &str) noexcept
 Removes line feed character from str. More...
 
std::string jau::codec::base::to_string (const alphabet &v) noexcept
 

Detailed Description

Data Stream Encoder and Decoder.

Supported codecs:

Function Documentation

◆ to_string()

std::string jau::codec::base::to_string ( const alphabet v)
inlinenoexcept

◆ operator!=()

bool jau::codec::base::operator!= ( const alphabet lhs,
const alphabet rhs 
)
inlinenoexcept
Examples
test_functional.hpp, and test_functional_perf.hpp.

Definition at line 99 of file base_codec.hpp.

Here is the caller graph for this function:

◆ operator==()

bool jau::codec::base::operator== ( const alphabet lhs,
const alphabet rhs 
)
inlinenoexcept
Examples
test_functional.hpp, and test_functional_perf.hpp.

Definition at line 103 of file base_codec.hpp.

Here is the caller graph for this function:

◆ encode() [1/2]

std::string jau::codec::base::encode ( int  num,
const alphabet aspec,
const unsigned int  min_width = 0 
)
noexcept

Encodes a given positive decimal number to a symbolic string representing a given alphabet and its base.

Besides using a custom alphabet, the following build-in alphabets are provided

Parameters
numa positive decimal number
aspecthe used alphabet specification
min_widthminimum width of the encoded string, encoded zero is used for padding
Returns
the encoded string or an empty string if base exceeds alphabet::max_base() or invalid arguments
See also
encodeBase()
decodeBase()

Definition at line 33 of file base_codec.cpp.

Here is the caller graph for this function:

◆ encode() [2/2]

std::string jau::codec::base::encode ( int64_t  num,
const alphabet aspec,
const unsigned int  min_width = 0 
)
noexcept

Encodes a given positive decimal number to a symbolic string representing a given alphabet and its base.

Besides using a custom alphabet, the following build-in alphabets are provided

Parameters
numa positive decimal number
aspecthe used alphabet specification
min_widthminimum width of the encoded string, encoded zero is used for padding
Returns
the encoded string or an empty string if base exceeds alphabet::max_base() or invalid arguments
See also
encodeBase()
decodeBase()

Definition at line 53 of file base_codec.cpp.

◆ decode()

int64_t jau::codec::base::decode ( const std::string_view &  str,
const alphabet aspec 
)
noexcept

Decodes a given symbolic string representing a given alphabet and its base to a positive decimal number.

Besides using a custom alphabet, the following build-in alphabets are provided

Parameters
stran encoded string
aspecthe used alphabet specification
Returns
the decoded decimal value or -1 if base exceeds alphabet::max_base(), unknown code-point or invalid arguments
See also
encodeBase()

Definition at line 72 of file base_codec.cpp.

Here is the caller graph for this function:

◆ encode64()

std::string jau::codec::base::encode64 ( const void *  in_octets,
size_t  in_len,
const alphabet aspec 
)
noexcept

Encodes given octets using the given alphabet and fixed base 64 encoding according to base64 RFC 4648.

An error only occurs if in_len > 0 and resulting encoded string is empty.

Parameters
in_octetspointer to octets start
in_lenlength of octets in bytes
aspecthe used base 64 alphabet specification
Returns
the encoded string, empty if base exceeds alphabet::max_base() or invalid arguments

Definition at line 90 of file base_codec.cpp.

Here is the caller graph for this function:

◆ decode64()

std::vector< uint8_t > jau::codec::base::decode64 ( const std::string_view &  str,
const alphabet aspec 
)
noexcept

Decodes a given symbolic string representing using given alphabet and fixed base 64 to octets according to base64 RFC 4648.

An error only occurs if the encoded string length > 0 and resulting decoded octets size is empty.

Parameters
strencoded string
aspecthe used base 64 alphabet specification
Returns
the decoded octets, empty if base exceeds alphabet::max_base(), unknown code-point or invalid arguments

Definition at line 141 of file base_codec.cpp.

Here is the caller graph for this function:

◆ insert_lf()

size_t jau::codec::base::insert_lf ( std::string &  str,
const size_t  period 
)
noexcept

Inserts a line feed (LF) character \n (ASCII 0x0a) after every period of characters.

Parameters
strthe input string of characters, which will be mutated.
periodperiod of characters after which one LF will be inserted.
Returns
count of inserted LF characters

Definition at line 212 of file base_codec.cpp.

Here is the caller graph for this function:

◆ remove_lf()

size_t jau::codec::base::remove_lf ( std::string &  str)
noexcept

Removes line feed character from str.

Parameters
strthe input string of characters, which will be mutated.
Returns
count of removed LF characters

Definition at line 224 of file base_codec.cpp.

Here is the caller graph for this function:

◆ encode64_pem()

std::string jau::codec::base::encode64_pem ( const void *  in_octets,
size_t  in_len,
const alphabet aspec 
)
inlinenoexcept

Encodes given octets using the given alphabet and fixed base 64 encoding according to base64 RFC 4648 and adds line-feeds every 64 characters as required for PEM.

An error only occurs if in_len > 0 and resulting encoded string is empty.

Parameters
in_octetspointer to octets start
in_lenlength of octets in bytes
aspecthe used base 64 alphabet specification
Returns
the encoded string, empty if base exceeds alphabet::max_base() or invalid arguments

Definition at line 560 of file base_codec.hpp.

Here is the caller graph for this function:

◆ encode64_mime()

std::string jau::codec::base::encode64_mime ( const void *  in_octets,
size_t  in_len,
const alphabet aspec 
)
inlinenoexcept

Encodes given octets using the given alphabet and fixed base 64 encoding according to base64 RFC 4648 and adds line-feeds every 76 characters as required for MIME.

An error only occurs if in_len > 0 and resulting encoded string is empty.

Parameters
in_octetspointer to octets start
in_lenlength of octets in bytes
aspecthe used base 64 alphabet specification
Returns
the encoded string, empty if base exceeds alphabet::max_base() or invalid arguments

Definition at line 578 of file base_codec.hpp.

Here is the caller graph for this function:

◆ decode64_lf() [1/2]

std::vector< uint8_t > jau::codec::base::decode64_lf ( const std::string_view &  str,
const alphabet aspec 
)
inlinenoexcept

Decodes a given symbolic string representing using given alphabet and fixed base 64 to octets according to base64 RFC 4648 and removes all linefeeds before decoding as required for PEM and MIME.

An error only occurs if the encoded string length > 0 and resulting decoded octets size is empty.

Parameters
strand encoded string, will be copied
aspecthe used base 64 alphabet specification
Returns
the decoded octets, empty if base exceeds alphabet::max_base(), unknown code-point or invalid arguments

Definition at line 595 of file base_codec.hpp.

Here is the caller graph for this function:

◆ decode64_lf() [2/2]

std::vector< uint8_t > jau::codec::base::decode64_lf ( std::string &  str,
const alphabet aspec 
)
inlinenoexcept

Decodes a given symbolic string representing using given alphabet and fixed base 64 to octets according to base64 RFC 4648 and removes all linefeeds before decoding as required for PEM and MIME.

An error only occurs if the encoded string length > 0 and resulting decoded octets size is empty.

Parameters
strand encoded string, no copy, will be mutated
aspecthe used base 64 alphabet specification
Returns
the decoded octets, empty if base exceeds alphabet::max_base(), unknown code-point or invalid arguments

Definition at line 612 of file base_codec.hpp.