Kicking it Olde Sküül! Burgerlib on Github Follow Olde Sküül on Twitter Burgerbecky on LinkedIn Burgerbecky on LinkedIn
Loading...
Searching...
No Matches
Burger::SwapEndian Struct Reference

Swap the byte order of 16, 32 and 64 bit values. More...

Inheritance diagram for Burger::SwapEndian:

Static Public Member Functions

template<typename T >
static constexpr remove_pointer< T >::type load (T Input) noexcept
 Load an arithmetic value endian swapped.
 
template<typename T >
static void store (T *pOutput, T Input) noexcept
 Reverse the endian of stored arithmetic value.
 
template<typename T >
static void store (volatile T *pOutput, T Input) noexcept
 Reverse the endian of volatile stored arithmetic value.
 
template<typename T >
static T load_unaligned (T *pInput) noexcept
 Fetch a byte swapped value from memory with byte alignment.
 
template<typename T >
static void store_unaligned (T *pOutput, T Input) noexcept
 Reverse the endian of unaligned stored arithmetic value.
 
template<typename T >
static void fixup (T *pOutput) noexcept
 Swap the endian of a variable.
 
template<typename T >
static void fixup (volatile T *pOutput) noexcept
 Swap the endian of a volatile variable.
 
template<typename T >
static void fixup_unaligned (T *pOutput) noexcept
 Swap the endian of a variable that is byte aligned.
 
template<typename T >
static void fixup_unaligned (volatile T *pOutput) noexcept
 Swap the endian of a volatile variable that is byte aligned.
 

Detailed Description

Swap the byte order of 16, 32 and 64 bit values.


When reading data from machines that are using different microprocessors, the byte order could be reversed. These functions will swap the byte order.

Whenever possible, these functions will use native CPU endian swap instructions for performance.

Note
These functions will always swap the bytes, LittleEndian or BigEndian to let the compiler determine whether byte swapping is needed.
See also
NativeEndian, LittleEndian and BigEndian

Member Function Documentation

◆ fixup() [1/2]

template<typename T >
static void Burger::SwapEndian::fixup ( T * pOutput)
inlinestaticnoexcept

Swap the endian of a variable.


Read in the variable, swap the endian, and then store the result back in the original variable.

Note
Single byte variables can't be endian swapped. So no operation is performed.
Template Parameters
TPointer to a value to endian swap.
Parameters
pOutputPointer to the variable to endian swap
See also
NativeEndian::fixup(T*)

◆ fixup() [2/2]

template<typename T >
static void Burger::SwapEndian::fixup ( volatile T * pOutput)
inlinestaticnoexcept

Swap the endian of a volatile variable.


Read in the variable, swap the endian, and then store the result back in the original variable.

Note
Single byte variables can't be endian swapped. So no operation is performed.
Template Parameters
TPointer to a value to endian swap.
Parameters
pOutputPointer to the variable to endian swap
See also
NativeEndian::fixup(T*)

◆ fixup_unaligned() [1/2]

template<typename T >
static void Burger::SwapEndian::fixup_unaligned ( T * pOutput)
inlinestaticnoexcept

Swap the endian of a variable that is byte aligned.


Read in the variable, swap the endian, and then store the result back in the original variable. This function works with values that are byte aligned.

Note
Single byte variables can't be endian swapped. So no operation is performed.
Template Parameters
TPointer to a value to endian swap.
Parameters
pOutputPointer to the variable to endian swap
See also
NativeEndian::fixup_unaligned(T*)

◆ fixup_unaligned() [2/2]

template<typename T >
static void Burger::SwapEndian::fixup_unaligned ( volatile T * pOutput)
inlinestaticnoexcept

Swap the endian of a volatile variable that is byte aligned.


Read in the variable, swap the endian, and then store the result back in the original variable. This function works with values that are byte aligned.

Note
Single byte variables can't be endian swapped. So no operation is performed.
Template Parameters
TPointer to a value to endian swap.
Parameters
pOutputPointer to the variable to endian swap
See also
NativeEndian::fixup_unaligned(T*)

◆ load()

template<typename T >
static constexpr remove_pointer< T >::type Burger::SwapEndian::load ( T Input)
inlinestaticconstexprnoexcept

Load an arithmetic value endian swapped.


Given either an arithmetic type, or a pointer to an arithmetic type, load the value and return it with endian swapped.

If a non-arithmetic or pointer to non-arithmetic type is used, this template will throw a static assert.

Note
If a pointer is passed to this template, the pointer is assumed to be aligned to the data type's granularity.
Template Parameters
TArithmetic type or pointer to arithmetic type.
Parameters
InputThe value to load from pointer or return endian swapped
Returns
The input value or the loaded value from pointer.
See also
NativeEndian::load(T)

◆ load_unaligned()

template<typename T >
static T Burger::SwapEndian::load_unaligned ( T * pInput)
inlinestaticnoexcept

Fetch a byte swapped value from memory with byte alignment.


Assuming the data is unaligned, it will grab data a byte at a time and reconstruct it into a value in swapped endian.

Template Parameters
Tarithmetic type.
Parameters
pInputPointer to a value.
Returns
The loaded value
See also
store_unaligned(T*, T), or NativeEndian::load_unaligned(T*)

◆ store() [1/2]

template<typename T >
static void Burger::SwapEndian::store ( T * pOutput,
T Input )
inlinestaticnoexcept

Reverse the endian of stored arithmetic value.


Given either an arithmetic type and its pointer, store the value endian swapped.

If a non-arithmetic or pointer to non-arithmetic type is used, this template will throw a static assert.

Note
If a pointer is assumed to be aligned to the data type's granularity.
nullptr is illegal and will page fault.
Template Parameters
TArithmetic type
Parameters
pOutputPointer to a value to store as endian swapped
InputThe arithmetic value to store endian swapped
See also
store(volatile T*,T), load(T), NativeEndian::store(T*, T)

◆ store() [2/2]

template<typename T >
static void Burger::SwapEndian::store ( volatile T * pOutput,
T Input )
inlinestaticnoexcept

Reverse the endian of volatile stored arithmetic value.


Given either an arithmetic type and its pointer, store the value endian swapped.

If a non-arithmetic or pointer to non-arithmetic type is used, this template will throw a static assert.

Note
If a pointer is assumed to be aligned to the data type's granularity.
nullptr is illegal and will page fault.
Template Parameters
TArithmetic type
Parameters
pOutputPointer to a value to store as endian swapped
InputThe arithmetic value to store endian swapped
See also
store(volatile T*,T), load(T), NativeEndian::store(T*, T)

◆ store_unaligned()

template<typename T >
static void Burger::SwapEndian::store_unaligned ( T * pOutput,
T Input )
inlinestaticnoexcept

Reverse the endian of unaligned stored arithmetic value.


It assumes that the output pointer is unaligned.

Note
If a pointer is assumed to be aligned to the data type's granularity.
nullptr is illegal and will page fault.
Template Parameters
TPointer to a value to endian swap.
Parameters
pOutputPointer to a value to store as endian swapped
InputThe arithmetic value to store endian swapped
See also
store(T*,T), NativeEndian::store_unaligned(T*,T)