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 #ifndef ALREADY_DID_BINIO_STDINT
21 #define ALREADY_DID_BINIO_STDINT
22 #if defined(BinIO_STDINT_HEADER)
23 #include BinIO_STDINT_HEADER
24 typedef float float32_t;
25 typedef double float64_t;
27 typedef unsigned char uint8_t;
28 typedef unsigned short uint16_t;
29 typedef unsigned long uint32_t;
31 typedef unsigned __int64 uint64_t;
33 typedef unsigned long long uint64_t;
35 typedef float float32_t;
36 typedef double float64_t;
42 #define BinIO_INLINE static inline
44 #define BinIO_INLINE static
48 #ifndef BinIO_BYTE_ORDER
49 #if defined(__ppc__) || defined(__POWERPC__)
50 #define BinIO_BYTE_ORDER BinIO_BIG_ENDIAN_BYTE_ORDER
52 #define BinIO_BYTE_ORDER BinIO_LITTLE_ENDIAN_BYTE_ORDER
56 BinIO_INLINE void BinIOSwap1(const uint8_t *src, uint8_t *dst)
61 BinIO_INLINE void BinIOSwap2(const uint8_t *src, uint8_t *dst)
63 *(dst + 1) = *(src + 0);
64 *(dst + 0) = *(src + 1);
67 BinIO_INLINE void BinIOSwap4(const uint8_t *src, uint8_t *dst)
69 *(dst + 3) = *(src + 0);
70 *(dst + 2) = *(src + 1);
71 *(dst + 1) = *(src + 2);
72 *(dst + 0) = *(src + 3);
75 BinIO_INLINE void BinIOSwap8(const uint8_t *src, uint8_t *dst)
77 *(dst + 7) = *(src + 0);
78 *(dst + 6) = *(src + 1);
79 *(dst + 5) = *(src + 2);
80 *(dst + 4) = *(src + 3);
81 *(dst + 3) = *(src + 4);
82 *(dst + 2) = *(src + 5);
83 *(dst + 1) = *(src + 6);
84 *(dst + 0) = *(src + 7);
87 BinIO_INLINE int BinIONormalizeByteOrder(int byte_order)
89 if (byte_order == BinIO_HOST_BYTE_ORDER)
91 byte_order = BinIO_BYTE_ORDER;
93 else if (byte_order == BinIO_NETWORK_BYTE_ORDER)
95 byte_order = BinIO_BIG_ENDIAN_BYTE_ORDER;
101 extern void BinIOConvert1(int from_byte_order, int to_byte_order,
102 const uint8_t *src, uint8_t *dst,
104 extern void BinIOConvert2(int from_byte_order, int to_byte_order,
105 const uint8_t *src, uint8_t *dst,
107 extern void BinIOConvert4(int from_byte_order, int to_byte_order,
108 const uint8_t *src, uint8_t *dst,
110 extern void BinIOConvert8(int from_byte_order, int to_byte_order,
111 const uint8_t *src, uint8_t *dst,
114 struct BinIOFormatCursor
121 typedef void (*BinIOProcessFunction)(void *context,
126 extern void BinIOInitFormatCursor(struct BinIOFormatCursor *cursor,
129 extern int BinIONextChar(void *context,
130 struct BinIOFormatCursor *cursor,
131 BinIOProcessFunction func);
133 extern void BinIOCountBytes(void *context, int type, int byte_order, int count);
135 extern size_t BinIOFormatByteCount(const char *format);