Rihen Rihen NkentseuDocumentation

NkEndianness.h

Include
#include "NKPlatform/NkEndianness.h"
Namespace
nkentseu::platform
Link (Jenga)
nkentseudependson(["NKPlatform"])

Types

NkEndiannessEnumeration of the supported byte orders

Functions · 50

NkGetCompileTimeEndiannessByte order detection at compile time (NK API)
NkGetRuntimeEndiannessByte order detection at run time (NK API)
NkIsLittleEndianChecks whether the system is little-endian
NkIsBigEndianChecks whether the system is big-endian
ByteSwap16Reverses the bytes of a 16-bit integer
NkByteSwap16NK alias for ByteSwap16
ByteSwap32Reverses the bytes of a 32-bit integer
NkByteSwap32NK alias for ByteSwap32
ByteSwap64Reverses the bytes of a 64-bit integer
NkByteSwap64NK alias for ByteSwap64
ByteSwapGeneric byte swap through a template
HostToNetwork16Converts a uint16 from host to network byte order (big-endian)
NkHostToNetwork16NK alias for HostToNetwork16
HostToNetwork32Converts a uint32 from host to network byte order (big-endian)
NkHostToNetwork32NK alias for HostToNetwork32
HostToNetwork64Converts a uint64 from host to network byte order (big-endian)
NkHostToNetwork64NK alias for HostToNetwork64
NetworkToHost16Converts a uint16 from network to host byte order
NkNetworkToHost16NK alias for NetworkToHost16
NetworkToHost32Converts a uint32 from network to host byte order
NkNetworkToHost32NK alias for NetworkToHost32
NetworkToHost64Converts a uint64 from network to host byte order
NkNetworkToHost64NK alias for NetworkToHost64
ToLittleEndianConverts a value to little-endian
FromLittleEndianConverts a value from little-endian
ToBigEndianConverts a value to big-endian
FromBigEndianConverts a value from big-endian
ByteSwapBufferReverses the bytes of every element of a buffer
BufferToLittleEndianConverts a buffer to little-endian
BufferFromLittleEndianConverts a buffer from little-endian
BufferToBigEndianConverts a buffer to big-endian
BufferFromBigEndianConverts a buffer from big-endian
ReadUnaligned16Reads a uint16 from a possibly unaligned address
ReadUnaligned32Reads a uint32 from a possibly unaligned address
ReadUnaligned64Reads a uint64 from a possibly unaligned address
WriteUnaligned16Writes a uint16 to a possibly unaligned address
WriteUnaligned32Writes a uint32 to a possibly unaligned address
WriteUnaligned64Writes a uint64 to a possibly unaligned address
ReadLE16Reads a little-endian uint16 from unaligned memory
ReadLE32Reads a little-endian uint32 from unaligned memory
ReadLE64Reads a little-endian uint64 from unaligned memory
ReadBE16Reads a big-endian uint16 from unaligned memory
ReadBE32Reads a big-endian uint32 from unaligned memory
ReadBE64Reads a big-endian uint64 from unaligned memory
WriteLE16Writes a little-endian uint16 to unaligned memory
WriteLE32Writes a little-endian uint32 to unaligned memory
WriteLE64Writes a little-endian uint64 to unaligned memory
WriteBE16Writes a big-endian uint16 to unaligned memory
WriteBE32Writes a big-endian uint32 to unaligned memory
WriteBE64Writes a big-endian uint64 to unaligned memory

Macros · 13

NKENTSEU_FORCE_INLINE
NK_LITTLE_ENDIANMacro telling whether the platform is little-endian
NK_BIG_ENDIANMacro telling whether the platform is big-endian
NK_ENDIAN_UNKNOWNMacro signalling an unknown byte order
NK_BSWAP16Short alias for ByteSwap16
NK_BSWAP32Short alias for ByteSwap32
NK_BSWAP64Short alias for ByteSwap64
NK_HTON16Short alias for HostToNetwork16 (htons equivalent)
NK_HTON32Short alias for HostToNetwork32 (htonl equivalent)
NK_HTON64Short alias for HostToNetwork64
NK_NTOH16Short alias for NetworkToHost16 (ntohs equivalent)
NK_NTOH32Short alias for NetworkToHost32 (ntohl equivalent)
NK_NTOH64Short alias for NetworkToHost64

