jaulib v1.3.0
Jau Support Library (C++, Java, ..)
Namespaces | Classes | Enumerations | Functions | Variables
Byte Utilities

Byte utility functions and types for endian- and bit conversions, inclusive alignment handling and general get & put functionality. More...

Collaboration diagram for Byte Utilities:

Namespaces

namespace  jau::impl
 

Classes

struct  jau::has_endian_big< Dummy_type >
 A big-endian type trait for convenience . More...
 
struct  jau::has_endian_little< Dummy_type >
 A little-endian type trait for convenience . More...
 
class  jau::POctets
 Persistent endian aware octet data, i.e. More...
 
class  jau::TOctets
 Transient endian aware octet data, i.e. More...
 
class  jau::TOctetSlice
 Transient endian aware octet data slice, i.e. More...
 
class  jau::TROOctets
 Transient read only and endian aware octet data, i.e. More...
 

Enumerations

enum class  jau::endian_t : uint32_t {
  jau::endian_t::little = 0x41424344U , jau::endian_t::big = 0x44434241U , jau::endian_t::pdp = 0x43444142U , jau::endian_t::honeywell = 0x42414443U ,
  jau::endian_t::undefined = 0x00000000U , jau::endian_t::native = impl::get_host_order()
}
 Endian identifier, indicating endianess of all scalar types. More...
 
enum class  jau::lb_endian_t : uint32_t { jau::lb_endian_t::little = static_cast<uint32_t>( endian_t::little ) , jau::lb_endian_t::big = static_cast<uint32_t>( endian_t::big ) , jau::lb_endian_t::native = static_cast<uint32_t>( endian_t::native ) }
 Simplified reduced endian type only covering little- and big-endian. More...
 

Functions

constexpr uint128dp_t jau::be_to_cpu (uint128dp_t const &n) noexcept
 
constexpr uint16_t jau::be_to_cpu (uint16_t const n) noexcept
 
constexpr uint192dp_t jau::be_to_cpu (uint192dp_t const &n) noexcept
 
constexpr uint256dp_t jau::be_to_cpu (uint256dp_t const &n) noexcept
 
constexpr uint32_t jau::be_to_cpu (uint32_t const n) noexcept
 
constexpr uint64_t jau::be_to_cpu (uint64_t const &n) noexcept
 
constexpr uint128dp_t jau::bswap (uint128dp_t const &source) noexcept
 
constexpr uint16_t jau::bswap (uint16_t const source) noexcept
 
constexpr uint192dp_t jau::bswap (uint192dp_t const &source) noexcept
 
constexpr uint256dp_t jau::bswap (uint256dp_t const &source) noexcept
 
constexpr uint32_t jau::bswap (uint32_t const source) noexcept
 
constexpr uint64_t jau::bswap (uint64_t const &source) noexcept
 
constexpr void jau::bswap (uint8_t *sink, uint8_t const *source, nsize_t len)
 
const uint8_t * jau::cast_char_ptr_to_uint8 (const char *s) noexcept
 
const char * jau::cast_uint8_ptr_to_char (const uint8_t *b) noexcept
 
char * jau::cast_uint8_ptr_to_char (uint8_t *b) noexcept
 
constexpr uint128dp_t jau::cpu_to_be (uint128dp_t const &h) noexcept
 
constexpr uint16_t jau::cpu_to_be (uint16_t const h) noexcept
 
constexpr uint192dp_t jau::cpu_to_be (uint192dp_t const &h) noexcept
 
constexpr uint256dp_t jau::cpu_to_be (uint256dp_t const &h) noexcept
 
constexpr uint32_t jau::cpu_to_be (uint32_t const h) noexcept
 
constexpr uint64_t jau::cpu_to_be (uint64_t const &h) noexcept
 
constexpr uint128dp_t jau::cpu_to_le (uint128dp_t const &h) noexcept
 
constexpr uint16_t jau::cpu_to_le (uint16_t const h) noexcept
 
constexpr uint192dp_t jau::cpu_to_le (uint192dp_t const &h) noexcept
 
constexpr uint256dp_t jau::cpu_to_le (uint256dp_t const &h) noexcept
 
constexpr uint32_t jau::cpu_to_le (uint32_t const h) noexcept
 
constexpr uint64_t jau::cpu_to_le (uint64_t const &h) noexcept
 
std::string jau::dfa_utf8_decode (const uint8_t *buffer, const size_t buffer_size)
 Returns all valid consecutive UTF-8 characters within buffer in the range up to buffer_size or until EOS. More...
 
uint32_t jau::dfa_utf8_decode (uint32_t &state, uint32_t &codep, const uint32_t byte_value)
 
constexpr int8_t jau::get_int8 (uint8_t const *buffer) noexcept
 
