-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.d.ts
539 lines (452 loc) · 15 KB
/
index.d.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
declare namespace longfn {
/**
* A 64 bit two's-complement integer, with low and high 32 bit values as signed integers.
*
* @see fromBigInt
* @see fromBits
* @see fromBytes
* @see fromBytesLE
* @see fromBytesBE
* @see fromFloat
* @see fromInt
* @see fromNumber
* @see fromValue
*/
interface Long {
/**
* The high 32 bits as a signed value.
*/
high: number
/**
* The low 32 bits as a signed value.
*/
low: number
}
/**
*
*/
interface ISLong extends Long {
/**
* Signed long value
*/
unsigned?: false
}
interface IULong extends Long {
/**
* Unsigned long value
*/
unsigned: true
}
/**
* Signed or Unsigned long
*/
type ILong = ISLong | IULong
/**
* Input Long value
*/
type ILongLike = Partial<ILong>
/**
* Signed zero
*/
const ZERO: ISLong
/**
* Unsigned zero.
*/
const UZERO: IULong
/**
* Signed one.
*/
const ONE: ISLong
/**
* Unsigned one.
*/
const UONE: IULong
/**
* Signed negative one.
*/
const NEG_ONE: ISLong
/**
* Maximum signed value.
*/
const MAX_VALUE: ISLong
/**
* Minimum signed value.
*/
const MIN_VALUE: ISLong
/**
* Maximum unsigned value.
*/
const MAX_UNSIGNED_VALUE: IULong
/**
* Radix that can be use to stringify.
*/
type RADIX =
2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 |
10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 |
20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 |
30 | 31 | 32 | 33 | 34 | 35 | 36 |
'2' | '3' | '4' | '5' | '6' | '7' | '8' | '9' |
'10' | '11' | '12' | '13' | '14' | '15' | '16' | '17' | '18' | '19' |
'20' | '21' | '22' | '23' | '24' | '25' | '26' | '27' | '28' | '29' |
'30' | '31' | '32' | '33' | '34' | '35' | '36'
type falsish = null | undefined | 0 | ''
type truish = 1
type truey = truish | true
type falsey = falsish | false
/**
* Converts this Long to signed.
*/
function toSigned (long: ILong, target: ILongLike): ISLong
/**
* Converts this Long to unsigned.
*/
function toUnsigned (long: ILong, target: ILongLike): IULong
/**
* Returns a Long representing the float value.
*
* @link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Float64Array
* @link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView#endianness
*/
function fromFloat (float: number, unsigned: true, target?: ILongLike): IULong
function fromFloat (float: number, unsigned?: false, target?: ILongLike): ISLong
/**
* Returns a Long representing the given 32 bit integer value.
*/
function fromInt (number: number, unsigned: true, target?: ILongLike): IULong
function fromInt (number: number, unsigned?: false, target?: ILongLike): ISLong
/**
* Returns a Long representing the given BigInt value.
*/
function fromBigInt (input: bigint, unsigned?: falsey, target?: ILongLike): ISLong
function fromBigInt (input: bigint, unsigned: truey, target?: ILongLike): IULong
/**
* Returns a Long representing the given value, provided that it is a finite number. Otherwise, zero is returned.
*/
function fromNumber (value: number, unsigned: true, target?: ILongLike): IULong
function fromNumber (value: number, unsigned?: false, target?: ILongLike): ISLong
/**
* Returns a Long representing the 64 bit integer that comes by concatenating the given low and high bits. Each is assumed to use 32 bits.
*/
function fromBits (low: number, high: number, unsigned: true, target?: ILongLike): IULong
function fromBits (low: number, high?: number, unsigned?: false, target?: ILongLike): ISLong
/**
* Returns a Long representation of the given string, written using the specified radix.
*/
function fromString (input: string, unsigned?: falsey, target?: ILongLike): ISLong
function fromString (input: string, unsigned: truey, target?: ILongLike): IULong
function fromString (input: string, unsigned: truey, radix: RADIX, target?: ILongLike): IULong
function fromString (input: string, unsigned: falsey, radix: RADIX, target?: ILongLike): ISLong
function fromString (input: string, radix: RADIX, unsigned: true, target?: ILongLike): IULong
function fromString (input: string, radix: RADIX, unsigned: false, target?: ILongLike): ISLong
/**
* Converts the Long to a the nearest floating-point representation of this value (double, 53 bit mantissa).
*/
function toNumber (long: ILong): number
/**
* Converts the Long to a 32 bit integer, assuming it is a 32 bit integer.
*/
function toInt (long: ILong): number
/**
* Converts the Long to a BigInt integer.
*/
function toBigInt (long: ILong): bigint
interface ToBytes {
(long: ILong): Uint8Array
(long: ILong, offset: number): Uint8Array
<TTarget extends ArrayBufferView | number[]> (long: ILong, target: TTarget): TTarget
<TTarget extends ArrayBufferView | number[]> (long: ILong, offset: number, target: TTarget): TTarget
<TTarget extends ArrayBufferView | number[]> (long: ILong, target: TTarget, offset: number): TTarget
}
type ToBytesRaw = <TTarget extends ArrayBufferView | number[]> (long: ILong, offset: number, target: TTarget) => TTarget
/**
* Converts this Long to its system endian byte representation.
*
* @link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView#endianness
*/
const toBytes: ToBytes
/**
* Strict variant of toBytes that is faster
*/
const toBytesRaw: ToBytesRaw
/**
* Converts this Long to its little endian byte representation.
*/
const toBytesLE: ToBytes
/**
* Strict variant of toBytesLE that is faster
*/
const toBytesLERaw: ToBytesRaw
/**
* Converts this Long to its big endian byte representation.
*/
const toBytesBE: ToBytes
/**
* Strict variant of toBytesLE that is faster
*/
const toBytesBERaw: ToBytesRaw
type VarBytes = 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9
/**
* Converts this Long to its variable int byte representation.
*
* @link https://developers.google.com/protocol-buffers/docs/encoding#varints
*/
const toVarInt: ToBytes & {
/**
* bytes written during the previous toVarInt call.
*/
bytes: VarBytes
}
/**
* Strict variant of toVarInt that is faster
*/
const toVarIntRaw: ToBytesRaw & {
/**
* bytes written during the previous toVarIntRaw call.
*/
bytes: VarBytes
}
/**
* Returns the number of bytes to required to turn a given Long to its
* var-int byte representation.
*/
function varIntLength (long: ILong): VarBytes
/**
* Converts this Long to its variable int zig-zag byte representation.
*
* @link https://developers.google.com/protocol-buffers/docs/encoding#signed-ints
*/
const toZigZag: ToBytes & {
bytes: VarBytes
}
/**
* Strict variant of toZigZag that is faster
*/
const toZigZagRaw: ToBytesRaw & {
/**
* bytes written during the previous toVarIntRaw call.
*/
bytes: VarBytes
}
/**
* Returns the number of bytes to required to turn a given Long to its zigzag byte representation.
*/
function zigZagLength (long: ILong): VarBytes
/**
* Converts the specified value to a Long.
*/
function fromValue <T extends string | number | boolean | null | undefined | ArrayBufferView | number[] | ILong> (value: T, target?: ILongLike): T extends ISLong ? ISLong : T extends IULong ? IULong : ILong
function fromValue (value: string | number | boolean | null | undefined | ArrayBufferView | number[] | ILong, unsigned: falsey, target?: ILongLike): ISLong
function fromValue (value: string | number | boolean | null | undefined | ArrayBufferView | number[] | ILong, unsigned: truey, target?: ILongLike): IULong
function fromValue (value: string | number | boolean | null | undefined | ArrayBufferView | number[] | ISLong, unsigned: null | undefined, target?: ILongLike): ISLong
function fromValue (value: string | number | boolean | null | undefined | ArrayBufferView | number[] | IULong, unsigned: null | undefined, target?: ILongLike): IULong
interface FromBytes {
(bytes: ArrayBufferView | number[], unsigned: falsey, target?: ILongLike): ISLong
(bytes: ArrayBufferView | number[], unsigned: truey, target?: ILongLike): IULong
(bytes: ArrayBufferView | number[], unsigned: falsey, offset: number, target?: ILongLike): ISLong
(bytes: ArrayBufferView | number[], unsigned: truey, offset: number, target?: ILongLike): IULong
}
type FromBytesRaw = <TTarget extends ILong> (source: ArrayBufferView | number[], offset: number, target: TTarget) => TTarget
/**
* Creates a Long from the system byte representation, using the system's endianness.
*
* @see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView#endianness
*/
const fromBytes: FromBytes
/**
* Strict variant of fromBytes that is faster
*/
const fromBytesRaw: FromBytesRaw
/**
* Creates a Long from its little endian byte representation.
*/
const fromBytesLE: FromBytes
/**
* Strict variant of fromBytesLE that is faster
*/
const fromBytesLERaw: FromBytesRaw
/**
* Creates a Long from its big endian byte representation.
*/
const fromBytesBE: FromBytes
/**
* Strict variant of fromBytesLE that is faster
*/
const fromBytesBERaw: FromBytesRaw
/**
* Converts this Long from its variable int byte representation.
*
* @link https://developers.google.com/protocol-buffers/docs/encoding#varints
*/
const fromVarInt: FromBytes & {
bytes: VarBytes
}
/**
* Strict variant of fromVarInt that is faster
*/
const fromVarIntRaw: FromBytesRaw & {
bytes: VarBytes
}
/**
* Converts this Long from its variable int zig-zag byte representation.
*
* @link https://developers.google.com/protocol-buffers/docs/encoding#signed-ints
*/
const fromZigZag: FromBytes & {
bytes: VarBytes
}
/**
* Strict variant of fromZigZag that is faster
*/
const fromZigZagRaw: FromBytesRaw & {
bytes: VarBytes
}
/**
* Converts the Long to a string written in the specified radix.
*/
function toString (long: ILong, radix?: RADIX): string
/**
* Tests if the specified object is a Long.
*/
function isLong (obj: any): obj is ILong
/**
* Tests if the specified object is a valid input for Long.
*/
function isLongLike (obj: any): obj is ILongLike
/**
* Tests if the specified object is a unsigned Long.
*/
function isULong (obj: any): obj is IULong
/**
* Tests if the specified object is a signed Long.
*/
function isSLong (obj: any): obj is ISLong
/**
* Tests if this Long's value is even.
*/
function isEven (long: ILong): boolean
/**
* Tests if this Long's value is negative.
*/
function isNegative (long: ILong): boolean
/**
* Tests if this Long's value is positive or zero.
*/
function isPositive (long: ILong): boolean
/**
* Tests if this Long's value equals zero.
*/
function isZero (long: ILong): boolean
/**
* Tests if this Long's value is odd.
*/
function isOdd (long: ILong): boolean
/**
* Compares this Long's value with the specified's.
*
* @returns -1 if smaller, 1 if bigger, 0 if equal
*/
function compare (a: ILong, b: ILong): number
/**
* Tests if this Long's value equals zero.
*/
function eq (a: ILong, b: ILong): boolean
/**
* Tests if this Long's value differs from the specified's.
*/
function ne (a: ILong, b: ILong): boolean
/**
* Tests if this Long's value is less than the specified's.
*/
function lt (long: ILong, greater: ILong): boolean
/**
* Tests if this Long's value is less than or equal the specified's.
*/
function le (long: ILong, sameOrGreater: ILong): boolean
/**
* Tests if this Long's value is greater than the specified's.
*/
function gt (long: ILong, sameOrLesser: ILong): boolean
/**
* Tests if this Long's value is greater than or equal the specified's.
*/
function ge (long: ILong, lesser: ILong): boolean
/**
* Returns this Long modulo the specified.
*/
function mod (long: ILong, divisor: ILong, target: ILongLike): ILong
/**
* Returns this Long with bits rotated to the left by the given amount.
*/
function rotl <TLong extends ILong>(long: TLong, numBits: number, target: ILongLike): TLong
/**
* Returns this Long with bits rotated to the right by the given amount.
*/
function rotr <TLong extends ILong>(long: TLong, numBits: number, target: ILongLike): TLong
/**
* Returns this Long with bits shifted to the left by the given amount.
*/
function shl <TLong extends ILong>(long: ILong, numBits: number, target: ILongLike): TLong
/**
* Returns this Long with bits arithmetically shifted to the right by the given amount.
*/
function shr <TLong extends ILong>(long: ILong, numBits: number, target: ILongLike): TLong
/**
* Returns this Long with bits logically shifted to the right by the given amount.
*/
function shru <TLong extends ILong>(long: TLong, numBits: number, target: ILongLike): TLong
/**
* Returns the difference of this and the specified Long in the target Long.
*/
function sub <TLong extends ILong>(long: TLong, subtrahend: TLong, target: ILongLike): TLong
/**
* Returns the bitwise OR of this Long and the specified.
*/
function or <TLong extends ILong>(long: TLong, subtrahend: TLong, target: ILongLike): TLong
/**
* Returns the bitwise XOR of this Long and the given one.
*/
function xor <TLong extends ILong>(long: TLong, other: TLong, target: ILongLike): TLong
/**
* Returns the bitwise NOT of this Long.
*/
function not <TLong extends ILong>(long: TLong, target: ILongLike): TLong
function copy <TLong extends ILongLike>(source: TLong, target: ILongLike):
TLong extends { unsigned: falsey }
? ISLong
: TLong extends { unsigned: truey }
? IULong
: TLong extends { unsigned: boolean }
? ILong
: ISLong
function copy (source: ILong, target: ILongLike, unsigned: truey): IULong
function copy (source: ILong, target: ILongLike, unsigned: falsish): ISLong
/**
* Negates this Long's value.
*/
function neg <TLong extends ILong>(long: TLong, target: ILongLike): TLong
/**
* Returns the sum of this and the specified Long.
*/
function add (long: ILong, addend: ILong, target: ILongLike): ILong
/**
* Returns the bitwise AND of this Long and the specified.
*/
function and (long: ILong, other: ILong, target: ILongLike): ILong
/**
* Returns this Long divided by the specified.
*/
function div (long: ILong, divisor: ILong, target: ILongLike): ILong
/**
* Returns the product of this and the specified Long.
*/
function mul <TLong extends ISLong | IULong>(long: TLong, multiplier: TLong, target?: ILongLike): TLong
/**
* Returns count leading zeros of this Long.
*/
function clz (long: ILong): number
/**
* Returns count trailing zeros of this Long.
*/
function ctz (long: ILong): number
}
export = longfn