The OpenD Programming Language

ionPutIntFieldR

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

Examples

1 ubyte[9] data;
2 
3 alias AliasSeq(T...) = T;
4 
5 foreach(T; AliasSeq!(ubyte, ushort, uint, ulong))
6 {
7     data[] = 0;
8     assert(ionPutIntFieldR!T(data.ptr + 9, 0, false) == 0, T.stringof);
9 
10     data[] = 0;
11     assert(ionPutIntFieldR!T(data.ptr + 9, 0, true) == 1);
12     assert(data[$ - 1] == 0x80);
13 
14     data[] = 0;
15     assert(ionPutIntFieldR!T(data.ptr + 9, 1, false) == 1);
16     assert(data[$ - 1] == 0x01);
17 
18     data[] = 0;
19     assert(ionPutIntFieldR!T(data.ptr + 9, 1, true) == 1);
20     assert(data[$ - 1] == 0x81);
21 
22     data[] = 0;
23     assert(ionPutIntFieldR!T(data.ptr + 9, 0x3F, true) == 1);
24     assert(data[$ - 1] == 0xBF);
25 
26     data[] = 0;
27     assert(ionPutIntFieldR!T(data.ptr + 9, 0xFF, false) == 2);
28     assert(data[$ - 2] == 0x00);
29     assert(data[$ - 1] == 0xFF);
30 
31     data[] = 0;
32     assert(ionPutIntFieldR!T(data.ptr + 9, 0xFF, true) == 2);
33     assert(data[$ - 2] == 0x80);
34     assert(data[$ - 1] == 0xFF);
35 
36     data[] = 0;
37     assert(ionPutIntFieldR!T(data.ptr + 9, 0x80, true) == 2);
38     assert(data[$ - 2] == 0x80);
39     assert(data[$ - 1] == 0x80);
40 }
41 
42 data[] = 0;
43 assert(ionPutIntFieldR(data.ptr + 9, int.max) == 4);
44 assert(data[5 + 0] == 0x7F);
45 assert(data[5 + 1] == 0xFF);
46 assert(data[5 + 2] == 0xFF);
47 assert(data[5 + 3] == 0xFF);
48 
49 data[] = 0;
50 assert(ionPutIntFieldR(data.ptr + 9, int.min) == 5);
51 assert(data[4 + 0] == 0x80);
52 assert(data[4 + 1] == 0x80);
53 assert(data[4 + 2] == 0x00);
54 assert(data[4 + 3] == 0x00);
55 assert(data[4 + 4] == 0x00);
56 
57 data[] = 0;
58 assert(ionPutIntFieldR(data.ptr + 9, long.max >> 1) == 8);
59 assert(data[1 + 0] == 0x3F);
60 assert(data[1 + 1] == 0xFF);
61 assert(data[1 + 2] == 0xFF);
62 assert(data[1 + 3] == 0xFF);
63 assert(data[1 + 4] == 0xFF);
64 assert(data[1 + 5] == 0xFF);
65 assert(data[1 + 6] == 0xFF);
66 assert(data[1 + 7] == 0xFF);
67 
68 data[] = 0;
69 assert(ionPutIntFieldR(data.ptr + 9, long.max) == 8);
70 assert(data[1 + 0] == 0x7F);
71 assert(data[1 + 1] == 0xFF);
72 assert(data[1 + 2] == 0xFF);
73 assert(data[1 + 3] == 0xFF);
74 assert(data[1 + 4] == 0xFF);
75 assert(data[1 + 5] == 0xFF);
76 assert(data[1 + 6] == 0xFF);
77 assert(data[1 + 7] == 0xFF);
78 
79 data[] = 0xFF;
80 assert(ionPutIntFieldR!ulong(data.ptr + 9, long.max + 1, false) == 9);
81 assert(data[0] == 0x00);
82 assert(data[1] == 0x80);
83 assert(data[2] == 0x00);
84 assert(data[3] == 0x00);
85 assert(data[4] == 0x00);
86 assert(data[5] == 0x00);
87 assert(data[6] == 0x00);
88 assert(data[7] == 0x00);
89 assert(data[8] == 0x00);
90 
91 data[] = 0;
92 assert(ionPutIntFieldR(data.ptr + 9, ulong.max, true) == 9);
93 assert(data[0] == 0x80);
94 assert(data[1] == 0xFF);
95 assert(data[2] == 0xFF);
96 assert(data[3] == 0xFF);
97 assert(data[4] == 0xFF);
98 assert(data[5] == 0xFF);
99 assert(data[6] == 0xFF);
100 assert(data[7] == 0xFF);
101 assert(data[8] == 0xFF);

Meta