template<typename T >
constexpr T jau::get_packed_value (const packed_t< T > *source, const lb_endian_t byte_order) noexcept
 Return packed_t::store after converting it to from either lb_endian::little or lb_endian::big depending on given byte_order to lb_endian::native. More...
 
constexpr uint128dp_t jau::get_uint128 (uint8_t const *buffer) noexcept
 See get_uint16() for reference. More...
 
constexpr uint128dp_t jau::get_uint128 (uint8_t const *buffer, const lb_endian_t byte_order) noexcept
 See get_uint16() for reference. More...
 
constexpr uint16_t jau::get_uint16 (uint8_t const *buffer) noexcept
 Returns a uint16_t value from the given byte address using packed_t to resolve a potential memory alignment issue free of costs. More...
 
constexpr uint16_t jau::get_uint16 (uint8_t const *buffer, const lb_endian_t byte_order) noexcept
 Returns a uint16_t value from the given byte address using packed_t to resolve a potential memory alignment issue free of costs. More...
 
constexpr uint192dp_t jau::get_uint192 (uint8_t const *buffer) noexcept
 See get_uint16() for reference. More...
 
constexpr uint192dp_t jau::get_uint192 (uint8_t const *buffer, const lb_endian_t byte_order) noexcept
 See get_uint16() for reference. More...
 
constexpr uint256dp_t jau::get_uint256 (uint8_t const *buffer) noexcept
 See get_uint16() for reference. More...
 
constexpr uint256dp_t jau::get_uint256 (uint8_t const *buffer, const lb_endian_t byte_order) noexcept
 See get_uint16() for reference. More...
 
constexpr uint32_t jau::get_uint32 (uint8_t const *buffer) noexcept
 See get_uint16() for reference. More...
 
constexpr uint32_t jau::get_uint32 (uint8_t const *buffer, const lb_endian_t byte_order) noexcept
 See get_uint16() for reference. More...
 
constexpr uint64_t jau::get_uint64 (uint8_t const *buffer) noexcept
 See get_uint16() for reference. More...
 
constexpr uint64_t jau::get_uint64 (uint8_t const *buffer, const lb_endian_t byte_order) noexcept
 See get_uint16() for reference. More...
 
constexpr uint8_t jau::get_uint8 (uint8_t const *buffer) noexcept
 
template<typename T >
constexpr std::enable_if_t< std::is_standard_layout_v< T >, T > jau::get_value (uint8_t const *buffer) noexcept
 Returns a T value from the given byte address using packed_t to resolve a potential memory alignment issue free of costs. More...
 
template<typename T >
constexpr std::enable_if_t< std::is_standard_layout_v< T >, T > jau::get_value (uint8_t const *buffer, const lb_endian_t byte_order) noexcept
 Returns a T value from the given byte address using packed_t to resolve a potential memory alignment issue free of costs. More...
 
constexpr bool jau::is_big_endian () noexcept
 Evaluates true if platform is running in big endian mode, i.e. More...
 
constexpr bool jau::is_defined_endian (const endian_t &v) noexcept
 Evaluates true if the given endian is defined, i.e. More...
 
constexpr bool jau::is_little_endian () noexcept
 Evaluates true if platform is running in little endian mode, i.e. More...
 
constexpr bool jau::is_little_endian (const endian_t byte_order) noexcept
 Returns true if given byte_order equals endian::little, otherwise false. More...
 
constexpr bool jau::is_little_endian (const lb_endian_t byte_order) noexcept
 Returns true if given byte_order equals lb_endian::little, otherwise false. More...
 
constexpr bool jau::is_little_or_big_endian () noexcept
 Evaluates true if platform is running in little or big endian mode, i.e. More...
 
constexpr uint128dp_t jau::le_to_cpu (uint128dp_t const &l) noexcept
 
constexpr uint16_t jau::le_to_cpu (uint16_t const l) noexcept
 
constexpr uint192dp_t jau::le_to_cpu (uint192dp_t const &l) noexcept
 
constexpr uint256dp_t jau::le_to_cpu (uint256dp_t const &l) noexcept
 
constexpr uint32_t jau::le_to_cpu (uint32_t const l) noexcept
 
constexpr uint64_t jau::le_to_cpu (uint64_t const &l) noexcept
 
constexpr void jau::put_uint128 (uint8_t *buffer, const uint128dp_t &v) noexcept
 See put_uint16() for reference. More...
 
constexpr void jau::put_uint128 (uint8_t *buffer, const uint128dp_t &v, const lb_endian_t byte_order) noexcept
 See put_uint16() for reference. More...
 
constexpr void jau::put_uint16 (uint8_t *buffer, const uint16_t v) noexcept
 Put the given uint16_t value into the given byte address using packed_t to resolve a potential memory alignment issue free of costs. More...
 
