ionPutVarUInt

size_t
ionPutVarUInt
(
T
)
(
scope ubyte* ptr
,
const T num
)
if (
isUnsigned!T
)

Examples

1 ubyte[19] data = void;
2 
3 alias AliasSeq(T...) = T;
4 
5 foreach(T; AliasSeq!(ubyte, ushort, uint, ulong))
6 {
7     data[] = 0;
8     assert(ionPutVarUInt!T(data.ptr, 0) == 1);
9     assert(data[0] == 0x80);
10 
11     data[] = 0;
12     assert(ionPutVarUInt!T(data.ptr, 1) == 1);
13     assert(data[0] == 0x81);
14 
15     data[] = 0;
16     assert(ionPutVarUInt!T(data.ptr, 0x7F) == 1);
17     assert(data[0] == 0xFF);
18 
19     data[] = 0;
20     assert(ionPutVarUInt!T(data.ptr, 0xFF) == 2);
21     assert(data[0] == 0x01);
22     assert(data[1] == 0xFF);
23 }
24 
25 foreach(T; AliasSeq!(ushort, uint, ulong))
26 {
27 
28     data[] = 0;
29     assert(ionPutVarUInt!T(data.ptr, 0x3FFF) == 2);
30     assert(data[0] == 0x7F);
31     assert(data[1] == 0xFF);
32 
33     data[] = 0;
34     assert(ionPutVarUInt!T(data.ptr, 0x7FFF) == 3);
35     assert(data[0] == 0x01);
36     assert(data[1] == 0x7F);
37     assert(data[2] == 0xFF);
38 
39     data[] = 0;
40     assert(ionPutVarUInt!T(data.ptr, 0xFFEE) == 3);
41     assert(data[0] == 0x03);
42     assert(data[1] == 0x7F);
43     assert(data[2] == 0xEE);
44 }
45 
46 data[] = 0;
47 assert(ionPutVarUInt(data.ptr, uint.max) == 5);
48 assert(data[0] == 0x0F);
49 assert(data[1] == 0x7F);
50 assert(data[2] == 0x7F);
51 assert(data[3] == 0x7F);
52 assert(data[4] == 0xFF);
53 
54 data[] = 0;
55 assert(ionPutVarUInt!ulong(data.ptr, ulong.max >> 1) == 9);
56 assert(data[0] == 0x7F);
57 assert(data[1] == 0x7F);
58 assert(data[2] == 0x7F);
59 assert(data[3] == 0x7F);
60 assert(data[4] == 0x7F);
61 assert(data[5] == 0x7F);
62 assert(data[6] == 0x7F);
63 assert(data[7] == 0x7F);
64 assert(data[8] == 0xFF);
65 
66 data[] = 0;
67 assert(ionPutVarUInt(data.ptr, ulong.max) == 10);
68 assert(data[0] == 0x01);
69 assert(data[1] == 0x7F);
70 assert(data[2] == 0x7F);
71 assert(data[3] == 0x7F);
72 assert(data[4] == 0x7F);
73 assert(data[5] == 0x7F);
74 assert(data[6] == 0x7F);
75 assert(data[7] == 0x7F);
76 assert(data[8] == 0x7F);
77 assert(data[9] == 0xFF);

Meta