1 | unit UVarInt;
|
---|
2 |
|
---|
3 | {$mode delphi}
|
---|
4 |
|
---|
5 | interface
|
---|
6 |
|
---|
7 | uses
|
---|
8 | Classes, SysUtils, Math;
|
---|
9 |
|
---|
10 | const
|
---|
11 | BitAlignment = 8;
|
---|
12 |
|
---|
13 | type
|
---|
14 | { TVarInt }
|
---|
15 |
|
---|
16 | TVarInt = record
|
---|
17 | private
|
---|
18 | public
|
---|
19 | Value: Int64;
|
---|
20 | class operator Implicit(A: TVarInt): Int64;
|
---|
21 | class operator Implicit(A: TVarInt): QWord;
|
---|
22 | class operator Implicit(A: TVarInt): Integer;
|
---|
23 | class operator Implicit(A: TVarInt): Byte;
|
---|
24 | class operator Implicit(A: TVarInt): Char;
|
---|
25 | class operator Implicit(A: Byte): TVarInt;
|
---|
26 | class operator Implicit(A: Integer): TVarInt;
|
---|
27 | class operator Implicit(A: Int64): TVarInt;
|
---|
28 | class operator Implicit(A: QWord): TVarInt;
|
---|
29 | class operator Explicit(A: Byte): TVarInt;
|
---|
30 | class operator Explicit(A: Integer): TVarInt;
|
---|
31 | class operator Explicit(A: Int64): TVarInt;
|
---|
32 | class operator Explicit(A: TVarInt): Int64;
|
---|
33 | class operator Inc(A: TVarInt): TVarInt;
|
---|
34 | class operator Inc(A: TVarInt; B: TVarInt): TVarInt;
|
---|
35 | class operator Dec(A: TVarInt): TVarInt;
|
---|
36 | class operator Dec(A: TVarInt; B: TVarInt): TVarInt;
|
---|
37 | class operator Negative(A: TVarInt): TVarInt;
|
---|
38 | class operator Add(A: TVarInt; B: TVarInt): TVarInt;
|
---|
39 | class operator Multiply(A: TVarInt; B: TVarInt): TVarInt;
|
---|
40 | class operator IntDivide(A: TVarInt; B: TVarInt): TVarInt;
|
---|
41 | class operator Modulus(A: TVarInt; B: TVarInt): TVarInt;
|
---|
42 | class operator Subtract(A: TVarInt; B: TVarInt): TVarInt;
|
---|
43 | class operator Equal(A: TVarInt; B: TVarInt): Boolean;
|
---|
44 | class operator NotEqual(A: TVarInt; B: TVarInt): Boolean;
|
---|
45 | class operator GreaterThan(A: TVarInt; B: TVarInt): Boolean;
|
---|
46 | class operator GreaterThanOrEqual(A: TVarInt; B: TVarInt): Boolean;
|
---|
47 | class operator LessThan(A: TVarInt; B: TVarInt): Boolean;
|
---|
48 | class operator LessThanOrEqual(A: TVarInt; B: TVarInt): Boolean;
|
---|
49 | class operator LeftShift(A: TVarInt; B: TVarInt): TVarInt;
|
---|
50 | class operator RightShift(A: TVarInt; B: TVarInt): TVarInt;
|
---|
51 | class operator BitwiseAnd(A: TVarInt; B: TVarInt): TVarInt;
|
---|
52 | class operator BitwiseOr(A: TVarInt; B: TVarInt): TVarInt;
|
---|
53 | class operator BitwiseXor(A: TVarInt; B: TVarInt): TVarInt;
|
---|
54 | function GetByteSize: Integer;
|
---|
55 | function WriteToAddr(Ptr: Pointer): Integer;
|
---|
56 | function ReadFromAddr(Ptr: Pointer): Integer;
|
---|
57 | end;
|
---|
58 |
|
---|
59 | { TVarUInt }
|
---|
60 |
|
---|
61 | TVarUInt = record
|
---|
62 | private
|
---|
63 | public
|
---|
64 | Value: QWord;
|
---|
65 | class operator Implicit(A: TVarUInt): Int64;
|
---|
66 | class operator Implicit(A: TVarUInt): QWord;
|
---|
67 | class operator Implicit(A: TVarUInt): Integer;
|
---|
68 | class operator Implicit(A: TVarUInt): Byte;
|
---|
69 | class operator Implicit(A: TVarUInt): Char;
|
---|
70 | class operator Implicit(A: TVarUInt): TVarInt;
|
---|
71 | class operator Implicit(A: Byte): TVarUInt;
|
---|
72 | class operator Implicit(A: Integer): TVarUInt;
|
---|
73 | class operator Implicit(A: Int64): TVarUInt;
|
---|
74 | class operator Implicit(A: QWord): TVarUInt;
|
---|
75 | class operator Implicit(A: TVarInt): TVarUInt;
|
---|
76 | class operator Explicit(A: Byte): TVarUInt;
|
---|
77 | class operator Explicit(A: Integer): TVarUInt;
|
---|
78 | class operator Explicit(A: Int64): TVarUInt;
|
---|
79 | class operator Explicit(A: TVarUInt): Int64;
|
---|
80 | class operator Inc(A: TVarUInt): TVarUInt;
|
---|
81 | class operator Inc(A: TVarUInt; B: TVarInt): TVarUInt;
|
---|
82 | class operator Dec(A: TVarUInt): TVarUInt;
|
---|
83 | class operator Dec(A: TVarUInt; B: TVarUInt): TVarUInt;
|
---|
84 | class operator Negative(A: TVarUInt): TVarUInt;
|
---|
85 | class operator Add(A: TVarUInt; B: TVarUInt): TVarUInt;
|
---|
86 | class operator Multiply(A: TVarUInt; B: TVarUInt): TVarUInt;
|
---|
87 | class operator IntDivide(A: TVarUInt; B: TVarUInt): TVarUInt;
|
---|
88 | class operator Modulus(A: TVarUInt; B: TVarUInt): TVarUInt;
|
---|
89 | class operator Subtract(A: TVarUInt; B: TVarUInt): TVarUInt;
|
---|
90 | class operator Equal(A: TVarUInt; B: TVarUInt): Boolean;
|
---|
91 | class operator NotEqual(A: TVarUInt; B: TVarUInt): Boolean;
|
---|
92 | class operator GreaterThan(A: TVarUInt; B: TVarUInt): Boolean;
|
---|
93 | class operator GreaterThanOrEqual(A: TVarUInt; B: TVarUInt): Boolean;
|
---|
94 | class operator LessThan(A: TVarUInt; B: TVarUInt): Boolean;
|
---|
95 | class operator LessThanOrEqual(A: TVarUInt; B: TVarUInt): Boolean;
|
---|
96 | class operator LeftShift(A: TVarUInt; B: TVarUInt): TVarUInt;
|
---|
97 | class operator RightShift(A: TVarUInt; B: TVarUInt): TVarUInt;
|
---|
98 | class operator BitwiseAnd(A: TVarUInt; B: TVarUInt): TVarUInt;
|
---|
99 | class operator BitwiseOr(A: TVarUInt; B: TVarUInt): TVarUInt;
|
---|
100 | class operator BitwiseXor(A: TVarUInt; B: TVarUInt): TVarUInt;
|
---|
101 | function GetByteSize: Integer;
|
---|
102 | function WriteToAddr(Ptr: Pointer): Integer;
|
---|
103 | function ReadFromAddr(Ptr: Pointer): Integer;
|
---|
104 | end;
|
---|
105 |
|
---|
106 | function DecodeUnaryLength(Data: Byte): Integer;
|
---|
107 | function GetUnaryLengthMask(Length: Integer): Byte;
|
---|
108 |
|
---|
109 | resourcestring
|
---|
110 | SVarIntOverflow = 'VarInt read overflow.';
|
---|
111 |
|
---|
112 |
|
---|
113 | implementation
|
---|
114 |
|
---|
115 | function GetUnaryLengthMask(Length: Integer): Byte;
|
---|
116 | begin
|
---|
117 | Result := ((1 shl (BitAlignment - Length)) - 1) xor $ff;
|
---|
118 | end;
|
---|
119 |
|
---|
120 | function DecodeUnaryLength(Data: Byte): Integer;
|
---|
121 | begin
|
---|
122 | Result := 1;
|
---|
123 | while (((Data shr (BitAlignment - Result)) and 1) = 1) and
|
---|
124 | (Result <= BitAlignment) do Inc(Result);
|
---|
125 | end;
|
---|
126 |
|
---|
127 | { TVarUInt }
|
---|
128 |
|
---|
129 | class operator TVarUInt.Implicit(A: TVarUInt): Int64;
|
---|
130 | begin
|
---|
131 | Result := A.Value;
|
---|
132 | end;
|
---|
133 |
|
---|
134 | class operator TVarUInt.Implicit(A: TVarUInt): QWord;
|
---|
135 | begin
|
---|
136 | Result := A.Value;
|
---|
137 | end;
|
---|
138 |
|
---|
139 | class operator TVarUInt.Implicit(A: TVarUInt): Integer;
|
---|
140 | begin
|
---|
141 | Result := A.Value;
|
---|
142 | end;
|
---|
143 |
|
---|
144 | class operator TVarUInt.Implicit(A: TVarUInt): Byte;
|
---|
145 | begin
|
---|
146 | Result := A.Value;
|
---|
147 | end;
|
---|
148 |
|
---|
149 | class operator TVarUInt.Implicit(A: TVarUInt): Char;
|
---|
150 | begin
|
---|
151 | Result := Chr(A.Value);
|
---|
152 | end;
|
---|
153 |
|
---|
154 | class operator TVarUInt.Implicit(A: TVarUInt): TVarInt;
|
---|
155 | begin
|
---|
156 | Result.Value := A.Value;
|
---|
157 | end;
|
---|
158 |
|
---|
159 | class operator TVarUInt.Implicit(A: Byte): TVarUInt;
|
---|
160 | begin
|
---|
161 | Result.Value := A;
|
---|
162 | end;
|
---|
163 |
|
---|
164 | class operator TVarUInt.Implicit(A: Integer): TVarUInt;
|
---|
165 | begin
|
---|
166 | Result.Value := A;
|
---|
167 | end;
|
---|
168 |
|
---|
169 | class operator TVarUInt.Implicit(A: Int64): TVarUInt;
|
---|
170 | begin
|
---|
171 | Result.Value := A;
|
---|
172 | end;
|
---|
173 |
|
---|
174 | class operator TVarUInt.Implicit(A: QWord): TVarUInt;
|
---|
175 | begin
|
---|
176 | Result.Value := A;
|
---|
177 | end;
|
---|
178 |
|
---|
179 | class operator TVarUInt.Implicit(A: TVarInt): TVarUInt;
|
---|
180 | begin
|
---|
181 | Result.Value := A.Value;
|
---|
182 | end;
|
---|
183 |
|
---|
184 | class operator TVarUInt.Explicit(A: Byte): TVarUInt;
|
---|
185 | begin
|
---|
186 | Result.Value := A;
|
---|
187 | end;
|
---|
188 |
|
---|
189 | class operator TVarUInt.Explicit(A: Integer): TVarUInt;
|
---|
190 | begin
|
---|
191 | Result.Value := A;
|
---|
192 | end;
|
---|
193 |
|
---|
194 | class operator TVarUInt.Explicit(A: Int64): TVarUInt;
|
---|
195 | begin
|
---|
196 | Result.Value := A;
|
---|
197 | end;
|
---|
198 |
|
---|
199 | class operator TVarUInt.Explicit(A: TVarUInt): Int64;
|
---|
200 | begin
|
---|
201 | Result := A.Value;
|
---|
202 | end;
|
---|
203 |
|
---|
204 | class operator TVarUInt.Inc(A: TVarUInt): TVarUInt;
|
---|
205 | begin
|
---|
206 | Result.Value := A.Value + 1;
|
---|
207 | end;
|
---|
208 |
|
---|
209 | class operator TVarUInt.Inc(A: TVarUInt; B: TVarInt): TVarUInt;
|
---|
210 | begin
|
---|
211 | Result.Value := A.Value + B.Value;
|
---|
212 | end;
|
---|
213 |
|
---|
214 | class operator TVarUInt.Dec(A: TVarUInt): TVarUInt;
|
---|
215 | begin
|
---|
216 | Result.Value := A.Value - 1;
|
---|
217 | end;
|
---|
218 |
|
---|
219 | class operator TVarUInt.Dec(A: TVarUInt; B: TVarUInt): TVarUInt;
|
---|
220 | begin
|
---|
221 | Result.Value := A.Value - B.Value;
|
---|
222 | end;
|
---|
223 |
|
---|
224 | class operator TVarUInt.Negative(A: TVarUInt): TVarUInt;
|
---|
225 | begin
|
---|
226 | Result.Value := -A.Value;
|
---|
227 | end;
|
---|
228 |
|
---|
229 | class operator TVarUInt.Add(A: TVarUInt; B: TVarUInt): TVarUInt;
|
---|
230 | begin
|
---|
231 | Result.Value := A.Value + B.Value;
|
---|
232 | end;
|
---|
233 |
|
---|
234 | class operator TVarUInt.Multiply(A: TVarUInt; B: TVarUInt): TVarUInt;
|
---|
235 | begin
|
---|
236 | Result.Value := A.Value * B.Value;
|
---|
237 | end;
|
---|
238 |
|
---|
239 | class operator TVarUInt.IntDivide(A: TVarUInt; B: TVarUInt): TVarUInt;
|
---|
240 | begin
|
---|
241 | Result.Value := A.Value div B.Value;
|
---|
242 | end;
|
---|
243 |
|
---|
244 | class operator TVarUInt.Modulus(A: TVarUInt; B: TVarUInt): TVarUInt;
|
---|
245 | begin
|
---|
246 | Result.Value := A.Value mod B.Value;
|
---|
247 | end;
|
---|
248 |
|
---|
249 | class operator TVarUInt.Subtract(A: TVarUInt; B: TVarUInt): TVarUInt;
|
---|
250 | begin
|
---|
251 | Result.Value := A.Value - B.Value;
|
---|
252 | end;
|
---|
253 |
|
---|
254 | class operator TVarUInt.Equal(A: TVarUInt; B: TVarUInt): Boolean;
|
---|
255 | begin
|
---|
256 | Result := A.Value = B.Value;
|
---|
257 | end;
|
---|
258 |
|
---|
259 | class operator TVarUInt.NotEqual(A: TVarUInt; B: TVarUInt): Boolean;
|
---|
260 | begin
|
---|
261 | Result := A.Value <> B.Value;
|
---|
262 | end;
|
---|
263 |
|
---|
264 | class operator TVarUInt.GreaterThan(A: TVarUInt; B: TVarUInt): Boolean;
|
---|
265 | begin
|
---|
266 | Result := A.Value > B.Value;
|
---|
267 | end;
|
---|
268 |
|
---|
269 | class operator TVarUInt.GreaterThanOrEqual(A: TVarUInt; B: TVarUInt): Boolean;
|
---|
270 | begin
|
---|
271 | Result := A.Value >= B.Value;
|
---|
272 | end;
|
---|
273 |
|
---|
274 | class operator TVarUInt.LessThan(A: TVarUInt; B: TVarUInt): Boolean;
|
---|
275 | begin
|
---|
276 | Result := A.Value < B.Value;
|
---|
277 | end;
|
---|
278 |
|
---|
279 | class operator TVarUInt.LessThanOrEqual(A: TVarUInt; B: TVarUInt): Boolean;
|
---|
280 | begin
|
---|
281 | Result := A.Value <= B.Value;
|
---|
282 | end;
|
---|
283 |
|
---|
284 | class operator TVarUInt.LeftShift(A: TVarUInt; B: TVarUInt): TVarUInt;
|
---|
285 | begin
|
---|
286 | Result.Value := A.Value shl B.Value;
|
---|
287 | end;
|
---|
288 |
|
---|
289 | class operator TVarUInt.RightShift(A: TVarUInt; B: TVarUInt): TVarUInt;
|
---|
290 | begin
|
---|
291 | Result.Value := A.Value shr B.Value;
|
---|
292 | end;
|
---|
293 |
|
---|
294 | class operator TVarUInt.BitwiseAnd(A: TVarUInt; B: TVarUInt): TVarUInt;
|
---|
295 | begin
|
---|
296 | Result.Value := A.Value and B.Value;
|
---|
297 | end;
|
---|
298 |
|
---|
299 | class operator TVarUInt.BitwiseOr(A: TVarUInt; B: TVarUInt): TVarUInt;
|
---|
300 | begin
|
---|
301 | Result.Value := A.Value or B.Value;
|
---|
302 | end;
|
---|
303 |
|
---|
304 | class operator TVarUInt.BitwiseXor(A: TVarUInt; B: TVarUInt): TVarUInt;
|
---|
305 | begin
|
---|
306 | Result.Value := A.Value xor B.Value;
|
---|
307 | end;
|
---|
308 |
|
---|
309 | function TVarUInt.GetByteSize: Integer;
|
---|
310 | var
|
---|
311 | Length: Integer;
|
---|
312 | begin
|
---|
313 | // Get bit length
|
---|
314 | Length := SizeOf(Value) * BitAlignment - 1;
|
---|
315 | while (((Value shr Length) and 1) = 0) and (Length > 0) do
|
---|
316 | Dec(Length);
|
---|
317 | Inc(Length);
|
---|
318 | Result := Ceil(Length / (BitAlignment - 1));
|
---|
319 | end;
|
---|
320 |
|
---|
321 | function TVarUInt.WriteToAddr(Ptr: Pointer): Integer;
|
---|
322 | var
|
---|
323 | Length: Byte;
|
---|
324 | Data: Byte;
|
---|
325 | I: Integer;
|
---|
326 | LengthMask: Byte;
|
---|
327 | begin
|
---|
328 | Result := 0;
|
---|
329 |
|
---|
330 | Length := GetByteSize;
|
---|
331 | LengthMask := GetUnaryLengthMask(Length);
|
---|
332 |
|
---|
333 | // Copy data
|
---|
334 | for I := Length downto 1 do begin
|
---|
335 | Data := (Value shr (BitAlignment * (I - 1))) and $ff;
|
---|
336 | if I = Length then Data := (Data and
|
---|
337 | (LengthMask xor $ff)) or ((LengthMask shl 1) and $ff);
|
---|
338 | PByte(Ptr)^ := Data;
|
---|
339 | Inc(Ptr);
|
---|
340 | Inc(Result);
|
---|
341 | end;
|
---|
342 | end;
|
---|
343 |
|
---|
344 | function TVarUInt.ReadFromAddr(Ptr: Pointer): Integer;
|
---|
345 | var
|
---|
346 | Data: Byte;
|
---|
347 | Length: Integer;
|
---|
348 | I: Integer;
|
---|
349 | LengthMask: Byte;
|
---|
350 | begin
|
---|
351 | Value := 0;
|
---|
352 | Result := 0;
|
---|
353 | Length := 1;
|
---|
354 | I := 0;
|
---|
355 | while I < Length do begin
|
---|
356 | Data := PByte(Ptr)^;
|
---|
357 | if I = 0 then begin
|
---|
358 | if Data = $ff then begin
|
---|
359 | Length := PByte(Ptr)^;
|
---|
360 | Inc(Ptr);
|
---|
361 | if Length > BitAlignment then
|
---|
362 | raise Exception.Create(SVarIntOverflow);
|
---|
363 | if Length > 0 then begin
|
---|
364 | Data := PByte(Ptr)^;
|
---|
365 | Inc(Ptr);
|
---|
366 | end else Data := 0;
|
---|
367 | end else begin
|
---|
368 | Length := DecodeUnaryLength(Data);
|
---|
369 | LengthMask := GetUnaryLengthMask(Length);
|
---|
370 | Data := Data and (LengthMask xor $ff);
|
---|
371 | end;
|
---|
372 | end;
|
---|
373 | Value := Value or (QWord(Data) shl ((Length - I - 1) * BitAlignment));
|
---|
374 | Inc(I);
|
---|
375 | Inc(Ptr);
|
---|
376 | end;
|
---|
377 | Result := Length;
|
---|
378 | end;
|
---|
379 |
|
---|
380 | { TVarInt }
|
---|
381 |
|
---|
382 | class operator TVarInt.Implicit(A: TVarInt): Int64;
|
---|
383 | begin
|
---|
384 | Result := A.Value;
|
---|
385 | end;
|
---|
386 |
|
---|
387 | class operator TVarInt.Implicit(A: TVarInt): QWord;
|
---|
388 | begin
|
---|
389 | Result := A.Value;
|
---|
390 | end;
|
---|
391 |
|
---|
392 | class operator TVarInt.Implicit(A: TVarInt): Integer;
|
---|
393 | begin
|
---|
394 | Result := A.Value;
|
---|
395 | end;
|
---|
396 |
|
---|
397 | class operator TVarInt.Implicit(A: TVarInt): Byte;
|
---|
398 | begin
|
---|
399 | Result := A.Value;
|
---|
400 | end;
|
---|
401 |
|
---|
402 | class operator TVarInt.Implicit(A: TVarInt): Char;
|
---|
403 | begin
|
---|
404 | Result := Char(A.Value);
|
---|
405 | end;
|
---|
406 |
|
---|
407 | class operator TVarInt.Implicit(A: Byte): TVarInt;
|
---|
408 | begin
|
---|
409 | Result.Value := A;
|
---|
410 | end;
|
---|
411 |
|
---|
412 | class operator TVarInt.Implicit(A: Integer): TVarInt;
|
---|
413 | begin
|
---|
414 | Result.Value := A;
|
---|
415 | end;
|
---|
416 |
|
---|
417 | class operator TVarInt.Implicit(A: Int64): TVarInt;
|
---|
418 | begin
|
---|
419 | Result.Value := A;
|
---|
420 | end;
|
---|
421 |
|
---|
422 | class operator TVarInt.Implicit(A: QWord): TVarInt;
|
---|
423 | begin
|
---|
424 | Result.Value := A;
|
---|
425 | end;
|
---|
426 |
|
---|
427 | class operator TVarInt.Explicit(A: Byte): TVarInt;
|
---|
428 | begin
|
---|
429 | Result.Value := A;
|
---|
430 | end;
|
---|
431 |
|
---|
432 | class operator TVarInt.Explicit(A: Integer): TVarInt;
|
---|
433 | begin
|
---|
434 | Result.Value := A;
|
---|
435 | end;
|
---|
436 |
|
---|
437 | class operator TVarInt.Explicit(A: Int64): TVarInt;
|
---|
438 | begin
|
---|
439 | Result.Value := A;
|
---|
440 | end;
|
---|
441 |
|
---|
442 | class operator TVarInt.Explicit(A: TVarInt): Int64;
|
---|
443 | begin
|
---|
444 | Result := A.Value;
|
---|
445 | end;
|
---|
446 |
|
---|
447 | class operator TVarInt.Inc(A: TVarInt): TVarInt;
|
---|
448 | begin
|
---|
449 | Result.Value := A.Value + 1;
|
---|
450 | end;
|
---|
451 |
|
---|
452 | class operator TVarInt.Inc(A: TVarInt; B: TVarInt): TVarInt;
|
---|
453 | begin
|
---|
454 | Result := A.Value + B.Value;
|
---|
455 | end;
|
---|
456 |
|
---|
457 | class operator TVarInt.Dec(A: TVarInt): TVarInt;
|
---|
458 | begin
|
---|
459 | Result.Value := A.Value - 1;
|
---|
460 | end;
|
---|
461 |
|
---|
462 | class operator TVarInt.Dec(A: TVarInt; B: TVarInt): TVarInt;
|
---|
463 | begin
|
---|
464 | Result.Value := A.Value - B.Value;
|
---|
465 | end;
|
---|
466 |
|
---|
467 | class operator TVarInt.Negative(A: TVarInt): TVarInt;
|
---|
468 | begin
|
---|
469 | Result.Value := -A.Value;
|
---|
470 | end;
|
---|
471 |
|
---|
472 | class operator TVarInt.Add(A: TVarInt; B: TVarInt): TVarInt;
|
---|
473 | begin
|
---|
474 | Result.Value := A.Value + B.Value;
|
---|
475 | end;
|
---|
476 |
|
---|
477 | class operator TVarInt.Multiply(A: TVarInt; B: TVarInt): TVarInt;
|
---|
478 | begin
|
---|
479 | Result.Value := A.Value * B.Value;
|
---|
480 | end;
|
---|
481 |
|
---|
482 | class operator TVarInt.IntDivide(A: TVarInt; B: TVarInt): TVarInt;
|
---|
483 | begin
|
---|
484 | Result.Value := A.Value div B.Value;
|
---|
485 | end;
|
---|
486 |
|
---|
487 | class operator TVarInt.Modulus(A: TVarInt; B: TVarInt): TVarInt;
|
---|
488 | begin
|
---|
489 | Result.Value := A.Value mod B.Value;
|
---|
490 | end;
|
---|
491 |
|
---|
492 | class operator TVarInt.Subtract(A: TVarInt; B: TVarInt): TVarInt;
|
---|
493 | begin
|
---|
494 | Result.Value := A.Value - B.Value;
|
---|
495 | end;
|
---|
496 |
|
---|
497 | class operator TVarInt.Equal(A: TVarInt; B: TVarInt): Boolean;
|
---|
498 | begin
|
---|
499 | Result := A.Value = B.Value;
|
---|
500 | end;
|
---|
501 |
|
---|
502 | class operator TVarInt.NotEqual(A: TVarInt; B: TVarInt): Boolean;
|
---|
503 | begin
|
---|
504 | Result := A.Value <> B.Value;
|
---|
505 | end;
|
---|
506 |
|
---|
507 | class operator TVarInt.GreaterThan(A: TVarInt; B: TVarInt): Boolean;
|
---|
508 | begin
|
---|
509 | Result := A.Value > B.Value;
|
---|
510 | end;
|
---|
511 |
|
---|
512 | class operator TVarInt.GreaterThanOrEqual(A: TVarInt; B: TVarInt): Boolean;
|
---|
513 | begin
|
---|
514 | Result := A.Value >= B.Value;
|
---|
515 | end;
|
---|
516 |
|
---|
517 | class operator TVarInt.LessThan(A: TVarInt; B: TVarInt): Boolean;
|
---|
518 | begin
|
---|
519 | Result := A.Value < B.Value;
|
---|
520 | end;
|
---|
521 |
|
---|
522 | class operator TVarInt.LessThanOrEqual(A: TVarInt; B: TVarInt): Boolean;
|
---|
523 | begin
|
---|
524 | Result := A.Value <= B.Value;
|
---|
525 | end;
|
---|
526 |
|
---|
527 | class operator TVarInt.LeftShift(A: TVarInt; B: TVarInt): TVarInt;
|
---|
528 | begin
|
---|
529 | Result.Value := A.Value shl B.Value;
|
---|
530 | end;
|
---|
531 |
|
---|
532 | class operator TVarInt.RightShift(A: TVarInt; B: TVarInt): TVarInt;
|
---|
533 | begin
|
---|
534 | Result.Value := A.Value shr B.Value;
|
---|
535 | end;
|
---|
536 |
|
---|
537 | class operator TVarInt.BitwiseAnd(A: TVarInt; B: TVarInt): TVarInt;
|
---|
538 | begin
|
---|
539 | Result.Value := A.Value and B.Value;
|
---|
540 | end;
|
---|
541 |
|
---|
542 | class operator TVarInt.BitwiseOr(A: TVarInt; B: TVarInt): TVarInt;
|
---|
543 | begin
|
---|
544 | Result.Value := A.Value or B.Value;
|
---|
545 | end;
|
---|
546 |
|
---|
547 | class operator TVarInt.BitwiseXor(A: TVarInt; B: TVarInt): TVarInt;
|
---|
548 | begin
|
---|
549 | Result.Value := A.Value xor B.Value;
|
---|
550 | end;
|
---|
551 |
|
---|
552 | function TVarInt.GetByteSize: Integer;
|
---|
553 | var
|
---|
554 | UInt: TVarUInt;
|
---|
555 | begin
|
---|
556 | UInt := Value;
|
---|
557 | Result := UInt.GetByteSize;
|
---|
558 | end;
|
---|
559 |
|
---|
560 | function TVarInt.WriteToAddr(Ptr: Pointer): Integer;
|
---|
561 | var
|
---|
562 | UInt: TVarUInt;
|
---|
563 | begin
|
---|
564 | UInt := Value;
|
---|
565 | Result := UInt.WriteToAddr(Ptr);
|
---|
566 | end;
|
---|
567 |
|
---|
568 | function TVarInt.ReadFromAddr(Ptr: Pointer): Integer;
|
---|
569 | var
|
---|
570 | UInt: TVarUInt;
|
---|
571 | begin
|
---|
572 | Result := UInt.ReadFromAddr(Ptr);
|
---|
573 | Value := UInt;
|
---|
574 | end;
|
---|
575 |
|
---|
576 |
|
---|
577 | end.
|
---|
578 |
|
---|