constexpr void jau::put_uint16 (uint8_t *buffer, const uint16_t v, const lb_endian_t byte_order) noexcept
 Put the given uint16_t value into the given byte address using packed_t to resolve a potential memory alignment issue free of costs. More...
 
constexpr void jau::put_uint192 (uint8_t *buffer, const uint192dp_t &v) noexcept
 See put_uint16() for reference. More...
 
constexpr void jau::put_uint192 (uint8_t *buffer, const uint192dp_t &v, const lb_endian_t byte_order) noexcept
 See put_uint16() for reference. More...
 
constexpr void jau::put_uint256 (uint8_t *buffer, const uint256dp_t &v) noexcept
 See put_uint16() for reference. More...
 
constexpr void jau::put_uint256 (uint8_t *buffer, const uint256dp_t &v, const lb_endian_t byte_order) noexcept
 See put_uint16() for reference. More...
 
constexpr void jau::put_uint32 (uint8_t *buffer, const uint32_t v) noexcept
 See put_uint16() for reference. More...
 
constexpr void jau::put_uint32 (uint8_t *buffer, const uint32_t v, const lb_endian_t byte_order) noexcept
 See put_uint16() for reference. More...
 
constexpr void jau::put_uint64 (uint8_t *buffer, const uint64_t &v) noexcept
 See put_uint16() for reference. More...
 
constexpr void jau::put_uint64 (uint8_t *buffer, const uint64_t &v, const lb_endian_t byte_order) noexcept
 See put_uint16() for reference. More...
 
constexpr void jau::put_uint8 (uint8_t *buffer, const uint8_t v) noexcept
 
template<typename T >
constexpr std::enable_if_t< std::is_standard_layout_v< T >, void > jau::put_value (uint8_t *buffer, const T &v) noexcept
 Put the given T value into the given byte address using packed_t to resolve a potential memory alignment issue free of costs. More...
 
template<typename T >
constexpr std::enable_if_t< std::is_standard_layout_v< T >, void > jau::put_value (uint8_t *buffer, const T &v, const lb_endian_t byte_order) noexcept
 Put the given T value into the given byte address using packed_t to resolve a potential memory alignment issue free of costs. More...
 
constexpr endian_t jau::to_endian (const lb_endian_t v) noexcept
 
constexpr lb_endian_t jau::to_lb_endian (const endian_t v) noexcept
 
std::string jau::to_string (const endian_t v) noexcept
 Return std::string representation of the given endian. More...
 
std::string jau::to_string (const lb_endian_t v) noexcept
 Return std::string representation of the given lb_endian. More...
 

Variables

template<typename Dummy_type >
constexpr bool jau::has_endian_big_v = has_endian_big<Dummy_type>::value
 Value access of big-endian type trait for convenience . More...
 
template<typename Dummy_type >
constexpr bool jau::has_endian_little_v = has_endian_little<Dummy_type>::value
 Value access of little-endian type trait for convenience . More...
 

Detailed Description

Byte utility functions and types for endian- and bit conversions, inclusive alignment handling and general get & put functionality.

This category is also supporting Integer types and arithmetic.

All endian API entries are of constexpr and hence evaluated at compile time.
Therefore, if-branches and expressions are also of constexpr and optimized 'away' at compile time.
This includes the cpu_to_<endian>(..) and <endian>_to_cpu(..) etc utility functions.

See endian enum class regarding endian constexpr compile time determination.

Aligned memory transfer from and to potentially unaligned memory is performed via put_uint16(), get_uint16() with all its explicit stdint types, as well as the generic template functions put_value() and get_value(). The implementation uses packed_t to resolve a potential memory alignment issue free of costs, see packed_t_alignment_cast.

Enumeration Type Documentation

◆ endian_t

enum class jau::endian_t : uint32_t
strong

Endian identifier, indicating endianess of all scalar types.

Inspired by C++20 std::endian

Corner case platforms currently not supported, i.e. unified endianess and mixed endianess.

All endian API entries are of constexpr and hence evaluated at compile time.
Therefore, if-branches and expressions are also of constexpr and optimized 'away' at compile time.
This includes the cpu_to_<endian>(..) and <endian>_to_cpu(..) etc utility functions.

On i386 platforms the host byte order is Least Significant Byte first (LSB) or Little-Endian, whereas the network byte order, as used on the Internet, is Most Significant Byte first (MSB) or Big-Endian. See #include <arpa/inet.h>

Bluetooth is LSB or Little-Endian!

See lb_endian

Enumerator
little 

Identifier for little endian.

big 

Identifier for big endian.

pdp 

