The OpenD Programming Language

ionPutVarIntR

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

Examples

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

Meta