7 #define DEFPACK_BE(bits, type) void pack_ ## bits ## _be ( \
8 unsigned char *out, type v \
11 for (i = 1; i <= bits/8; i++) { \
12 out[bits/8 - i] = v % 256; \
17 #define DEFPACK_LE(bits, type) void pack_ ## bits ## _le ( \
18 unsigned char *out, type v \
21 for (i = 0; i < bits/8; i++) { \
27 DEFPACK_BE(16, unsigned short)
28 DEFPACK_BE(32, unsigned long)
30 DEFPACK_BE(64, unsigned long long)
33 DEFPACK_LE(16, unsigned short)
34 DEFPACK_LE(32, unsigned long)
36 DEFPACK_LE(64, unsigned long long)
39 #define DEFUNPACK_BE(bits, type) type unpack_ ## bits ## _be ( \
44 for (i = 0; i < bits/8; i++) { \
51 #define DEFUNPACK_LE(bits, type) type unpack_ ## bits ## _le ( \
56 for (i = 1; i <= bits/8; i++) { \
58 v += in[bits/8 - i]; \
63 DEFUNPACK_BE(16, unsigned short)
64 DEFUNPACK_BE(32, unsigned long)
66 DEFUNPACK_BE(64, unsigned long long)
69 DEFUNPACK_LE(16, unsigned short)
70 DEFUNPACK_LE(32, unsigned long)
72 DEFUNPACK_LE(64, unsigned long long)