Identifier for DEC PDP-11, aka ENDIAN_LITTLE_WORD.

honeywell 

Identifier for Honeywell 316, aka ENDIAN_BIG_WORD.

undefined 

Undetermined endian.

native 

Identifier for native platform type, one of the above.

Definition at line 202 of file byte_util.hpp.

◆ lb_endian_t

enum class jau::lb_endian_t : uint32_t
strong

Simplified reduced endian type only covering little- and big-endian.

See endian for details.

Enumerator
little 

Identifier for little endian, equivalent to endian::little.

big 

Identifier for big endian, equivalent to endian::big.

native 

Identifier for native platform type, one of the above.

Definition at line 226 of file byte_util.hpp.

Function Documentation

◆ bswap() [1/7]

constexpr uint16_t jau::bswap ( uint16_t const  source)
constexprnoexcept
Examples
test_basictypeconv.cpp.

Definition at line 88 of file byte_util.hpp.

Here is the caller graph for this function:

◆ bswap() [2/7]

constexpr uint32_t jau::bswap ( uint32_t const  source)
constexprnoexcept

Definition at line 97 of file byte_util.hpp.

◆ bswap() [3/7]

constexpr uint64_t jau::bswap ( uint64_t const &  source)
constexprnoexcept

Definition at line 108 of file byte_util.hpp.

◆ bswap() [4/7]

constexpr void jau::bswap ( uint8_t *  sink,
uint8_t const *  source,
nsize_t  len 
)
constexpr

Definition at line 123 of file byte_util.hpp.

◆ bswap() [5/7]

constexpr uint128dp_t jau::bswap ( uint128dp_t const &  source)
constexprnoexcept

Definition at line 130 of file byte_util.hpp.

◆ bswap() [6/7]

constexpr uint192dp_t jau::bswap ( uint192dp_t const &  source)
constexprnoexcept

Definition at line 136 of file byte_util.hpp.

◆ bswap() [7/7]

constexpr uint256dp_t jau::bswap ( uint256dp_t const &  source)
constexprnoexcept

Definition at line 142 of file byte_util.hpp.

◆ cast_uint8_ptr_to_char() [1/2]

char * jau::cast_uint8_ptr_to_char ( uint8_t *  b)
inlinenoexcept

Definition at line 148 of file byte_util.hpp.

◆ cast_uint8_ptr_to_char() [2/2]

const char * jau::cast_uint8_ptr_to_char ( const uint8_t *  b)
inlinenoexcept

Definition at line 151 of file byte_util.hpp.

◆ cast_char_ptr_to_uint8()

const uint8_t * jau::cast_char_ptr_to_uint8 ( const char *  s)
inlinenoexcept

Definition at line 155 of file byte_util.hpp.

Here is the caller graph for this function:

◆ to_string() [1/2]

std::string jau::to_string ( const endian_t  v)
noexcept

Return std::string representation of the given endian.

Parameters
vthe endian value
Returns
the std::string representation
Examples
test_basictypeconv.cpp.

Definition at line 516 of file basic_types.cpp.

Here is the caller graph for this function:

◆ to_string() [2/2]

std::string jau::to_string ( const lb_endian_t  v)
noexcept

Return std::string representation of the given lb_endian.

Parameters
vthe lb_endian value
Returns
the std::string representation

Definition at line 527 of file basic_types.cpp.

◆ to_lb_endian()

constexpr lb_endian_t jau::to_lb_endian ( const endian_t  v)
constexprnoexcept
Examples
test_basictypeconv.cpp.

Definition at line 252 of file byte_util.hpp.

Here is the caller graph for this function:

◆ to_endian()

constexpr endian_t jau::to_endian ( const lb_endian_t  v)
constexprnoexcept

Definition at line 261 of file byte_util.hpp.

◆ is_defined_endian()

constexpr bool jau::is_defined_endian ( const endian_t v)
constexprnoexcept

Evaluates true if the given endian is defined, i.e.

little, big, pdp or honeywell.

Definition at line 275 of file byte_util.hpp.

Here is the caller graph for this function:

◆ is_little_endian() [1/3]

constexpr bool jau::is_little_endian ( const endian_t  byte_order)
constexprnoexcept

Returns true if given byte_order equals endian::little, otherwise false.

Examples
test_basictypeconv.cpp.

Definition at line 293 of file byte_util.hpp.

Here is the caller graph for this function:

◆ is_little_endian() [2/3]

constexpr bool jau::is_little_endian ( const lb_endian_t  byte_order)
constexprnoexcept

Returns true if given byte_order equals lb_endian::little, otherwise false.

Definition at line 300 of file byte_util.hpp.

◆ is_little_endian() [3/3]

constexpr bool jau::is_little_endian ( )
constexprnoexcept

