The OpenD Programming Language

ionPutVarInt

  1. size_t ionPutVarInt(ubyte* ptr, T num)
  2. size_t ionPutVarInt(ubyte* ptr, T num, bool sign)
    size_t
    ionPutVarInt
    (
    T
    )
    (
    scope ubyte* ptr
    ,
    const T num
    ,
    bool sign
    )

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(ionPutVarInt!T(data.ptr, 0, false) == 1);
9     assert(data[0] == 0x80);
10 
11     data[] = 0;
12     assert(ionPutVarInt!T(data.ptr, 1, false) == 1);
13     assert(data[0] == 0x81);
14 
15     data[] = 0;
16     assert(ionPutVarInt!T(data.ptr, 1, true) == 1);
17     assert(data[0] == 0xC1);
18 
19     data[] = 0;
20     assert(ionPutVarInt!T(data.ptr, 0x3F, false) == 1);
21     assert(data[0] == 0xBF);
22 
23     data[] = 0;
24     assert(ionPutVarInt!T(data.ptr, 0x3F, true) == 1);
25     assert(data[0] == 0xFF);
26 
27     data[] = 0;
28     assert(ionPutVarInt!T(data.ptr, 0x7F, false) == 2);
29     assert(data[0] == 0x00);
30     assert(data[1] == 0xFF);
31 
32     data[] = 0;
33     assert(ionPutVarInt!T(data.ptr, 128, true) == 2);
34     assert(data[0] == 0x41);
35     assert(data[1] == 0x80);
36 
37     data[] = 0;
38     assert(ionPutVarInt!T(data.ptr, 127, true) == 2);
39     assert(data[0] == 0x40);
40     assert(data[1] == 0xFF);
41 
42 
43     data[] = 0;
44     assert(ionPutVarInt!T(data.ptr, 3, true) == 1);
45     assert(data[0] == 0xC3);
46 
47     data[] = 0;
48     assert(ionPutVarInt!T(data.ptr, 127, true) == 2);
49     assert(data[0] == 0x40);
50     assert(data[1] == 0xFF);
51 
52     data[] = 0;
53     assert(ionPutVarInt!T(data.ptr, 63, true) == 1);
54     assert(data[0] == 0xFF);
55 }
56 
57 data[] = 0;
58 assert(ionPutVarInt!uint(data.ptr, int.max, false) == 5);
59 assert(data[0] == 0x07);
60 assert(data[1] == 0x7F);
61 assert(data[2] == 0x7F);
62 assert(data[3] == 0x7F);
63 assert(data[4] == 0xFF);
64 
65 data[] = 0;
66 assert(ionPutVarInt!uint(data.ptr, int.max, true) == 5);
67 assert(data[0] == 0x47);
68 assert(data[1] == 0x7F);
69 assert(data[2] == 0x7F);
70 assert(data[3] == 0x7F);
71 assert(data[4] == 0xFF);
72 
73 data[] = 0;
74 assert(ionPutVarInt!uint(data.ptr, int.max + 1, true) == 5);
75 assert(data[0] == 0x48);
76 assert(data[1] == 0x00);
77 assert(data[2] == 0x00);
78 assert(data[3] == 0x00);
79 assert(data[4] == 0x80);
80 
81 data[] = 0;
82 assert(ionPutVarInt!ulong(data.ptr, long.max >> 1, false) == 9);
83 assert(data[0] == 0x3F);
84 assert(data[1] == 0x7F);
85 assert(data[2] == 0x7F);
86 assert(data[3] == 0x7F);
87 assert(data[4] == 0x7F);
88 assert(data[5] == 0x7F);
89 assert(data[6] == 0x7F);
90 assert(data[7] == 0x7F);
91 assert(data[8] == 0xFF);
92 
93 data[] = 0;
94 assert(ionPutVarInt!ulong(data.ptr, long.max, false) == 10);
95 assert(data[0] == 0x00);
96 assert(data[1] == 0x7F);
97 assert(data[2] == 0x7F);
98 assert(data[3] == 0x7F);
99 assert(data[4] == 0x7F);
100 assert(data[5] == 0x7F);
101 assert(data[6] == 0x7F);
102 assert(data[7] == 0x7F);
103 assert(data[8] == 0x7F);
104 assert(data[9] == 0xFF);
105 
106 data[] = 0;
107 assert(ionPutVarInt!ulong(data.ptr, long.max, true) == 10);
108 assert(data[0] == 0x40);
109 assert(data[1] == 0x7F);
110 assert(data[2] == 0x7F);
111 assert(data[3] == 0x7F);
112 assert(data[4] == 0x7F);
113 assert(data[5] == 0x7F);
114 assert(data[6] == 0x7F);
115 assert(data[7] == 0x7F);
116 assert(data[8] == 0x7F);
117 assert(data[9] == 0xFF);
118 
119 data[] = 0;
120 assert(ionPutVarInt!ulong(data.ptr, -long.min, true) == 10);
121 assert(data[0] == 0x41);
122 assert(data[1] == 0x00);
123 assert(data[2] == 0x00);
124 assert(data[3] == 0x00);
125 assert(data[4] == 0x00);
126 assert(data[5] == 0x00);
127 assert(data[6] == 0x00);
128 assert(data[7] == 0x00);
129 assert(data[8] == 0x00);
130 assert(data[9] == 0x80);
131 
132 data[] = 0;
133 assert(ionPutVarInt(data.ptr, ulong.max, true) == 10);
134 assert(data[0] == 0x41);
135 assert(data[1] == 0x7F);
136 assert(data[2] == 0x7F);
137 assert(data[3] == 0x7F);
138 assert(data[4] == 0x7F);
139 assert(data[5] == 0x7F);
140 assert(data[6] == 0x7F);
141 assert(data[7] == 0x7F);
142 assert(data[8] == 0x7F);
143 assert(data[9] == 0xFF);
144 
145 data[] = 0;
146 assert(ionPutVarInt(data.ptr, ulong.max, false) == 10);
147 assert(data[0] == 0x01);
148 assert(data[1] == 0x7F);
149 assert(data[2] == 0x7F);
150 assert(data[3] == 0x7F);
151 assert(data[4] == 0x7F);
152 assert(data[5] == 0x7F);
153 assert(data[6] == 0x7F);
154 assert(data[7] == 0x7F);
155 assert(data[8] == 0x7F);
156 assert(data[9] == 0xFF);

Meta