-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.c
46 lines (36 loc) · 948 Bytes
/
test.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#include "leb128r.h"
#include <stdio.h>
#define pf printf
static const uint64_t U[] = {
1 << 14,
(1 << 14) + 127,
~0LU,
345635437642,
65460,
56,
};
static const int64_t I[] = {
0,
(1 << 13) + 63,
-((1 << 13) + 64),
-97701,
987756545,
1L << 63
};
int main(void) {
pf("\n"); uint64_t a, b; uint8_t r[10], *p;
for (uint64_t i = 0; i < sizeof(U) / 8; ++i) {
a = U[i], p = leb128r_encode_u64(a, r);
pf("e: %20lu %20ld\n", a, p - r);
p = (void *)leb128r_decode_u64(&b, r); if (a != b) goto e;
pf("d: %20lu %20ld\n\n", b, p - r);
}
for (uint64_t i = 0; i < sizeof(I) / 8; ++i) {
a = I[i], p = leb128r_encode_i64(a, r);
pf("e: %20ld %20ld\n", a, p - r);
p = (void *)leb128r_decode_i64(&b, r); if (a != b) goto e;
pf("d: %20ld %20ld\n\n", b, p - r);
}
return 0;
e: pf("F*\n"); return 1;
}