Evaluates true if platform is running in little endian mode, i.e.

jau::endian::little == jau::endian::native.

Definition at line 308 of file byte_util.hpp.

◆ is_big_endian()

constexpr bool jau::is_big_endian ( )
constexprnoexcept

Evaluates true if platform is running in big endian mode, i.e.

jau::endian::big == jau::endian::native.

Definition at line 316 of file byte_util.hpp.

Here is the caller graph for this function:

◆ is_little_or_big_endian()

constexpr bool jau::is_little_or_big_endian ( )
constexprnoexcept

Evaluates true if platform is running in little or big endian mode, i.e.

jau::endian::little == jau::endian::native || jau::endian::big == jau::endian::native.

Definition at line 324 of file byte_util.hpp.

Here is the caller graph for this function:

◆ be_to_cpu() [1/6]

constexpr uint16_t jau::be_to_cpu ( uint16_t const  n)
constexprnoexcept
Examples
test_basictypeconv.cpp.

Definition at line 378 of file byte_util.hpp.

Here is the caller graph for this function:

◆ cpu_to_be() [1/6]

constexpr uint16_t jau::cpu_to_be ( uint16_t const  h)
constexprnoexcept

Definition at line 387 of file byte_util.hpp.

Here is the caller graph for this function:

◆ le_to_cpu() [1/6]

constexpr uint16_t jau::le_to_cpu ( uint16_t const  l)
constexprnoexcept
Examples
test_basictypeconv.cpp.

Definition at line 396 of file byte_util.hpp.

Here is the caller graph for this function:

◆ cpu_to_le() [1/6]

constexpr uint16_t jau::cpu_to_le ( uint16_t const  h)
constexprnoexcept

Definition at line 405 of file byte_util.hpp.

Here is the caller graph for this function:

◆ be_to_cpu() [2/6]

constexpr uint32_t jau::be_to_cpu ( uint32_t const  n)
constexprnoexcept

Definition at line 415 of file byte_util.hpp.

◆ cpu_to_be() [2/6]

constexpr uint32_t jau::cpu_to_be ( uint32_t const  h)
constexprnoexcept

Definition at line 424 of file byte_util.hpp.

◆ le_to_cpu() [2/6]

constexpr uint32_t jau::le_to_cpu ( uint32_t const  l)
constexprnoexcept

Definition at line 433 of file byte_util.hpp.

◆ cpu_to_le() [2/6]

constexpr uint32_t jau::cpu_to_le ( uint32_t const  h)
constexprnoexcept

Definition at line 442 of file byte_util.hpp.

◆ be_to_cpu() [3/6]

constexpr uint64_t jau::be_to_cpu ( uint64_t const &  n)
constexprnoexcept

Definition at line 452 of file byte_util.hpp.

◆ cpu_to_be() [3/6]

constexpr uint64_t jau::cpu_to_be ( uint64_t const &  h)
constexprnoexcept

Definition at line 461 of file byte_util.hpp.

◆ le_to_cpu() [3/6]

constexpr uint64_t jau::le_to_cpu ( uint64_t const &  l)
constexprnoexcept

Definition at line 470 of file byte_util.hpp.

◆ cpu_to_le() [3/6]

constexpr uint64_t jau::cpu_to_le ( uint64_t const &  h)
constexprnoexcept

Definition at line 479 of file byte_util.hpp.

◆ be_to_cpu() [4/6]

constexpr uint128dp_t jau::be_to_cpu ( uint128dp_t const &  n)
constexprnoexcept

Definition at line 489 of file byte_util.hpp.

◆ cpu_to_be() [4/6]

constexpr uint128dp_t jau::cpu_to_be ( uint128dp_t const &  h)
constexprnoexcept

Definition at line 498 of file byte_util.hpp.

◆ le_to_cpu() [4/6]

constexpr uint128dp_t jau::le_to_cpu ( uint128dp_t const &  l)
constexprnoexcept

Definition at line 507 of file byte_util.hpp.

◆ cpu_to_le() [4/6]

constexpr uint128dp_t jau::cpu_to_le ( uint128dp_t const &  h)
constexprnoexcept

Definition at line 516 of file byte_util.hpp.

◆ be_to_cpu() [5/6]

constexpr uint192dp_t jau::be_to_cpu ( uint192dp_t const &  n)
constexprnoexcept

Definition at line 526 of file byte_util.hpp.

◆ cpu_to_be() [5/6]

constexpr uint192dp_t jau::cpu_to_be ( uint192dp_t const &  h)
constexprnoexcept

Definition at line 535 of file byte_util.hpp.

◆ le_to_cpu() [5/6]

constexpr uint192dp_t jau::le_to_cpu ( uint192dp_t const &  l)
constexprnoexcept

