Sese Framework  2.3.0
A cross-platform framework
Loading...
Searching...
No Matches
Endian.h File Reference

Endianness conversion. More...

#include <type_traits>
#include <cstring>
#include <cstdint>

Go to the source code of this file.

Macros

#define ByteSwap16(i16)   ((i16 & 0x00FF) << 8 | (i16 & 0xFF00) >> 8)
 
#define ByteSwap32(i32)   ((i32 & 0x000000FF) << 24 | (i32 & 0x0000FF00) << 8 | (i32 & 0x00FF0000) >> 8 | (i32 & 0xFF000000) >> 24)
 
#define ByteSwap64(i64)
 
#define SESE_LITTLE_ENDIAN
 
#define ASSERT_FLOAT_SIZE   static_assert(sizeof(float) == 4, "Float size is not 4 bytes")
 
#define ASSERT_DOUBLE_SIZE   static_assert(sizeof(double) == 8, "Double size is not 8 bytes")
 

Enumerations

enum class  EndianType { LITTLE , BIG }
 

Functions

template<typename T >
ToBigEndian16 (T t)
 
template<typename T >
ToBigEndian32 (T t)
 
template<typename T >
ToBigEndian64 (T t)
 
template<typename T >
ToLittleEndian16 (T t)
 
template<typename T >
ToLittleEndian32 (T t)
 
template<typename T >
ToLittleEndian64 (T t)
 
template<typename T >
FromBigEndian16 (T t)
 
template<typename T >
FromBigEndian32 (T t)
 
template<typename T >
FromBigEndian64 (T t)
 
template<typename T >
FromLittleEndian16 (T t)
 
template<typename T >
FromLittleEndian32 (T t)
 
template<typename T >
FromLittleEndian64 (T t)
 
template<typename T >
std::enable_if< sizeof(T)==2, T >::t ToBigEndian (T t)
 
template<typename T >
std::enable_if< sizeof(T)==4, T >::t ToBigEndian (T t)
 
template<typename T >
std::enable_if< sizeof(T)==8, T >::t ToBigEndian (T t)
 
template<typename T >
ToLittleEndian (T t)
 
template<typename T >
std::enable_if< sizeof(T)==2, T >::t FromBigEndian (T t)
 
template<typename T >
std::enable_if< sizeof(T)==4, T >::t FromBigEndian (T t)
 
template<typename T >
std::enable_if< sizeof(T)==8, T >::t FromBigEndian (T t)
 
template<typename T >
FromLittleEndian (T t)
 
template<>
float ToBigEndian32 (float t)
 
template<>
double ToBigEndian64 (double t)
 
template<>
float ToLittleEndian32 (float t)
 
template<>
double ToLittleEndian64 (double t)
 
template<>
float FromBigEndian32 (float t)
 
template<>
double FromBigEndian64 (double t)
 
template<>
float FromLittleEndian32 (float t)
 
template<>
double FromLittleEndian64 (double t)
 

Detailed Description

Endianness conversion.

Author
kaoru
Date
April 3, 2022

Macro Definition Documentation

◆ ASSERT_DOUBLE_SIZE

#define ASSERT_DOUBLE_SIZE   static_assert(sizeof(double) == 8, "Double size is not 8 bytes")

◆ ASSERT_FLOAT_SIZE

#define ASSERT_FLOAT_SIZE   static_assert(sizeof(float) == 4, "Float size is not 4 bytes")

◆ ByteSwap16

#define ByteSwap16 ( i16)    ((i16 & 0x00FF) << 8 | (i16 & 0xFF00) >> 8)

◆ ByteSwap32

#define ByteSwap32 ( i32)    ((i32 & 0x000000FF) << 24 | (i32 & 0x0000FF00) << 8 | (i32 & 0x00FF0000) >> 8 | (i32 & 0xFF000000) >> 24)

◆ ByteSwap64

