mirror of
https://github.com/thepigeongenerator/mcaselector-lite.git
synced 2025-12-19 05:25:45 +01:00
define short-hand types for int32/uint32 et cetera
This commit is contained in:
@@ -5,50 +5,51 @@
|
||||
#include <stdint.h>
|
||||
|
||||
#include "../atrb.h"
|
||||
#include "../types.h"
|
||||
#include "bswap.h"
|
||||
|
||||
/* little endian */
|
||||
atrb_const static inline uint16_t le16ton(uint16_t); // converts little-endian (LE) encoding to native for a 16 bit integer. (NOOP if native is LE)
|
||||
atrb_const static inline uint32_t le32ton(uint32_t); // converts little-endian (LE) encoding to native for a 32 bit integer. (NOOP if native is LE)
|
||||
atrb_const static inline uint64_t le64ton(uint64_t); // converts little-endian (LE) encoding to native for a 64 bit integer. (NOOP if native is LE)
|
||||
atrb_const static inline uint16_t ntole16(uint16_t); // converts native encoding to little-endian (LE) for a 16 bit integer. (NOOP if native is LE)
|
||||
atrb_const static inline uint32_t ntole32(uint32_t); // converts native encoding to little-endian (LE) for a 32 bit integer. (NOOP if native is LE)
|
||||
atrb_const static inline uint64_t ntole64(uint64_t); // converts native encoding to little-endian (LE) for a 64 bit integer. (NOOP if native is LE)
|
||||
atrb_const static inline u16 le16ton(u16); // converts little-endian (LE) encoding to native for a 16 bit integer. (NOOP if native is LE)
|
||||
atrb_const static inline u32 le32ton(u32); // converts little-endian (LE) encoding to native for a 32 bit integer. (NOOP if native is LE)
|
||||
atrb_const static inline u64 le64ton(u64); // converts little-endian (LE) encoding to native for a 64 bit integer. (NOOP if native is LE)
|
||||
atrb_const static inline u16 ntole16(u16); // converts native encoding to little-endian (LE) for a 16 bit integer. (NOOP if native is LE)
|
||||
atrb_const static inline u32 ntole32(u32); // converts native encoding to little-endian (LE) for a 32 bit integer. (NOOP if native is LE)
|
||||
atrb_const static inline u64 ntole64(u64); // converts native encoding to little-endian (LE) for a 64 bit integer. (NOOP if native is LE)
|
||||
|
||||
/* big endian */
|
||||
atrb_const static inline uint16_t be16ton(uint16_t); // converts big-endian (BE) encoding to native for a 16 bit integer. (NOOP if native is BE)
|
||||
atrb_const static inline uint32_t be32ton(uint32_t); // converts big-endian (BE) encoding to native for a 32 bit integer. (NOOP if native is BE)
|
||||
atrb_const static inline uint64_t be64ton(uint64_t); // converts big-endian (BE) encoding to native for a 64 bit integer. (NOOP if native is BE)
|
||||
atrb_const static inline uint16_t ntobe16(uint16_t); // converts native encoding to big-endian (BE) for a 16 bit integer. (NOOP if native is BE)
|
||||
atrb_const static inline uint32_t ntobe32(uint32_t); // converts native encoding to big-endian (BE) for a 32 bit integer. (NOOP if native is BE)
|
||||
atrb_const static inline uint64_t ntobe64(uint64_t); // converts native encoding to big-endian (BE) for a 64 bit integer. (NOOP if native is BE)
|
||||
atrb_const static inline u16 be16ton(u16); // converts big-endian (BE) encoding to native for a 16 bit integer. (NOOP if native is BE)
|
||||
atrb_const static inline u32 be32ton(u32); // converts big-endian (BE) encoding to native for a 32 bit integer. (NOOP if native is BE)
|
||||
atrb_const static inline u64 be64ton(u64); // converts big-endian (BE) encoding to native for a 64 bit integer. (NOOP if native is BE)
|
||||
atrb_const static inline u16 ntobe16(u16); // converts native encoding to big-endian (BE) for a 16 bit integer. (NOOP if native is BE)
|
||||
atrb_const static inline u32 ntobe32(u32); // converts native encoding to big-endian (BE) for a 32 bit integer. (NOOP if native is BE)
|
||||
atrb_const static inline u64 ntobe64(u64); // converts native encoding to big-endian (BE) for a 64 bit integer. (NOOP if native is BE)
|
||||
|
||||
#if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
|
||||
uint16_t le16ton(uint16_t x) { return x; }
|
||||
uint32_t le32ton(uint32_t x) { return x; }
|
||||
uint64_t le64ton(uint64_t x) { return x; }
|
||||
uint16_t ntole16(uint16_t x) { return x; }
|
||||
uint32_t ntole32(uint32_t x) { return x; }
|
||||
uint64_t ntole64(uint64_t x) { return x; }
|
||||
uint16_t be16ton(uint16_t x) { return bswap16(x); }
|
||||
uint32_t be32ton(uint32_t x) { return bswap32(x); }
|
||||
uint64_t be64ton(uint64_t x) { return bswap64(x); }
|
||||
uint16_t ntobe16(uint16_t x) { return bswap16(x); }
|
||||
uint32_t ntobe32(uint32_t x) { return bswap32(x); }
|
||||
uint64_t ntobe64(uint64_t x) { return bswap64(x); }
|
||||
u16 le16ton(u16 x) { return x; }
|
||||
u32 le32ton(u32 x) { return x; }
|
||||
u64 le64ton(u64 x) { return x; }
|
||||
u16 ntole16(u16 x) { return x; }
|
||||
u32 ntole32(u32 x) { return x; }
|
||||
u64 ntole64(u64 x) { return x; }
|
||||
u16 be16ton(u16 x) { return bswap16(x); }
|
||||
u32 be32ton(u32 x) { return bswap32(x); }
|
||||
u64 be64ton(u64 x) { return bswap64(x); }
|
||||
u16 ntobe16(u16 x) { return bswap16(x); }
|
||||
u32 ntobe32(u32 x) { return bswap32(x); }
|
||||
u64 ntobe64(u64 x) { return bswap64(x); }
|
||||
#elif __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__
|
||||
uint16_t le16ton(uint16_t x) { bswap_16(x); }
|
||||
uint32_t le32ton(uint32_t x) { bswap_32(x); }
|
||||
uint64_t le64ton(uint64_t x) { bswap_64(x); }
|
||||
uint16_t ntole16(uint16_t x) { bswap_16(x); }
|
||||
uint32_t ntole32(uint32_t x) { bswap_32(x); }
|
||||
uint64_t ntole64(uint64_t x) { bswap_64(x); }
|
||||
uint16_t be16ton(uint16_t x) { return x; }
|
||||
uint32_t be32ton(uint32_t x) { return x; }
|
||||
uint64_t be64ton(uint64_t x) { return x; }
|
||||
uint16_t ntobe16(uint16_t x) { return x; }
|
||||
uint32_t ntobe32(uint32_t x) { return x; }
|
||||
uint64_t ntobe64(uint64_t x) { return x; }
|
||||
u16 le16ton(u16 x) { bswap_16(x); }
|
||||
u32 le32ton(u32 x) { bswap_32(x); }
|
||||
u64 le64ton(u64 x) { bswap_64(x); }
|
||||
u16 ntole16(u16 x) { bswap_16(x); }
|
||||
u32 ntole32(u32 x) { bswap_32(x); }
|
||||
u64 ntole64(u64 x) { bswap_64(x); }
|
||||
u16 be16ton(u16 x) { return x; }
|
||||
u32 be32ton(u32 x) { return x; }
|
||||
u64 be64ton(u64 x) { return x; }
|
||||
u16 ntobe16(u16 x) { return x; }
|
||||
u32 ntobe32(u32 x) { return x; }
|
||||
u64 ntobe64(u64 x) { return x; }
|
||||
#else
|
||||
#error machine architecture unsupported! Expected either big-endian or little-endian, make sure to use a compiler which defines __BYTE_ORDER__ (like clang or gcc)
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user