Member details

NKENTSEU_FORCE_INLINE

#
macro
#define NKENTSEU_FORCE_INLINE

NkGetCompileTimeEndianness

#
function
constexpr NkEndianness NkGetCompileTimeEndianness()

Byte order detection at compile time (NK API)

@codefragment, not compiled
if constexpr (NkGetCompileTimeEndianness() == NkEndianness::NK_LITTLE) {
    // Code optimisé pour little-endian
}

NkGetRuntimeEndianness

#
function
NkEndianness NkGetRuntimeEndianness()

Byte order detection at run time (NK API)

NkIsLittleEndian

#
function
constexpr bool NkIsLittleEndian()

Checks whether the system is little-endian

NkIsBigEndian

#
function
constexpr bool NkIsBigEndian()

Checks whether the system is big-endian

NK_LITTLE_ENDIAN

#
macro
#define NK_LITTLE_ENDIAN

Macro telling whether the platform is little-endian

NK_BIG_ENDIAN

#
macro
#define NK_BIG_ENDIAN

Macro telling whether the platform is big-endian

NK_ENDIAN_UNKNOWN

#
macro
#define NK_ENDIAN_UNKNOWN

Macro signalling an unknown byte order

ByteSwap16

#
function
constexpr uint16_t ByteSwap16(uint16_t value)

Reverses the bytes of a 16-bit integer

Parameters

NameTypeRoleDefault
valueuint16_t

NkByteSwap16

#
function
constexpr uint16_t NkByteSwap16(uint16_t value)

NK alias for ByteSwap16

Parameters

NameTypeRoleDefault
valueuint16_t

ByteSwap32

#
function
constexpr uint32_t ByteSwap32(uint32_t value)

Reverses the bytes of a 32-bit integer

Parameters

NameTypeRoleDefault
valueuint32_t

NkByteSwap32

#
function
constexpr uint32_t NkByteSwap32(uint32_t value)

NK alias for ByteSwap32

Parameters

NameTypeRoleDefault
valueuint32_t

ByteSwap64

#
function
constexpr uint64_t ByteSwap64(uint64_t value)

Reverses the bytes of a 64-bit integer

Parameters

NameTypeRoleDefault
valueuint64_t

NkByteSwap64

#
function
constexpr uint64_t NkByteSwap64(uint64_t value)

NK alias for ByteSwap64

Parameters

NameTypeRoleDefault
valueuint64_t

ByteSwap

#
functiongeneric (template)
template <typename T> constexpr T ByteSwap(T value)

Generic byte swap through a template

Parameters

NameTypeRoleDefault
valueT
@codefragment, not compiled
uint32_t swapped = ByteSwap(myValue);
float floatSwapped = ByteSwap(myFloat); // via union interne

HostToNetwork16

#
function
constexpr uint16_t HostToNetwork16(uint16_t value)

Converts a uint16 from host to network byte order (big-endian)

Parameters

NameTypeRoleDefault
valueuint16_t

NkHostToNetwork16

#
function
constexpr uint16_t NkHostToNetwork16(uint16_t value)

NK alias for HostToNetwork16

Parameters

NameTypeRoleDefault
valueuint16_t

HostToNetwork32

#
function
constexpr uint32_t HostToNetwork32(uint32_t value)

Converts a uint32 from host to network byte order (big-endian)

Parameters

NameTypeRoleDefault
valueuint32_t

NkHostToNetwork32

#
function
constexpr uint32_t NkHostToNetwork32(uint32_t value)

NK alias for HostToNetwork32

Parameters

NameTypeRoleDefault
valueuint32_t

HostToNetwork64

#
function
constexpr uint64_t HostToNetwork64(uint64_t value)

Converts a uint64 from host to network byte order (big-endian)

Parameters

NameTypeRoleDefault
valueuint64_t

NkHostToNetwork64

