5 void BinIOConvert1(int from_byte_order, int to_byte_order,
6 const uint8_t *src, uint8_t *dst,
9 if (BinIONormalizeByteOrder(from_byte_order) !=
10 BinIONormalizeByteOrder(to_byte_order))
13 for (i = 0; i < count; ++i)
22 memcpy(dst, src, 1 * count);
26 void BinIOConvert2(int from_byte_order, int to_byte_order,
27 const uint8_t *src, uint8_t *dst,
30 if (BinIONormalizeByteOrder(from_byte_order) !=
31 BinIONormalizeByteOrder(to_byte_order))
34 for (i = 0; i < count; ++i)
43 memcpy(dst, src, 2 * count);
47 void BinIOConvert4(int from_byte_order, int to_byte_order,
48 const uint8_t *src, uint8_t *dst,
51 if (BinIONormalizeByteOrder(from_byte_order) !=
52 BinIONormalizeByteOrder(to_byte_order))
55 for (i = 0; i < count; ++i)
64 memcpy(dst, src, 4 * count);
68 void BinIOConvert8(int from_byte_order, int to_byte_order,
69 const uint8_t *src, uint8_t *dst,
72 if (BinIONormalizeByteOrder(from_byte_order) !=
73 BinIONormalizeByteOrder(to_byte_order))
76 for (i = 0; i < count; ++i)
85 memcpy(dst, src, 8 * count);
89 void BinIOInitFormatCursor(struct BinIOFormatCursor *cursor,
92 cursor->cursor = format;
93 cursor->byte_order = BinIO_HOST_BYTE_ORDER;
97 int BinIONextChar(void *context,
98 struct BinIOFormatCursor *cursor,
99 BinIOProcessFunction func)
103 switch (c = *(cursor->cursor)++)
105 case BinIO_LITTLE_ENDIAN_BYTE_ORDER:
106 case BinIO_BIG_ENDIAN_BYTE_ORDER:
107 case BinIO_HOST_BYTE_ORDER:
108 case BinIO_NETWORK_BYTE_ORDER:
109 cursor->byte_order = c;
112 case '0': case '1': case '2': case '3': case '4':
113 case '5': case '6': case '7': case '8': case '9':
114 count = cursor->count;
118 cursor->count = value;
122 cursor->count = (count * 10) + value;
126 case BinIO_TYPE_IGNORE_BYTE:
127 case BinIO_TYPE_BYTE:
128 case BinIO_TYPE_INT16:
129 case BinIO_TYPE_INT32:
130 case BinIO_TYPE_INT64:
131 case BinIO_TYPE_FLOAT32:
132 case BinIO_TYPE_FLOAT64:
133 func(context, c, cursor->byte_order, cursor->count);
134 cursor->byte_order = BinIO_HOST_BYTE_ORDER;
138 case ' ': case '\t': case '\r': case '\n':
148 extern void BinIOCountBytes(void *context, int type, int byte_order, int count)
150 size_t type_size = 0;
159 case BinIO_TYPE_IGNORE_BYTE: type_size = 1; break;
160 case BinIO_TYPE_BYTE: type_size = 1; break;
161 case BinIO_TYPE_INT16: type_size = 2; break;
162 case BinIO_TYPE_INT32: type_size = 4; break;
163 case BinIO_TYPE_INT64: type_size = 8; break;
164 case BinIO_TYPE_FLOAT32: type_size = 4; break;
165 case BinIO_TYPE_FLOAT64: type_size = 8; break;
168 *(size_t*)context += type_size * count;
171 extern size_t BinIOFormatByteCount(const char *format)
173 struct BinIOFormatCursor cursor;
176 BinIOInitFormatCursor(&cursor, format);
178 while (BinIONextChar(&n_bytes, &cursor, BinIOCountBytes)) {}