Definition at line 544 of file byte_util.hpp.

◆ cpu_to_le() [5/6]

constexpr uint192dp_t jau::cpu_to_le ( uint192dp_t const &  h)
constexprnoexcept

Definition at line 553 of file byte_util.hpp.

◆ be_to_cpu() [6/6]

constexpr uint256dp_t jau::be_to_cpu ( uint256dp_t const &  n)
constexprnoexcept

Definition at line 563 of file byte_util.hpp.

◆ cpu_to_be() [6/6]

constexpr uint256dp_t jau::cpu_to_be ( uint256dp_t const &  h)
constexprnoexcept

Definition at line 572 of file byte_util.hpp.

◆ le_to_cpu() [6/6]

constexpr uint256dp_t jau::le_to_cpu ( uint256dp_t const &  l)
constexprnoexcept

Definition at line 581 of file byte_util.hpp.

◆ cpu_to_le() [6/6]

constexpr uint256dp_t jau::cpu_to_le ( uint256dp_t const &  h)
constexprnoexcept

Definition at line 590 of file byte_util.hpp.

◆ put_uint8()

constexpr void jau::put_uint8 ( uint8_t *  buffer,
const uint8_t  v 
)
constexprnoexcept

Definition at line 607 of file byte_util.hpp.

◆ get_uint8()

constexpr uint8_t jau::get_uint8 ( uint8_t const *  buffer)
constexprnoexcept

Definition at line 611 of file byte_util.hpp.

◆ get_int8()

constexpr int8_t jau::get_int8 ( uint8_t const *  buffer)
constexprnoexcept

Definition at line 615 of file byte_util.hpp.

Here is the caller graph for this function:

◆ get_packed_value()

template<typename T >
constexpr T jau::get_packed_value ( const packed_t< T > *  source,
const lb_endian_t  byte_order 
)
constexprnoexcept

Return packed_t::store after converting it to from either lb_endian::little or lb_endian::big depending on given byte_order to lb_endian::native.

Template Parameters
T
Parameters
source
byte_order

Definition at line 628 of file byte_util.hpp.

Here is the caller graph for this function:

◆ put_uint16() [1/2]

constexpr void jau::put_uint16 ( uint8_t *  buffer,
const uint16_t  v 
)
constexprnoexcept

Put the given uint16_t value into the given byte address using packed_t to resolve a potential memory alignment issue free of costs.

See also
packed_t_alignment_cast

Definition at line 638 of file byte_util.hpp.

Here is the caller graph for this function:

◆ put_uint16() [2/2]

constexpr void jau::put_uint16 ( uint8_t *  buffer,
const uint16_t  v,
const lb_endian_t  byte_order 
)
constexprnoexcept

Put the given uint16_t value into the given byte address using packed_t to resolve a potential memory alignment issue free of costs.

The value is converted from lb_endian::native to either lb_endian::little or lb_endian::big depending on given byte_order before it is stored in memory.

See also
packed_t_alignment_cast

Definition at line 651 of file byte_util.hpp.

◆ get_uint16() [1/2]

constexpr uint16_t jau::get_uint16 ( uint8_t const *  buffer)
constexprnoexcept

Returns a uint16_t value from the given byte address using packed_t to resolve a potential memory alignment issue free of costs.

See also
packed_t_alignment_cast

Definition at line 661 of file byte_util.hpp.

Here is the caller graph for this function:

◆ get_uint16() [2/2]

constexpr uint16_t jau::get_uint16 ( uint8_t const *  buffer,
const lb_endian_t  byte_order 
)
constexprnoexcept

Returns a uint16_t value from the given byte address using packed_t to resolve a potential memory alignment issue free of costs.

The value is converted from either lb_endian::little or lb_endian::big depending on given byte_order to lb_endian::native before it is returned to the caller.

See also
packed_t_alignment_cast

Definition at line 674 of file byte_util.hpp.

◆ put_uint32() [1/2]

constexpr void jau::put_uint32 ( uint8_t *  buffer,
const uint32_t  v 
)
constexprnoexcept

See put_uint16() for reference.

See also
packed_t_alignment_cast

Definition at line 683 of file byte_util.hpp.

Here is the caller graph for this function:

◆ put_uint32() [2/2]

constexpr void jau::put_uint32 ( uint8_t *  buffer,
const uint32_t  v,
const lb_endian_t  byte_order 
)
constexprnoexcept

See put_uint16() for reference.

See also
packed_t_alignment_cast

Definition at line 691 of file byte_util.hpp.

◆ get_uint32() [1/2]

constexpr uint32_t jau::get_uint32 ( uint8_t const *  buffer)
constexprnoexcept

See get_uint16() for reference.

See also
packed_t_alignment_cast

