Functions and macros for endian conversions and byteswap conversions.
a
.a
and convert it to native.v
to pointer a
with LE/BE encoding.v
to LE/BE.v
to native.v
to native, implemented as a macro. Use with compile-time constants only, the result will be a compile-time constant as well. Unlike most other functions these, can be used for e.g. switch-case labels. Classes | |
union | SwapFloat |
union | SwapDouble |
Macros | |
#define | SWAP_CONSTANT_64(a) |
#define | SWAP_CONSTANT_32(a) |
#define | SWAP_CONSTANT_16(a) |
#define | MKTAG(a0, a1, a2, a3) ((uint32)((a3) | ((a2) << 8) | ((a1) << 16) | ((a0) << 24))) |
#define | MKTAG16(a0, a1) ((uint16)((a1) | ((a0) << 8))) |
Functions | |
uint16 | SWAP_BYTES_16 (const uint16 a) |
uint32 | SWAP_BYTES_32 (uint32 a) |
uint64 | SWAP_BYTES_64 (uint64 a) |
Map functions for reading/writing BE/LE integers depending on native endianess | |
#define | READ_LE_UINT16(a) READ_UINT16(a) |
#define | READ_LE_UINT32(a) READ_UINT32(a) |
#define | WRITE_LE_UINT16(a, v) WRITE_UINT16(a, v) |
#define | WRITE_LE_UINT32(a, v) WRITE_UINT32(a, v) |
#define | FROM_LE_32(a) ((uint32)(a)) |
#define | FROM_LE_16(a) ((uint16)(a)) |
#define | FROM_BE_32(a) SWAP_BYTES_32(a) |
#define | FROM_BE_16(a) SWAP_BYTES_16(a) |
#define | TO_LE_32(a) ((uint32)(a)) |
#define | TO_LE_16(a) ((uint16)(a)) |
#define | TO_BE_32(a) SWAP_BYTES_32(a) |
#define | TO_BE_16(a) SWAP_BYTES_16(a) |
#define | CONSTANT_LE_32(a) ((uint32)(a)) |
#define | CONSTANT_LE_16(a) ((uint16)(a)) |
#define | CONSTANT_BE_32(a) SWAP_CONSTANT_32(a) |
#define | CONSTANT_BE_16(a) SWAP_CONSTANT_16(a) |
#define | READ_LE_UINT64(a) READ_UINT64(a) |
#define | WRITE_LE_UINT64(a, v) WRITE_UINT64(a, v) |
#define | FROM_LE_64(a) ((uint64)(a)) |
#define | FROM_BE_64(a) SWAP_BYTES_64(a) |
#define | TO_LE_64(a) ((uint64)(a)) |
#define | TO_BE_64(a) SWAP_BYTES_64(a) |
#define | CONSTANT_LE_64(a) ((uint64)(a)) |
#define | CONSTANT_BE_64(a) SWAP_CONSTANT_64(a) |
Functions for directly reading/writing and inverting | |
Use these in case the unaligned load and byteswap take a lot of instructions. | |
uint16 | READ_BE_UINT16 (const void *ptr) |
uint32 | READ_BE_UINT32 (const void *ptr) |
void | WRITE_BE_UINT16 (void *ptr, uint16 value) |
void | WRITE_BE_UINT32 (void *ptr, uint32 value) |
uint64 | READ_BE_UINT64 (const void *ptr) |
void | WRITE_BE_UINT64 (void *ptr, uint64 value) |
uint32 | READ_LE_UINT24 (const void *ptr) |
void | WRITE_LE_UINT24 (void *ptr, uint32 value) |
uint32 | READ_BE_UINT24 (const void *ptr) |
void | WRITE_BE_UINT24 (void *ptr, uint32 value) |
STATIC_ASSERT (sizeof(float)==sizeof(uint32), Unexpected_size_of_float) | |
float | READ_LE_FLOAT32 (const void *ptr) |
void | WRITE_LE_FLOAT32 (void *ptr, float value) |
float | READ_BE_FLOAT32 (const void *ptr) |
void | WRITE_BE_FLOAT32 (void *ptr, float value) |
STATIC_ASSERT (sizeof(double)==sizeof(uint64)||sizeof(double)==sizeof(uint32), Unexpected_size_of_double) | |
template<size_t n> | |
double | READ_DOUBLE (const SwapDouble &sw) |
template<size_t n> | |
void | WRITE_DOUBLE (SwapDouble &sw, double d) |
template<> | |
double | READ_DOUBLE< sizeof(uint64)> (const SwapDouble &sd) |
template<> | |
void | WRITE_DOUBLE< sizeof(uint64)> (SwapDouble &sd, double d) |
template<> | |
double | READ_DOUBLE< sizeof(uint32)> (const SwapDouble &sd) |
template<> | |
void | WRITE_DOUBLE< sizeof(uint32)> (SwapDouble &sd, double d) |
double | READ_LE_FLOAT64 (const void *ptr) |
void | WRITE_LE_FLOAT64 (void *ptr, double value) |
double | READ_BE_FLOAT64 (const void *ptr) |
void | WRITE_BE_FLOAT64 (void *ptr, double value) |
double | READ_FPA_FLOAT64 (const void *ptr) |
void | WRITE_FPA_FLOAT64 (void *ptr, double value) |
double | READ_FLOAT64 (const void *ptr) |
void | WRITE_FLOAT64 (void *ptr, double value) |
int16 | READ_LE_INT16 (const void *ptr) |
void | WRITE_LE_INT16 (void *ptr, int16 value) |
int16 | READ_BE_INT16 (const void *ptr) |
void | WRITE_BE_INT16 (void *ptr, int16 value) |
int32 | READ_LE_INT32 (const void *ptr) |
void | WRITE_LE_INT32 (void *ptr, int32 value) |
int32 | READ_BE_INT32 (const void *ptr) |
void | WRITE_BE_INT32 (void *ptr, int32 value) |
#define | READ_UINT24(a) READ_LE_UINT24(a) |
#define | WRITE_UINT24(a, b) WRITE_LE_UINT24(a,b) |
#define | READ_FLOAT32(a) READ_LE_FLOAT32(a) |
#define | WRITE_FLOAT32(a, b) WRITE_LE_FLOAT32(a,b) |
#define SWAP_CONSTANT_64 | ( | a | ) |
Swap the bytes in a 64-bit word in order to convert LE encoded data to BE and vice versa. Use with compile-time constants only.
#define SWAP_CONSTANT_32 | ( | a | ) |
Swap the bytes in a 32-bit word in order to convert LE encoded data to BE and vice versa. Use with compile-time constants only.
#define SWAP_CONSTANT_16 | ( | a | ) |
Swap the bytes in a 16-bit word in order to convert LE encoded data to BE and vice versa. Use with compile-time constants only.
#define MKTAG | ( | a0, | |
a1, | |||
a2, | |||
a3 | |||
) | ((uint32)((a3) | ((a2) << 8) | ((a1) << 16) | ((a0) << 24))) |
A wrapper macro used around four character constants, like 'DATA', to ensure portability. Typical usage: MKTAG('D','A','T','A').
This is required because the C/C++ standard does not define the endianess to be used for character constants. Hence, if one uses multi-byte character constants, a potential portability problem opens up.
#define MKTAG16 | ( | a0, | |
a1 | |||
) | ((uint16)((a1) | ((a0) << 8))) |
A wrapper macro used around two character constants, like 'wb', to ensure portability. Typical usage: MKTAG16('w','b').
|
inline |
Swap the bytes in a 16-bit word in order to convert LE encoded data to BE and vice versa.
|
inline |
Swap the bytes in a 32-bit word in order to convert LE encoded data to BE and vice versa.
|
inline |
Swap the bytes in a 64-bit word in order to convert LE encoded data to BE and vice versa.