#
function
constexpr uint64_t NkHostToNetwork64(uint64_t value)

NK alias for HostToNetwork64

Parameters

NameTypeRoleDefault
valueuint64_t

NetworkToHost16

#
function
constexpr uint16_t NetworkToHost16(uint16_t value)

Converts a uint16 from network to host byte order

Parameters

NameTypeRoleDefault
valueuint16_t

NkNetworkToHost16

#
function
constexpr uint16_t NkNetworkToHost16(uint16_t value)

NK alias for NetworkToHost16

Parameters

NameTypeRoleDefault
valueuint16_t

NetworkToHost32

#
function
constexpr uint32_t NetworkToHost32(uint32_t value)

Converts a uint32 from network to host byte order

Parameters

NameTypeRoleDefault
valueuint32_t

NkNetworkToHost32

#
function
constexpr uint32_t NkNetworkToHost32(uint32_t value)

NK alias for NetworkToHost32

Parameters

NameTypeRoleDefault
valueuint32_t

NetworkToHost64

#
function
constexpr uint64_t NetworkToHost64(uint64_t value)

Converts a uint64 from network to host byte order

Parameters

NameTypeRoleDefault
valueuint64_t

NkNetworkToHost64

#
function
constexpr uint64_t NkNetworkToHost64(uint64_t value)

NK alias for NetworkToHost64

Parameters

NameTypeRoleDefault
valueuint64_t

ToLittleEndian

#
functiongeneric (template)
template <typename T> constexpr T ToLittleEndian(T value)

Converts a value to little-endian

Parameters

NameTypeRoleDefault
valueT

FromLittleEndian

#
functiongeneric (template)
template <typename T> constexpr T FromLittleEndian(T value)

Converts a value from little-endian

Parameters

NameTypeRoleDefault
valueT

ToBigEndian

#
functiongeneric (template)
template <typename T> constexpr T ToBigEndian(T value)

Converts a value to big-endian

Parameters

NameTypeRoleDefault
valueT

FromBigEndian

#
functiongeneric (template)
template <typename T> constexpr T FromBigEndian(T value)

Converts a value from big-endian

Parameters

NameTypeRoleDefault
valueT

ByteSwapBuffer

#
functiongeneric (template)
template <typename T> void ByteSwapBuffer(T *data, size_t count)

Reverses the bytes of every element of a buffer

Parameters

NameTypeRoleDefault
dataT *
countsize_t

BufferToLittleEndian

#
functiongeneric (template)
template <typename T> void BufferToLittleEndian(T *data, size_t count)

Converts a buffer to little-endian

Parameters

NameTypeRoleDefault
dataT *
countsize_t

BufferFromLittleEndian

#
functiongeneric (template)
template <typename T> void BufferFromLittleEndian(T *data, size_t count)

Converts a buffer from little-endian

Parameters

NameTypeRoleDefault
dataT *
countsize_t

BufferToBigEndian

#
functiongeneric (template)
template <typename T> void BufferToBigEndian(T *data, size_t count)

Converts a buffer to big-endian

Parameters

NameTypeRoleDefault
dataT *
countsize_t

BufferFromBigEndian

#
functiongeneric (template)
template <typename T> void BufferFromBigEndian(T *data, size_t count)

Converts a buffer from big-endian

Parameters

NameTypeRoleDefault
dataT *
countsize_t

ReadUnaligned16

#
function
uint16_t ReadUnaligned16(const void *ptr)

Reads a uint16 from a possibly unaligned address

Parameters

NameTypeRoleDefault
ptrconst void *

ReadUnaligned32

#
function
uint32_t ReadUnaligned32(const void *ptr)

Reads a uint32 from a possibly unaligned address

Parameters

NameTypeRoleDefault
ptrconst void *

ReadUnaligned64

#
function
uint64_t ReadUnaligned64(const void *ptr)

Reads a uint64 from a possibly unaligned address

Parameters

NameTypeRoleDefault
ptrconst void *

WriteUnaligned16

#
function
void WriteUnaligned16(void *ptr, uint16_t value)