Definition at line 699 of file byte_util.hpp.

Here is the caller graph for this function:

◆ get_uint32() [2/2]

constexpr uint32_t jau::get_uint32 ( uint8_t const *  buffer,
const lb_endian_t  byte_order 
)
constexprnoexcept

See get_uint16() for reference.

See also
packed_t_alignment_cast

Definition at line 707 of file byte_util.hpp.

◆ put_uint64() [1/2]

constexpr void jau::put_uint64 ( uint8_t *  buffer,
const uint64_t &  v 
)
constexprnoexcept

See put_uint16() for reference.

See also
packed_t_alignment_cast

Definition at line 716 of file byte_util.hpp.

Here is the caller graph for this function:

◆ put_uint64() [2/2]

constexpr void jau::put_uint64 ( uint8_t *  buffer,
const uint64_t &  v,
const lb_endian_t  byte_order 
)
constexprnoexcept

See put_uint16() for reference.

See also
packed_t_alignment_cast

Definition at line 724 of file byte_util.hpp.

◆ get_uint64() [1/2]

constexpr uint64_t jau::get_uint64 ( uint8_t const *  buffer)
constexprnoexcept

See get_uint16() for reference.

See also
packed_t_alignment_cast

Definition at line 732 of file byte_util.hpp.

Here is the caller graph for this function:

◆ get_uint64() [2/2]

constexpr uint64_t jau::get_uint64 ( uint8_t const *  buffer,
const lb_endian_t  byte_order 
)
constexprnoexcept

See get_uint16() for reference.

See also
packed_t_alignment_cast

Definition at line 740 of file byte_util.hpp.

◆ put_uint128() [1/2]

constexpr void jau::put_uint128 ( uint8_t *  buffer,
const uint128dp_t v 
)
constexprnoexcept

See put_uint16() for reference.

See also
packed_t_alignment_cast

Definition at line 749 of file byte_util.hpp.

Here is the caller graph for this function:

◆ put_uint128() [2/2]

constexpr void jau::put_uint128 ( uint8_t *  buffer,
const uint128dp_t v,
const lb_endian_t  byte_order 
)
constexprnoexcept

See put_uint16() for reference.

See also
packed_t_alignment_cast

Definition at line 757 of file byte_util.hpp.

◆ get_uint128() [1/2]

constexpr uint128dp_t jau::get_uint128 ( uint8_t const *  buffer)
constexprnoexcept

See get_uint16() for reference.

See also
packed_t_alignment_cast

Definition at line 765 of file byte_util.hpp.

Here is the caller graph for this function:

◆ get_uint128() [2/2]

constexpr uint128dp_t jau::get_uint128 ( uint8_t const *  buffer,
const lb_endian_t  byte_order 
)
constexprnoexcept

See get_uint16() for reference.

See also
packed_t_alignment_cast

Definition at line 773 of file byte_util.hpp.

◆ put_uint192() [1/2]

constexpr void jau::put_uint192 ( uint8_t *  buffer,
const uint192dp_t v 
)
constexprnoexcept

See put_uint16() for reference.

See also
packed_t_alignment_cast

Definition at line 782 of file byte_util.hpp.

Here is the caller graph for this function:

◆ put_uint192() [2/2]

constexpr void jau::put_uint192 ( uint8_t *  buffer,
const uint192dp_t v,
const lb_endian_t  byte_order 
)
constexprnoexcept

See put_uint16() for reference.

See also
packed_t_alignment_cast

Definition at line 790 of file byte_util.hpp.

◆ get_uint192() [1/2]

constexpr uint192dp_t jau::get_uint192 ( uint8_t const *  buffer)
constexprnoexcept

See get_uint16() for reference.

See also
packed_t_alignment_cast

Definition at line 798 of file byte_util.hpp.

Here is the caller graph for this function:

◆ get_uint192() [2/2]

constexpr uint192dp_t jau::get_uint192 ( uint8_t const *  buffer,
const lb_endian_t  byte_order 
)
constexprnoexcept

See get_uint16() for reference.

See also
packed_t_alignment_cast

Definition at line 806 of file byte_util.hpp.

◆ put_uint256() [1/2]

constexpr void jau::put_uint256 ( uint8_t *  buffer,
const uint256dp_t v 
)
constexprnoexcept

See put_uint16() for reference.

See also
packed_t_alignment_cast

Definition at line 815 of file byte_util.hpp.

Here is the caller graph for this function:

◆ put_uint256() [2/2]

constexpr void jau::put_uint256 ( uint8_t *  buffer,
const uint256dp_t v,
const lb_endian_t  byte_order 
)
constexprnoexcept

See put_uint16() for reference.

See also
packed_t_alignment_cast