#define ByteSwap64 ( i64)
Value:
((i64 & 0x00000000000000FF) << 56 | \
(i64 & 0x000000000000FF00) << 40 | \
(i64 & 0x0000000000FF0000) << 24 | \
(i64 & 0x00000000FF000000) << 8 | \
(i64 & 0x000000FF00000000) >> 8 | \
(i64 & 0x0000FF0000000000) >> 24 | \
(i64 & 0x00FF000000000000) >> 40 | \
(i64 & 0xFF00000000000000) >> 56)

Referenced by FromBigEndian(), FromBigEndian64(), ToBigEndian(), and ToBigEndian64().

◆ SESE_LITTLE_ENDIAN

#define SESE_LITTLE_ENDIAN

Enumeration Type Documentation

◆ EndianType

enum class EndianType
strong
Enumerator
LITTLE 
BIG 

Function Documentation

◆ FromBigEndian() [1/3]

template<typename T >
std::enable_if< sizeof(T)==2, T >::t FromBigEndian ( T t)
inline

References ByteSwap16.

◆ FromBigEndian() [2/3]

template<typename T >
std::enable_if< sizeof(T)==4, T >::t FromBigEndian ( T t)
inline

References ByteSwap32.

◆ FromBigEndian() [3/3]

template<typename T >
std::enable_if< sizeof(T)==8, T >::t FromBigEndian ( T t)
inline

References ByteSwap64.

◆ FromBigEndian16()

◆ FromBigEndian32() [1/2]

template<>
float FromBigEndian32 ( float t)
inline

◆ FromBigEndian32() [2/2]

◆ FromBigEndian64() [1/2]

template<>
double FromBigEndian64 ( double t)
inline

◆ FromBigEndian64() [2/2]

template<typename T >
T FromBigEndian64 ( T t)
inline

References ByteSwap64.

Referenced by FromBigEndian64(), and FromLittleEndian64().

◆ FromLittleEndian()

template<typename T >
T FromLittleEndian ( T t)
inline

◆ FromLittleEndian16()

template<typename T >
T FromLittleEndian16 ( T t)
inline

◆ FromLittleEndian32() [1/2]

template<>
float FromLittleEndian32 ( float t)
inline

◆ FromLittleEndian32() [2/2]

template<typename T >
T FromLittleEndian32 ( T t)
inline

◆ FromLittleEndian64() [1/2]

template<>
double FromLittleEndian64 ( double t)
inline

◆ FromLittleEndian64() [2/2]

template<typename T >
T FromLittleEndian64 ( T t)
inline

◆ ToBigEndian() [1/3]

template<typename T >
std::enable_if< sizeof(T)==2, T >::t ToBigEndian ( T t)
inline

References ByteSwap16.

◆ ToBigEndian() [2/3]

template<typename T >
std::enable_if< sizeof(T)==4, T >::t ToBigEndian ( T t)
inline

References ByteSwap32.

◆ ToBigEndian() [3/3]

template<typename T >
std::enable_if< sizeof(T)==8, T >::t ToBigEndian ( T t)
inline

References ByteSwap64.

◆ ToBigEndian16()

◆ ToBigEndian32() [1/2]

template<>
float ToBigEndian32 ( float t)
inline

◆ ToBigEndian32() [2/2]

◆ ToBigEndian64() [1/2]

template<>
double ToBigEndian64 ( double t)
inline

◆ ToBigEndian64() [2/2]

template<typename T >
T ToBigEndian64 ( T t)
inline

◆ ToLittleEndian()

template<typename T >
T ToLittleEndian ( T t)
inline

◆ ToLittleEndian16()

template<typename T >
T ToLittleEndian16 ( T t)
inline

◆ ToLittleEndian32() [1/2]

template<>
float ToLittleEndian32 ( float t)
inline

◆ ToLittleEndian32() [2/2]

template<typename T >
T ToLittleEndian32 ( T t)
inline

◆ ToLittleEndian64() [1/2]

template<>
double ToLittleEndian64 ( double t)
inline

◆ ToLittleEndian64() [2/2]

template<typename T >
T ToLittleEndian64 ( T t)
inline