7 #define BinIO_TYPE_IGNORE_BYTE 'x'
8 #define BinIO_TYPE_BYTE 'b'
9 #define BinIO_TYPE_INT16 's'
10 #define BinIO_TYPE_INT32 'i'
11 #define BinIO_TYPE_INT64 'l'
12 #define BinIO_TYPE_FLOAT32 'f'
13 #define BinIO_TYPE_FLOAT64 'd'
15 #define BinIO_LITTLE_ENDIAN_BYTE_ORDER 'L'
16 #define BinIO_BIG_ENDIAN_BYTE_ORDER 'B'
17 #define BinIO_HOST_BYTE_ORDER 'H'
18 #define BinIO_NETWORK_BYTE_ORDER 'N'
20 #if defined(BinIO_STDINT_HEADER)
21 #include BinIO_STDINT_HEADER
22 typedef float float32_t;
23 typedef double float64_t;
25 typedef unsigned char uint8_t;
26 typedef unsigned short uint16_t;
27 typedef unsigned long uint32_t;
29 typedef unsigned __int64 uint64_t;
31 typedef unsigned long long uint64_t;
33 typedef float float32_t;
34 typedef double float64_t;
39 #define BinIO_INLINE static inline
41 #define BinIO_INLINE static
45 #ifndef BinIO_BYTE_ORDER
46 #if defined(__ppc__) || defined(__POWERPC__)
47 #define BinIO_BYTE_ORDER BinIO_BIG_ENDIAN_BYTE_ORDER
49 #define BinIO_BYTE_ORDER BinIO_LITTLE_ENDIAN_BYTE_ORDER
53 BinIO_INLINE void BinIOSwap1(const uint8_t *src, uint8_t *dst)
58 BinIO_INLINE void BinIOSwap2(const uint8_t *src, uint8_t *dst)
60 *(dst + 1) = *(src + 0);
61 *(dst + 0) = *(src + 1);
64 BinIO_INLINE void BinIOSwap4(const uint8_t *src, uint8_t *dst)
66 *(dst + 3) = *(src + 0);
67 *(dst + 2) = *(src + 1);
68 *(dst + 1) = *(src + 2);
69 *(dst + 0) = *(src + 3);
72 BinIO_INLINE void BinIOSwap8(const uint8_t *src, uint8_t *dst)
74 *(dst + 7) = *(src + 0);
75 *(dst + 6) = *(src + 1);
76 *(dst + 5) = *(src + 2);
77 *(dst + 4) = *(src + 3);
78 *(dst + 3) = *(src + 4);
79 *(dst + 2) = *(src + 5);
80 *(dst + 1) = *(src + 6);
81 *(dst + 0) = *(src + 7);
84 BinIO_INLINE int BinIONormalizeByteOrder(int byte_order)
86 if (byte_order == BinIO_HOST_BYTE_ORDER)
88 byte_order = BinIO_BYTE_ORDER;
90 else if (byte_order == BinIO_NETWORK_BYTE_ORDER)
92 byte_order = BinIO_BIG_ENDIAN_BYTE_ORDER;
98 extern void BinIOConvert1(int from_byte_order, int to_byte_order,
99 const uint8_t *src, uint8_t *dst,
101 extern void BinIOConvert2(int from_byte_order, int to_byte_order,
102 const uint8_t *src, uint8_t *dst,
104 extern void BinIOConvert4(int from_byte_order, int to_byte_order,
105 const uint8_t *src, uint8_t *dst,
107 extern void BinIOConvert8(int from_byte_order, int to_byte_order,
108 const uint8_t *src, uint8_t *dst,
111 struct BinIOFormatCursor
118 typedef void (*BinIOProcessFunction)(void *context,
123 extern void BinIOInitFormatCursor(struct BinIOFormatCursor *cursor,
126 extern int BinIONextChar(void *context,
127 struct BinIOFormatCursor *cursor,
128 BinIOProcessFunction func);
130 extern void BinIOCountBytes(void *context, int type, int byte_order, int count);
132 extern size_t BinIOFormatByteCount(const char *format);