Definition at line 823 of file byte_util.hpp.

◆ get_uint256() [1/2]

constexpr uint256dp_t jau::get_uint256 ( uint8_t const *  buffer)
constexprnoexcept

See get_uint16() for reference.

See also
packed_t_alignment_cast

Definition at line 831 of file byte_util.hpp.

Here is the caller graph for this function:

◆ get_uint256() [2/2]

constexpr uint256dp_t jau::get_uint256 ( uint8_t const *  buffer,
const lb_endian_t  byte_order 
)
constexprnoexcept

See get_uint16() for reference.

See also
packed_t_alignment_cast

Definition at line 839 of file byte_util.hpp.

◆ put_value() [1/2]

template<typename T >
constexpr std::enable_if_t< std::is_standard_layout_v< T >, void > jau::put_value ( uint8_t *  buffer,
const T &  v 
)
constexprnoexcept

Put the given T value into the given byte address using packed_t to resolve a potential memory alignment issue free of costs.

Template Parameters
T
Parameters
buffer
v
See also
packed_t_alignment_cast
Examples
test_basictypeconv.cpp.

Definition at line 864 of file byte_util.hpp.

Here is the caller graph for this function:

◆ put_value() [2/2]

template<typename T >
constexpr std::enable_if_t< std::is_standard_layout_v< T >, void > jau::put_value ( uint8_t *  buffer,
const T &  v,
const lb_endian_t  byte_order 
)
constexprnoexcept

Put the given T value into the given byte address using packed_t to resolve a potential memory alignment issue free of costs.

The value is converted from lb_endian::native to either lb_endian::little or lb_endian::big depending on given byte_order before it is stored in memory.

Template Parameters
T
Parameters
buffer
v
byte_order
See also
packed_t_alignment_cast

Definition at line 888 of file byte_util.hpp.

◆ get_value() [1/2]

template<typename T >
constexpr std::enable_if_t< std::is_standard_layout_v< T >, T > jau::get_value ( uint8_t const *  buffer)
constexprnoexcept

Returns a T value from the given byte address using packed_t to resolve a potential memory alignment issue free of costs.

Template Parameters
T
Parameters
buffer
Returns
See also
packed_t_alignment_cast

Definition at line 907 of file byte_util.hpp.

◆ get_value() [2/2]

template<typename T >
constexpr std::enable_if_t< std::is_standard_layout_v< T >, T > jau::get_value ( uint8_t const *  buffer,
const lb_endian_t  byte_order 
)
constexprnoexcept

Returns a T value from the given byte address using packed_t to resolve a potential memory alignment issue free of costs.

The value is converted from either lb_endian::little or lb_endian::big depending on given byte_order to lb_endian::native before it is returned to the caller.

Template Parameters
T
Parameters
buffer
byte_order
Returns
See also
packed_t_alignment_cast

Definition at line 930 of file byte_util.hpp.

◆ dfa_utf8_decode() [1/2]

uint32_t jau::dfa_utf8_decode ( uint32_t &  state,
uint32_t &  codep,
const uint32_t  byte_value 
)
Parameters
state
codep
byte_value
Returns

Definition at line 90 of file dfa_utf8_decode.cpp.

Here is the caller graph for this function:

◆ dfa_utf8_decode() [2/2]

std::string jau::dfa_utf8_decode ( const uint8_t *  buffer,
const size_t  buffer_size 
)

Returns all valid consecutive UTF-8 characters within buffer in the range up to buffer_size or until EOS.

In case a non UTF-8 character has been detected, the content will be cut off and the decoding loop ends.

Method utilizes a finite state machine detecting variable length UTF-8 codes. See Bjoern Hoehrmann's site http://bjoern.hoehrmann.de/utf-8/decoder/dfa/ for details.

Definition at line 31 of file dfa_utf8_decode.cpp.

Variable Documentation

◆ has_endian_little_v

template<typename Dummy_type >
constexpr bool jau::has_endian_little_v = has_endian_little<Dummy_type>::value
constexpr

Value access of little-endian type trait for convenience .

Since all endian definitions are of constexpr, code can simply use expressions of these for compile-time evaluation and optimization. A template SFINAE is not required.

Template Parameters
Dummy_typejust to make template SFINAE happy

Definition at line 346 of file byte_util.hpp.

◆ has_endian_big_v

template<typename Dummy_type >
constexpr bool jau::has_endian_big_v = has_endian_big<Dummy_type>::value
constexpr

Value access of big-endian type trait for convenience .

Since all endian definitions are of constexpr, code can simply use expressions of these for compile-time evaluation and optimization. A template SFINAE is not required.

Template Parameters
Dummy_typejust to make template SFINAE happy

Definition at line 366 of file byte_util.hpp.