Debian Codegraph @

node/@bufbuild/protobuf/dist/commonjs/proto-int64.d.ts

raw
1 /**
2 * Int64Support for the current environment.
3 */
4 export declare const protoInt64: Int64Support;
5 /**
6 * We use the `bigint` primitive to represent 64-bit integral types. If bigint
7 * is unavailable, we fall back to a string representation, which means that
8 * all values typed as `bigint` will actually be strings.
9 *
10 * If your code is intended to run in an environment where bigint may be
11 * unavailable, it must handle both the bigint and the string representation.
12 * For presenting values, this is straight-forward with implicit or explicit
13 * conversion to string:
14 *
15 * ```ts
16 * let el = document.createElement("span");
17 * el.innerText = message.int64Field; // assuming a protobuf int64 field
18 *
19 * console.log(`int64: ${message.int64Field}`);
20 *
21 * let str: string = message.int64Field.toString();
22 * ```
23 *
24 * If you need to manipulate 64-bit integral values and are sure the values
25 * can be safely represented as an IEEE-754 double precision number, you can
26 * convert to a JavaScript Number:
27 *
28 * ```ts
29 * console.log(message.int64Field.toString())
30 * let num = Number(message.int64Field);
31 * num = num + 1;
32 * message.int64Field = protoInt64.parse(num);
33 * ```
34 *
35 * If you need to manipulate 64-bit integral values that are outside the
36 * range of safe representation as a JavaScript Number, we recommend you
37 * use a third party library, for example the npm package "long":
38 *
39 * ```ts
40 * // convert the field value to a Long
41 * const bits = protoInt64.enc(message.int64Field);
42 * const longValue = Long.fromBits(bits.lo, bits.hi);
43 *
44 * // perform arithmetic
45 * const longResult = longValue.subtract(1);
46 *
47 * // set the result in the field
48 * message.int64Field = protoInt64.dec(longResult.low, longResult.high);
49 *
50 * // Assuming int64Field contains 9223372036854775807:
51 * console.log(message.int64Field); // 9223372036854775806
52 * ```
53 */
54 interface Int64Support {
55 /**
56 * 0n if bigint is available, "0" if unavailable.
57 */
58 readonly zero: bigint;
59 /**
60 * Is bigint available?
61 */
62 readonly supported: boolean;
63 /**
64 * Parse a signed 64-bit integer.
65 * Returns a bigint if available, a string otherwise.
66 */
67 parse(value: string | number | bigint): bigint;
68 /**
69 * Parse an unsigned 64-bit integer.
70 * Returns a bigint if available, a string otherwise.
71 */
72 uParse(value: string | number | bigint): bigint;
73 /**
74 * Convert a signed 64-bit integral value to a two's complement.
75 */
76 enc(value: string | number | bigint): {
77 lo: number;
78 hi: number;
79 };
80 /**
81 * Convert an unsigned 64-bit integral value to a two's complement.
82 */
83 uEnc(value: string | number | bigint): {
84 lo: number;
85 hi: number;
86 };
87 /**
88 * Convert a two's complement to a signed 64-bit integral value.
89 * Returns a bigint if available, a string otherwise.
90 */
91 dec(lo: number, hi: number): bigint;
92 /**
93 * Convert a two's complement to an unsigned 64-bit integral value.
94 * Returns a bigint if available, a string otherwise.
95 */
96 uDec(lo: number, hi: number): bigint;
97 }
98 export {};