Writes a uint16 to a possibly unaligned address

Parameters

NameTypeRoleDefault
ptrvoid *
valueuint16_t

WriteUnaligned32

#
function
void WriteUnaligned32(void *ptr, uint32_t value)

Writes a uint32 to a possibly unaligned address

Parameters

NameTypeRoleDefault
ptrvoid *
valueuint32_t

WriteUnaligned64

#
function
void WriteUnaligned64(void *ptr, uint64_t value)

Writes a uint64 to a possibly unaligned address

Parameters

NameTypeRoleDefault
ptrvoid *
valueuint64_t

ReadLE16

#
function
uint16_t ReadLE16(const void *ptr)

Reads a little-endian uint16 from unaligned memory

Parameters

NameTypeRoleDefault
ptrconst void *

ReadLE32

#
function
uint32_t ReadLE32(const void *ptr)

Reads a little-endian uint32 from unaligned memory

Parameters

NameTypeRoleDefault
ptrconst void *

ReadLE64

#
function
uint64_t ReadLE64(const void *ptr)

Reads a little-endian uint64 from unaligned memory

Parameters

NameTypeRoleDefault
ptrconst void *

ReadBE16

#
function
uint16_t ReadBE16(const void *ptr)

Reads a big-endian uint16 from unaligned memory

Parameters

NameTypeRoleDefault
ptrconst void *

ReadBE32

#
function
uint32_t ReadBE32(const void *ptr)

Reads a big-endian uint32 from unaligned memory

Parameters

NameTypeRoleDefault
ptrconst void *

ReadBE64

#
function
uint64_t ReadBE64(const void *ptr)

Reads a big-endian uint64 from unaligned memory

Parameters

NameTypeRoleDefault
ptrconst void *

WriteLE16

#
function
void WriteLE16(void *ptr, uint16_t value)

Writes a little-endian uint16 to unaligned memory

Parameters

NameTypeRoleDefault
ptrvoid *
valueuint16_t

WriteLE32

#
function
void WriteLE32(void *ptr, uint32_t value)

Writes a little-endian uint32 to unaligned memory

Parameters

NameTypeRoleDefault
ptrvoid *
valueuint32_t

WriteLE64

#
function
void WriteLE64(void *ptr, uint64_t value)

Writes a little-endian uint64 to unaligned memory

Parameters

NameTypeRoleDefault
ptrvoid *
valueuint64_t

WriteBE16

#
function
void WriteBE16(void *ptr, uint16_t value)

Writes a big-endian uint16 to unaligned memory

Parameters

NameTypeRoleDefault
ptrvoid *
valueuint16_t

WriteBE32

#
function
void WriteBE32(void *ptr, uint32_t value)

Writes a big-endian uint32 to unaligned memory

Parameters

NameTypeRoleDefault
ptrvoid *
valueuint32_t

WriteBE64

#
function
void WriteBE64(void *ptr, uint64_t value)

Writes a big-endian uint64 to unaligned memory

Parameters

NameTypeRoleDefault
ptrvoid *
valueuint64_t

NK_BSWAP16

#
macro
#define NK_BSWAP16(x)

Short alias for ByteSwap16

NK_BSWAP32

#
macro
#define NK_BSWAP32(x)

Short alias for ByteSwap32

NK_BSWAP64

#
macro
#define NK_BSWAP64(x)

Short alias for ByteSwap64

NK_HTON16

#
macro
#define NK_HTON16(x)

Short alias for HostToNetwork16 (htons equivalent)

NK_HTON32

#
macro
#define NK_HTON32(x)

Short alias for HostToNetwork32 (htonl equivalent)

NK_HTON64

#
macro
#define NK_HTON64(x)

Short alias for HostToNetwork64

NK_NTOH16

#
macro
#define NK_NTOH16(x)

Short alias for NetworkToHost16 (ntohs equivalent)

NK_NTOH32

#
macro
#define NK_NTOH32(x)

Short alias for NetworkToHost32 (ntohl equivalent)

NK_NTOH64

#
macro
#define NK_NTOH64(x)

Short alias for NetworkToHost64