node-red-contrib-meshtastic-advanced 1.0.2 → 1.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/decoder.js +1879 -40
- package/dist/decoder.js.map +1 -1
- package/dist/encoder.js +34 -33
- package/dist/encoder.js.map +1 -1
- package/dist/message-types.js +40 -40
- package/dist/message-types.js.map +1 -1
- package/dist/nodes/decode/decode.js.map +1 -1
- package/dist/nodes/decrypt/decrypt.js +1 -1
- package/dist/nodes/decrypt/decrypt.js.map +1 -1
- package/dist/nodes/encode/encode.js.map +1 -1
- package/dist/nodes/encrypt/encrypt.js +2 -2
- package/dist/nodes/encrypt/encrypt.js.map +1 -1
- package/dist/validation.js +171 -0
- package/dist/validation.js.map +1 -1
- package/dist/x25519.js +12 -9
- package/dist/x25519.js.map +1 -1
- package/package.json +2 -1
package/dist/decoder.js
CHANGED
|
@@ -1,5 +1,1842 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
const protobufs = require("@meshtastic/protobufs");
|
|
3
|
+
function isMessage(arg, schema) {
|
|
4
|
+
const isMessage2 = arg !== null && typeof arg == "object" && "$typeName" in arg && typeof arg.$typeName == "string";
|
|
5
|
+
if (!isMessage2) {
|
|
6
|
+
return false;
|
|
7
|
+
}
|
|
8
|
+
if (schema === void 0) {
|
|
9
|
+
return true;
|
|
10
|
+
}
|
|
11
|
+
return schema.typeName === arg.$typeName;
|
|
12
|
+
}
|
|
13
|
+
exports.ScalarType = void 0;
|
|
14
|
+
(function(ScalarType) {
|
|
15
|
+
ScalarType[ScalarType["DOUBLE"] = 1] = "DOUBLE";
|
|
16
|
+
ScalarType[ScalarType["FLOAT"] = 2] = "FLOAT";
|
|
17
|
+
ScalarType[ScalarType["INT64"] = 3] = "INT64";
|
|
18
|
+
ScalarType[ScalarType["UINT64"] = 4] = "UINT64";
|
|
19
|
+
ScalarType[ScalarType["INT32"] = 5] = "INT32";
|
|
20
|
+
ScalarType[ScalarType["FIXED64"] = 6] = "FIXED64";
|
|
21
|
+
ScalarType[ScalarType["FIXED32"] = 7] = "FIXED32";
|
|
22
|
+
ScalarType[ScalarType["BOOL"] = 8] = "BOOL";
|
|
23
|
+
ScalarType[ScalarType["STRING"] = 9] = "STRING";
|
|
24
|
+
ScalarType[ScalarType["BYTES"] = 12] = "BYTES";
|
|
25
|
+
ScalarType[ScalarType["UINT32"] = 13] = "UINT32";
|
|
26
|
+
ScalarType[ScalarType["SFIXED32"] = 15] = "SFIXED32";
|
|
27
|
+
ScalarType[ScalarType["SFIXED64"] = 16] = "SFIXED64";
|
|
28
|
+
ScalarType[ScalarType["SINT32"] = 17] = "SINT32";
|
|
29
|
+
ScalarType[ScalarType["SINT64"] = 18] = "SINT64";
|
|
30
|
+
})(exports.ScalarType || (exports.ScalarType = {}));
|
|
31
|
+
function varint64read() {
|
|
32
|
+
let lowBits = 0;
|
|
33
|
+
let highBits = 0;
|
|
34
|
+
for (let shift = 0; shift < 28; shift += 7) {
|
|
35
|
+
let b = this.buf[this.pos++];
|
|
36
|
+
lowBits |= (b & 127) << shift;
|
|
37
|
+
if ((b & 128) == 0) {
|
|
38
|
+
this.assertBounds();
|
|
39
|
+
return [lowBits, highBits];
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
let middleByte = this.buf[this.pos++];
|
|
43
|
+
lowBits |= (middleByte & 15) << 28;
|
|
44
|
+
highBits = (middleByte & 112) >> 4;
|
|
45
|
+
if ((middleByte & 128) == 0) {
|
|
46
|
+
this.assertBounds();
|
|
47
|
+
return [lowBits, highBits];
|
|
48
|
+
}
|
|
49
|
+
for (let shift = 3; shift <= 31; shift += 7) {
|
|
50
|
+
let b = this.buf[this.pos++];
|
|
51
|
+
highBits |= (b & 127) << shift;
|
|
52
|
+
if ((b & 128) == 0) {
|
|
53
|
+
this.assertBounds();
|
|
54
|
+
return [lowBits, highBits];
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
throw new Error("invalid varint");
|
|
58
|
+
}
|
|
59
|
+
function varint64write(lo, hi, bytes) {
|
|
60
|
+
for (let i = 0; i < 28; i = i + 7) {
|
|
61
|
+
const shift = lo >>> i;
|
|
62
|
+
const hasNext = !(shift >>> 7 == 0 && hi == 0);
|
|
63
|
+
const byte = (hasNext ? shift | 128 : shift) & 255;
|
|
64
|
+
bytes.push(byte);
|
|
65
|
+
if (!hasNext) {
|
|
66
|
+
return;
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
const splitBits = lo >>> 28 & 15 | (hi & 7) << 4;
|
|
70
|
+
const hasMoreBits = !(hi >> 3 == 0);
|
|
71
|
+
bytes.push((hasMoreBits ? splitBits | 128 : splitBits) & 255);
|
|
72
|
+
if (!hasMoreBits) {
|
|
73
|
+
return;
|
|
74
|
+
}
|
|
75
|
+
for (let i = 3; i < 31; i = i + 7) {
|
|
76
|
+
const shift = hi >>> i;
|
|
77
|
+
const hasNext = !(shift >>> 7 == 0);
|
|
78
|
+
const byte = (hasNext ? shift | 128 : shift) & 255;
|
|
79
|
+
bytes.push(byte);
|
|
80
|
+
if (!hasNext) {
|
|
81
|
+
return;
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
bytes.push(hi >>> 31 & 1);
|
|
85
|
+
}
|
|
86
|
+
const TWO_PWR_32_DBL = 4294967296;
|
|
87
|
+
function int64FromString(dec) {
|
|
88
|
+
const minus = dec[0] === "-";
|
|
89
|
+
if (minus) {
|
|
90
|
+
dec = dec.slice(1);
|
|
91
|
+
}
|
|
92
|
+
const base = 1e6;
|
|
93
|
+
let lowBits = 0;
|
|
94
|
+
let highBits = 0;
|
|
95
|
+
function add1e6digit(begin, end) {
|
|
96
|
+
const digit1e6 = Number(dec.slice(begin, end));
|
|
97
|
+
highBits *= base;
|
|
98
|
+
lowBits = lowBits * base + digit1e6;
|
|
99
|
+
if (lowBits >= TWO_PWR_32_DBL) {
|
|
100
|
+
highBits = highBits + (lowBits / TWO_PWR_32_DBL | 0);
|
|
101
|
+
lowBits = lowBits % TWO_PWR_32_DBL;
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
add1e6digit(-24, -18);
|
|
105
|
+
add1e6digit(-18, -12);
|
|
106
|
+
add1e6digit(-12, -6);
|
|
107
|
+
add1e6digit(-6);
|
|
108
|
+
return minus ? negate(lowBits, highBits) : newBits(lowBits, highBits);
|
|
109
|
+
}
|
|
110
|
+
function int64ToString(lo, hi) {
|
|
111
|
+
let bits = newBits(lo, hi);
|
|
112
|
+
const negative = bits.hi & 2147483648;
|
|
113
|
+
if (negative) {
|
|
114
|
+
bits = negate(bits.lo, bits.hi);
|
|
115
|
+
}
|
|
116
|
+
const result = uInt64ToString(bits.lo, bits.hi);
|
|
117
|
+
return negative ? "-" + result : result;
|
|
118
|
+
}
|
|
119
|
+
function uInt64ToString(lo, hi) {
|
|
120
|
+
({ lo, hi } = toUnsigned(lo, hi));
|
|
121
|
+
if (hi <= 2097151) {
|
|
122
|
+
return String(TWO_PWR_32_DBL * hi + lo);
|
|
123
|
+
}
|
|
124
|
+
const low = lo & 16777215;
|
|
125
|
+
const mid = (lo >>> 24 | hi << 8) & 16777215;
|
|
126
|
+
const high = hi >> 16 & 65535;
|
|
127
|
+
let digitA = low + mid * 6777216 + high * 6710656;
|
|
128
|
+
let digitB = mid + high * 8147497;
|
|
129
|
+
let digitC = high * 2;
|
|
130
|
+
const base = 1e7;
|
|
131
|
+
if (digitA >= base) {
|
|
132
|
+
digitB += Math.floor(digitA / base);
|
|
133
|
+
digitA %= base;
|
|
134
|
+
}
|
|
135
|
+
if (digitB >= base) {
|
|
136
|
+
digitC += Math.floor(digitB / base);
|
|
137
|
+
digitB %= base;
|
|
138
|
+
}
|
|
139
|
+
return digitC.toString() + decimalFrom1e7WithLeadingZeros(digitB) + decimalFrom1e7WithLeadingZeros(digitA);
|
|
140
|
+
}
|
|
141
|
+
function toUnsigned(lo, hi) {
|
|
142
|
+
return { lo: lo >>> 0, hi: hi >>> 0 };
|
|
143
|
+
}
|
|
144
|
+
function newBits(lo, hi) {
|
|
145
|
+
return { lo: lo | 0, hi: hi | 0 };
|
|
146
|
+
}
|
|
147
|
+
function negate(lowBits, highBits) {
|
|
148
|
+
highBits = ~highBits;
|
|
149
|
+
if (lowBits) {
|
|
150
|
+
lowBits = ~lowBits + 1;
|
|
151
|
+
} else {
|
|
152
|
+
highBits += 1;
|
|
153
|
+
}
|
|
154
|
+
return newBits(lowBits, highBits);
|
|
155
|
+
}
|
|
156
|
+
const decimalFrom1e7WithLeadingZeros = (digit1e7) => {
|
|
157
|
+
const partial = String(digit1e7);
|
|
158
|
+
return "0000000".slice(partial.length) + partial;
|
|
159
|
+
};
|
|
160
|
+
function varint32write(value, bytes) {
|
|
161
|
+
if (value >= 0) {
|
|
162
|
+
while (value > 127) {
|
|
163
|
+
bytes.push(value & 127 | 128);
|
|
164
|
+
value = value >>> 7;
|
|
165
|
+
}
|
|
166
|
+
bytes.push(value);
|
|
167
|
+
} else {
|
|
168
|
+
for (let i = 0; i < 9; i++) {
|
|
169
|
+
bytes.push(value & 127 | 128);
|
|
170
|
+
value = value >> 7;
|
|
171
|
+
}
|
|
172
|
+
bytes.push(1);
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
function varint32read() {
|
|
176
|
+
let b = this.buf[this.pos++];
|
|
177
|
+
let result = b & 127;
|
|
178
|
+
if ((b & 128) == 0) {
|
|
179
|
+
this.assertBounds();
|
|
180
|
+
return result;
|
|
181
|
+
}
|
|
182
|
+
b = this.buf[this.pos++];
|
|
183
|
+
result |= (b & 127) << 7;
|
|
184
|
+
if ((b & 128) == 0) {
|
|
185
|
+
this.assertBounds();
|
|
186
|
+
return result;
|
|
187
|
+
}
|
|
188
|
+
b = this.buf[this.pos++];
|
|
189
|
+
result |= (b & 127) << 14;
|
|
190
|
+
if ((b & 128) == 0) {
|
|
191
|
+
this.assertBounds();
|
|
192
|
+
return result;
|
|
193
|
+
}
|
|
194
|
+
b = this.buf[this.pos++];
|
|
195
|
+
result |= (b & 127) << 21;
|
|
196
|
+
if ((b & 128) == 0) {
|
|
197
|
+
this.assertBounds();
|
|
198
|
+
return result;
|
|
199
|
+
}
|
|
200
|
+
b = this.buf[this.pos++];
|
|
201
|
+
result |= (b & 15) << 28;
|
|
202
|
+
for (let readBytes = 5; (b & 128) !== 0 && readBytes < 10; readBytes++)
|
|
203
|
+
b = this.buf[this.pos++];
|
|
204
|
+
if ((b & 128) != 0)
|
|
205
|
+
throw new Error("invalid varint");
|
|
206
|
+
this.assertBounds();
|
|
207
|
+
return result >>> 0;
|
|
208
|
+
}
|
|
209
|
+
const protoInt64 = /* @__PURE__ */ makeInt64Support();
|
|
210
|
+
function makeInt64Support() {
|
|
211
|
+
const dv = new DataView(new ArrayBuffer(8));
|
|
212
|
+
const ok = typeof BigInt === "function" && typeof dv.getBigInt64 === "function" && typeof dv.getBigUint64 === "function" && typeof dv.setBigInt64 === "function" && typeof dv.setBigUint64 === "function" && (!!globalThis.Deno || typeof process != "object" || typeof process.env != "object" || process.env.BUF_BIGINT_DISABLE !== "1");
|
|
213
|
+
if (ok) {
|
|
214
|
+
const MIN = BigInt("-9223372036854775808");
|
|
215
|
+
const MAX = BigInt("9223372036854775807");
|
|
216
|
+
const UMIN = BigInt("0");
|
|
217
|
+
const UMAX = BigInt("18446744073709551615");
|
|
218
|
+
return {
|
|
219
|
+
zero: BigInt(0),
|
|
220
|
+
supported: true,
|
|
221
|
+
parse(value) {
|
|
222
|
+
const bi = typeof value == "bigint" ? value : BigInt(value);
|
|
223
|
+
if (bi > MAX || bi < MIN) {
|
|
224
|
+
throw new Error(`invalid int64: ${value}`);
|
|
225
|
+
}
|
|
226
|
+
return bi;
|
|
227
|
+
},
|
|
228
|
+
uParse(value) {
|
|
229
|
+
const bi = typeof value == "bigint" ? value : BigInt(value);
|
|
230
|
+
if (bi > UMAX || bi < UMIN) {
|
|
231
|
+
throw new Error(`invalid uint64: ${value}`);
|
|
232
|
+
}
|
|
233
|
+
return bi;
|
|
234
|
+
},
|
|
235
|
+
enc(value) {
|
|
236
|
+
dv.setBigInt64(0, this.parse(value), true);
|
|
237
|
+
return {
|
|
238
|
+
lo: dv.getInt32(0, true),
|
|
239
|
+
hi: dv.getInt32(4, true)
|
|
240
|
+
};
|
|
241
|
+
},
|
|
242
|
+
uEnc(value) {
|
|
243
|
+
dv.setBigInt64(0, this.uParse(value), true);
|
|
244
|
+
return {
|
|
245
|
+
lo: dv.getInt32(0, true),
|
|
246
|
+
hi: dv.getInt32(4, true)
|
|
247
|
+
};
|
|
248
|
+
},
|
|
249
|
+
dec(lo, hi) {
|
|
250
|
+
dv.setInt32(0, lo, true);
|
|
251
|
+
dv.setInt32(4, hi, true);
|
|
252
|
+
return dv.getBigInt64(0, true);
|
|
253
|
+
},
|
|
254
|
+
uDec(lo, hi) {
|
|
255
|
+
dv.setInt32(0, lo, true);
|
|
256
|
+
dv.setInt32(4, hi, true);
|
|
257
|
+
return dv.getBigUint64(0, true);
|
|
258
|
+
}
|
|
259
|
+
};
|
|
260
|
+
}
|
|
261
|
+
return {
|
|
262
|
+
zero: "0",
|
|
263
|
+
supported: false,
|
|
264
|
+
parse(value) {
|
|
265
|
+
if (typeof value != "string") {
|
|
266
|
+
value = value.toString();
|
|
267
|
+
}
|
|
268
|
+
assertInt64String(value);
|
|
269
|
+
return value;
|
|
270
|
+
},
|
|
271
|
+
uParse(value) {
|
|
272
|
+
if (typeof value != "string") {
|
|
273
|
+
value = value.toString();
|
|
274
|
+
}
|
|
275
|
+
assertUInt64String(value);
|
|
276
|
+
return value;
|
|
277
|
+
},
|
|
278
|
+
enc(value) {
|
|
279
|
+
if (typeof value != "string") {
|
|
280
|
+
value = value.toString();
|
|
281
|
+
}
|
|
282
|
+
assertInt64String(value);
|
|
283
|
+
return int64FromString(value);
|
|
284
|
+
},
|
|
285
|
+
uEnc(value) {
|
|
286
|
+
if (typeof value != "string") {
|
|
287
|
+
value = value.toString();
|
|
288
|
+
}
|
|
289
|
+
assertUInt64String(value);
|
|
290
|
+
return int64FromString(value);
|
|
291
|
+
},
|
|
292
|
+
dec(lo, hi) {
|
|
293
|
+
return int64ToString(lo, hi);
|
|
294
|
+
},
|
|
295
|
+
uDec(lo, hi) {
|
|
296
|
+
return uInt64ToString(lo, hi);
|
|
297
|
+
}
|
|
298
|
+
};
|
|
299
|
+
}
|
|
300
|
+
function assertInt64String(value) {
|
|
301
|
+
if (!/^-?[0-9]+$/.test(value)) {
|
|
302
|
+
throw new Error("invalid int64: " + value);
|
|
303
|
+
}
|
|
304
|
+
}
|
|
305
|
+
function assertUInt64String(value) {
|
|
306
|
+
if (!/^[0-9]+$/.test(value)) {
|
|
307
|
+
throw new Error("invalid uint64: " + value);
|
|
308
|
+
}
|
|
309
|
+
}
|
|
310
|
+
function scalarZeroValue(type, longAsString) {
|
|
311
|
+
switch (type) {
|
|
312
|
+
case exports.ScalarType.STRING:
|
|
313
|
+
return "";
|
|
314
|
+
case exports.ScalarType.BOOL:
|
|
315
|
+
return false;
|
|
316
|
+
case exports.ScalarType.DOUBLE:
|
|
317
|
+
case exports.ScalarType.FLOAT:
|
|
318
|
+
return 0;
|
|
319
|
+
case exports.ScalarType.INT64:
|
|
320
|
+
case exports.ScalarType.UINT64:
|
|
321
|
+
case exports.ScalarType.SFIXED64:
|
|
322
|
+
case exports.ScalarType.FIXED64:
|
|
323
|
+
case exports.ScalarType.SINT64:
|
|
324
|
+
return longAsString ? "0" : protoInt64.zero;
|
|
325
|
+
case exports.ScalarType.BYTES:
|
|
326
|
+
return new Uint8Array(0);
|
|
327
|
+
default:
|
|
328
|
+
return 0;
|
|
329
|
+
}
|
|
330
|
+
}
|
|
331
|
+
function isScalarZeroValue(type, value) {
|
|
332
|
+
switch (type) {
|
|
333
|
+
case exports.ScalarType.BOOL:
|
|
334
|
+
return value === false;
|
|
335
|
+
case exports.ScalarType.STRING:
|
|
336
|
+
return value === "";
|
|
337
|
+
case exports.ScalarType.BYTES:
|
|
338
|
+
return value instanceof Uint8Array && !value.byteLength;
|
|
339
|
+
default:
|
|
340
|
+
return value == 0;
|
|
341
|
+
}
|
|
342
|
+
}
|
|
343
|
+
const IMPLICIT$1 = 2;
|
|
344
|
+
const unsafeLocal = Symbol.for("reflect unsafe local");
|
|
345
|
+
function unsafeOneofCase(target, oneof) {
|
|
346
|
+
const c = target[oneof.localName].case;
|
|
347
|
+
if (c === void 0) {
|
|
348
|
+
return c;
|
|
349
|
+
}
|
|
350
|
+
return oneof.fields.find((f) => f.localName === c);
|
|
351
|
+
}
|
|
352
|
+
function unsafeIsSet(target, field) {
|
|
353
|
+
const name = field.localName;
|
|
354
|
+
if (field.oneof) {
|
|
355
|
+
return target[field.oneof.localName].case === name;
|
|
356
|
+
}
|
|
357
|
+
if (field.presence != IMPLICIT$1) {
|
|
358
|
+
return target[name] !== void 0 && Object.prototype.hasOwnProperty.call(target, name);
|
|
359
|
+
}
|
|
360
|
+
switch (field.fieldKind) {
|
|
361
|
+
case "list":
|
|
362
|
+
return target[name].length > 0;
|
|
363
|
+
case "map":
|
|
364
|
+
return Object.keys(target[name]).length > 0;
|
|
365
|
+
case "scalar":
|
|
366
|
+
return !isScalarZeroValue(field.scalar, target[name]);
|
|
367
|
+
case "enum":
|
|
368
|
+
return target[name] !== field.enum.values[0].number;
|
|
369
|
+
}
|
|
370
|
+
throw new Error("message field with implicit presence");
|
|
371
|
+
}
|
|
372
|
+
function unsafeGet(target, field) {
|
|
373
|
+
if (field.oneof) {
|
|
374
|
+
const oneof = target[field.oneof.localName];
|
|
375
|
+
if (oneof.case === field.localName) {
|
|
376
|
+
return oneof.value;
|
|
377
|
+
}
|
|
378
|
+
return void 0;
|
|
379
|
+
}
|
|
380
|
+
return target[field.localName];
|
|
381
|
+
}
|
|
382
|
+
function unsafeSet(target, field, value) {
|
|
383
|
+
if (field.oneof) {
|
|
384
|
+
target[field.oneof.localName] = {
|
|
385
|
+
case: field.localName,
|
|
386
|
+
value
|
|
387
|
+
};
|
|
388
|
+
} else {
|
|
389
|
+
target[field.localName] = value;
|
|
390
|
+
}
|
|
391
|
+
}
|
|
392
|
+
function unsafeClear(target, field) {
|
|
393
|
+
const name = field.localName;
|
|
394
|
+
if (field.oneof) {
|
|
395
|
+
const oneofLocalName = field.oneof.localName;
|
|
396
|
+
if (target[oneofLocalName].case === name) {
|
|
397
|
+
target[oneofLocalName] = { case: void 0 };
|
|
398
|
+
}
|
|
399
|
+
} else if (field.presence != IMPLICIT$1) {
|
|
400
|
+
delete target[name];
|
|
401
|
+
} else {
|
|
402
|
+
switch (field.fieldKind) {
|
|
403
|
+
case "map":
|
|
404
|
+
target[name] = {};
|
|
405
|
+
break;
|
|
406
|
+
case "list":
|
|
407
|
+
target[name] = [];
|
|
408
|
+
break;
|
|
409
|
+
case "enum":
|
|
410
|
+
target[name] = field.enum.values[0].number;
|
|
411
|
+
break;
|
|
412
|
+
case "scalar":
|
|
413
|
+
target[name] = scalarZeroValue(field.scalar, field.longAsString);
|
|
414
|
+
break;
|
|
415
|
+
}
|
|
416
|
+
}
|
|
417
|
+
}
|
|
418
|
+
function isObject(arg) {
|
|
419
|
+
return arg !== null && typeof arg == "object" && !Array.isArray(arg);
|
|
420
|
+
}
|
|
421
|
+
function isReflectList(arg, field) {
|
|
422
|
+
var _a, _b, _c, _d;
|
|
423
|
+
if (isObject(arg) && unsafeLocal in arg && "add" in arg && "field" in arg && typeof arg.field == "function") {
|
|
424
|
+
if (field !== void 0) {
|
|
425
|
+
const a = field;
|
|
426
|
+
const b = arg.field();
|
|
427
|
+
return a.listKind == b.listKind && a.scalar === b.scalar && ((_a = a.message) === null || _a === void 0 ? void 0 : _a.typeName) === ((_b = b.message) === null || _b === void 0 ? void 0 : _b.typeName) && ((_c = a.enum) === null || _c === void 0 ? void 0 : _c.typeName) === ((_d = b.enum) === null || _d === void 0 ? void 0 : _d.typeName);
|
|
428
|
+
}
|
|
429
|
+
return true;
|
|
430
|
+
}
|
|
431
|
+
return false;
|
|
432
|
+
}
|
|
433
|
+
function isReflectMap(arg, field) {
|
|
434
|
+
var _a, _b, _c, _d;
|
|
435
|
+
if (isObject(arg) && unsafeLocal in arg && "has" in arg && "field" in arg && typeof arg.field == "function") {
|
|
436
|
+
if (field !== void 0) {
|
|
437
|
+
const a = field, b = arg.field();
|
|
438
|
+
return a.mapKey === b.mapKey && a.mapKind == b.mapKind && a.scalar === b.scalar && ((_a = a.message) === null || _a === void 0 ? void 0 : _a.typeName) === ((_b = b.message) === null || _b === void 0 ? void 0 : _b.typeName) && ((_c = a.enum) === null || _c === void 0 ? void 0 : _c.typeName) === ((_d = b.enum) === null || _d === void 0 ? void 0 : _d.typeName);
|
|
439
|
+
}
|
|
440
|
+
return true;
|
|
441
|
+
}
|
|
442
|
+
return false;
|
|
443
|
+
}
|
|
444
|
+
function isReflectMessage(arg, messageDesc) {
|
|
445
|
+
return isObject(arg) && unsafeLocal in arg && "desc" in arg && isObject(arg.desc) && arg.desc.kind === "message" && (messageDesc === void 0 || arg.desc.typeName == messageDesc.typeName);
|
|
446
|
+
}
|
|
447
|
+
function isWrapper(arg) {
|
|
448
|
+
return isWrapperTypeName(arg.$typeName);
|
|
449
|
+
}
|
|
450
|
+
function isWrapperDesc(messageDesc) {
|
|
451
|
+
const f = messageDesc.fields[0];
|
|
452
|
+
return isWrapperTypeName(messageDesc.typeName) && f !== void 0 && f.fieldKind == "scalar" && f.name == "value" && f.number == 1;
|
|
453
|
+
}
|
|
454
|
+
function isWrapperTypeName(name) {
|
|
455
|
+
return name.startsWith("google.protobuf.") && [
|
|
456
|
+
"DoubleValue",
|
|
457
|
+
"FloatValue",
|
|
458
|
+
"Int64Value",
|
|
459
|
+
"UInt64Value",
|
|
460
|
+
"Int32Value",
|
|
461
|
+
"UInt32Value",
|
|
462
|
+
"BoolValue",
|
|
463
|
+
"StringValue",
|
|
464
|
+
"BytesValue"
|
|
465
|
+
].includes(name.substring(16));
|
|
466
|
+
}
|
|
467
|
+
const EDITION_PROTO3 = 999;
|
|
468
|
+
const EDITION_PROTO2 = 998;
|
|
469
|
+
const IMPLICIT = 2;
|
|
470
|
+
function create(schema, init) {
|
|
471
|
+
if (isMessage(init, schema)) {
|
|
472
|
+
return init;
|
|
473
|
+
}
|
|
474
|
+
const message = createZeroMessage(schema);
|
|
475
|
+
return message;
|
|
476
|
+
}
|
|
477
|
+
const tokenZeroMessageField = Symbol();
|
|
478
|
+
const messagePrototypes = /* @__PURE__ */ new WeakMap();
|
|
479
|
+
function createZeroMessage(desc) {
|
|
480
|
+
let msg;
|
|
481
|
+
if (!needsPrototypeChain(desc)) {
|
|
482
|
+
msg = {
|
|
483
|
+
$typeName: desc.typeName
|
|
484
|
+
};
|
|
485
|
+
for (const member of desc.members) {
|
|
486
|
+
if (member.kind == "oneof" || member.presence == IMPLICIT) {
|
|
487
|
+
msg[member.localName] = createZeroField(member);
|
|
488
|
+
}
|
|
489
|
+
}
|
|
490
|
+
} else {
|
|
491
|
+
const cached = messagePrototypes.get(desc);
|
|
492
|
+
let prototype;
|
|
493
|
+
let members;
|
|
494
|
+
if (cached) {
|
|
495
|
+
({ prototype, members } = cached);
|
|
496
|
+
} else {
|
|
497
|
+
prototype = {};
|
|
498
|
+
members = /* @__PURE__ */ new Set();
|
|
499
|
+
for (const member of desc.members) {
|
|
500
|
+
if (member.kind == "oneof") {
|
|
501
|
+
continue;
|
|
502
|
+
}
|
|
503
|
+
if (member.fieldKind != "scalar" && member.fieldKind != "enum") {
|
|
504
|
+
continue;
|
|
505
|
+
}
|
|
506
|
+
if (member.presence == IMPLICIT) {
|
|
507
|
+
continue;
|
|
508
|
+
}
|
|
509
|
+
members.add(member);
|
|
510
|
+
prototype[member.localName] = createZeroField(member);
|
|
511
|
+
}
|
|
512
|
+
messagePrototypes.set(desc, { prototype, members });
|
|
513
|
+
}
|
|
514
|
+
msg = Object.create(prototype);
|
|
515
|
+
msg.$typeName = desc.typeName;
|
|
516
|
+
for (const member of desc.members) {
|
|
517
|
+
if (members.has(member)) {
|
|
518
|
+
continue;
|
|
519
|
+
}
|
|
520
|
+
if (member.kind == "field") {
|
|
521
|
+
if (member.fieldKind == "message") {
|
|
522
|
+
continue;
|
|
523
|
+
}
|
|
524
|
+
if (member.fieldKind == "scalar" || member.fieldKind == "enum") {
|
|
525
|
+
if (member.presence != IMPLICIT) {
|
|
526
|
+
continue;
|
|
527
|
+
}
|
|
528
|
+
}
|
|
529
|
+
}
|
|
530
|
+
msg[member.localName] = createZeroField(member);
|
|
531
|
+
}
|
|
532
|
+
}
|
|
533
|
+
return msg;
|
|
534
|
+
}
|
|
535
|
+
function needsPrototypeChain(desc) {
|
|
536
|
+
switch (desc.file.edition) {
|
|
537
|
+
case EDITION_PROTO3:
|
|
538
|
+
return false;
|
|
539
|
+
case EDITION_PROTO2:
|
|
540
|
+
return true;
|
|
541
|
+
default:
|
|
542
|
+
return desc.fields.some((f) => f.presence != IMPLICIT && f.fieldKind != "message" && !f.oneof);
|
|
543
|
+
}
|
|
544
|
+
}
|
|
545
|
+
function createZeroField(field) {
|
|
546
|
+
if (field.kind == "oneof") {
|
|
547
|
+
return { case: void 0 };
|
|
548
|
+
}
|
|
549
|
+
if (field.fieldKind == "list") {
|
|
550
|
+
return [];
|
|
551
|
+
}
|
|
552
|
+
if (field.fieldKind == "map") {
|
|
553
|
+
return {};
|
|
554
|
+
}
|
|
555
|
+
if (field.fieldKind == "message") {
|
|
556
|
+
return tokenZeroMessageField;
|
|
557
|
+
}
|
|
558
|
+
const defaultValue = field.getDefaultValue();
|
|
559
|
+
if (defaultValue !== void 0) {
|
|
560
|
+
return field.fieldKind == "scalar" && field.longAsString ? defaultValue.toString() : defaultValue;
|
|
561
|
+
}
|
|
562
|
+
return field.fieldKind == "scalar" ? scalarZeroValue(field.scalar, field.longAsString) : field.enum.values[0].number;
|
|
563
|
+
}
|
|
564
|
+
class FieldError extends Error {
|
|
565
|
+
constructor(fieldOrOneof, message, name = "FieldValueInvalidError") {
|
|
566
|
+
super(message);
|
|
567
|
+
this.name = name;
|
|
568
|
+
this.field = () => fieldOrOneof;
|
|
569
|
+
}
|
|
570
|
+
}
|
|
571
|
+
const symbol = Symbol.for("@bufbuild/protobuf/text-encoding");
|
|
572
|
+
function getTextEncoding() {
|
|
573
|
+
if (globalThis[symbol] == void 0) {
|
|
574
|
+
const te = new globalThis.TextEncoder();
|
|
575
|
+
const td = new globalThis.TextDecoder();
|
|
576
|
+
globalThis[symbol] = {
|
|
577
|
+
encodeUtf8(text) {
|
|
578
|
+
return te.encode(text);
|
|
579
|
+
},
|
|
580
|
+
decodeUtf8(bytes) {
|
|
581
|
+
return td.decode(bytes);
|
|
582
|
+
},
|
|
583
|
+
checkUtf8(text) {
|
|
584
|
+
try {
|
|
585
|
+
encodeURIComponent(text);
|
|
586
|
+
return true;
|
|
587
|
+
} catch (_) {
|
|
588
|
+
return false;
|
|
589
|
+
}
|
|
590
|
+
}
|
|
591
|
+
};
|
|
592
|
+
}
|
|
593
|
+
return globalThis[symbol];
|
|
594
|
+
}
|
|
595
|
+
exports.WireType = void 0;
|
|
596
|
+
(function(WireType) {
|
|
597
|
+
WireType[WireType["Varint"] = 0] = "Varint";
|
|
598
|
+
WireType[WireType["Bit64"] = 1] = "Bit64";
|
|
599
|
+
WireType[WireType["LengthDelimited"] = 2] = "LengthDelimited";
|
|
600
|
+
WireType[WireType["StartGroup"] = 3] = "StartGroup";
|
|
601
|
+
WireType[WireType["EndGroup"] = 4] = "EndGroup";
|
|
602
|
+
WireType[WireType["Bit32"] = 5] = "Bit32";
|
|
603
|
+
})(exports.WireType || (exports.WireType = {}));
|
|
604
|
+
const FLOAT32_MAX = 34028234663852886e22;
|
|
605
|
+
const FLOAT32_MIN = -34028234663852886e22;
|
|
606
|
+
const UINT32_MAX = 4294967295;
|
|
607
|
+
const INT32_MAX = 2147483647;
|
|
608
|
+
const INT32_MIN = -2147483648;
|
|
609
|
+
class BinaryWriter {
|
|
610
|
+
constructor(encodeUtf8 = getTextEncoding().encodeUtf8) {
|
|
611
|
+
this.encodeUtf8 = encodeUtf8;
|
|
612
|
+
this.stack = [];
|
|
613
|
+
this.chunks = [];
|
|
614
|
+
this.buf = [];
|
|
615
|
+
}
|
|
616
|
+
/**
|
|
617
|
+
* Return all bytes written and reset this writer.
|
|
618
|
+
*/
|
|
619
|
+
finish() {
|
|
620
|
+
if (this.buf.length) {
|
|
621
|
+
this.chunks.push(new Uint8Array(this.buf));
|
|
622
|
+
this.buf = [];
|
|
623
|
+
}
|
|
624
|
+
let len = 0;
|
|
625
|
+
for (let i = 0; i < this.chunks.length; i++)
|
|
626
|
+
len += this.chunks[i].length;
|
|
627
|
+
let bytes = new Uint8Array(len);
|
|
628
|
+
let offset = 0;
|
|
629
|
+
for (let i = 0; i < this.chunks.length; i++) {
|
|
630
|
+
bytes.set(this.chunks[i], offset);
|
|
631
|
+
offset += this.chunks[i].length;
|
|
632
|
+
}
|
|
633
|
+
this.chunks = [];
|
|
634
|
+
return bytes;
|
|
635
|
+
}
|
|
636
|
+
/**
|
|
637
|
+
* Start a new fork for length-delimited data like a message
|
|
638
|
+
* or a packed repeated field.
|
|
639
|
+
*
|
|
640
|
+
* Must be joined later with `join()`.
|
|
641
|
+
*/
|
|
642
|
+
fork() {
|
|
643
|
+
this.stack.push({ chunks: this.chunks, buf: this.buf });
|
|
644
|
+
this.chunks = [];
|
|
645
|
+
this.buf = [];
|
|
646
|
+
return this;
|
|
647
|
+
}
|
|
648
|
+
/**
|
|
649
|
+
* Join the last fork. Write its length and bytes, then
|
|
650
|
+
* return to the previous state.
|
|
651
|
+
*/
|
|
652
|
+
join() {
|
|
653
|
+
let chunk = this.finish();
|
|
654
|
+
let prev = this.stack.pop();
|
|
655
|
+
if (!prev)
|
|
656
|
+
throw new Error("invalid state, fork stack empty");
|
|
657
|
+
this.chunks = prev.chunks;
|
|
658
|
+
this.buf = prev.buf;
|
|
659
|
+
this.uint32(chunk.byteLength);
|
|
660
|
+
return this.raw(chunk);
|
|
661
|
+
}
|
|
662
|
+
/**
|
|
663
|
+
* Writes a tag (field number and wire type).
|
|
664
|
+
*
|
|
665
|
+
* Equivalent to `uint32( (fieldNo << 3 | type) >>> 0 )`.
|
|
666
|
+
*
|
|
667
|
+
* Generated code should compute the tag ahead of time and call `uint32()`.
|
|
668
|
+
*/
|
|
669
|
+
tag(fieldNo, type) {
|
|
670
|
+
return this.uint32((fieldNo << 3 | type) >>> 0);
|
|
671
|
+
}
|
|
672
|
+
/**
|
|
673
|
+
* Write a chunk of raw bytes.
|
|
674
|
+
*/
|
|
675
|
+
raw(chunk) {
|
|
676
|
+
if (this.buf.length) {
|
|
677
|
+
this.chunks.push(new Uint8Array(this.buf));
|
|
678
|
+
this.buf = [];
|
|
679
|
+
}
|
|
680
|
+
this.chunks.push(chunk);
|
|
681
|
+
return this;
|
|
682
|
+
}
|
|
683
|
+
/**
|
|
684
|
+
* Write a `uint32` value, an unsigned 32 bit varint.
|
|
685
|
+
*/
|
|
686
|
+
uint32(value) {
|
|
687
|
+
assertUInt32(value);
|
|
688
|
+
while (value > 127) {
|
|
689
|
+
this.buf.push(value & 127 | 128);
|
|
690
|
+
value = value >>> 7;
|
|
691
|
+
}
|
|
692
|
+
this.buf.push(value);
|
|
693
|
+
return this;
|
|
694
|
+
}
|
|
695
|
+
/**
|
|
696
|
+
* Write a `int32` value, a signed 32 bit varint.
|
|
697
|
+
*/
|
|
698
|
+
int32(value) {
|
|
699
|
+
assertInt32(value);
|
|
700
|
+
varint32write(value, this.buf);
|
|
701
|
+
return this;
|
|
702
|
+
}
|
|
703
|
+
/**
|
|
704
|
+
* Write a `bool` value, a variant.
|
|
705
|
+
*/
|
|
706
|
+
bool(value) {
|
|
707
|
+
this.buf.push(value ? 1 : 0);
|
|
708
|
+
return this;
|
|
709
|
+
}
|
|
710
|
+
/**
|
|
711
|
+
* Write a `bytes` value, length-delimited arbitrary data.
|
|
712
|
+
*/
|
|
713
|
+
bytes(value) {
|
|
714
|
+
this.uint32(value.byteLength);
|
|
715
|
+
return this.raw(value);
|
|
716
|
+
}
|
|
717
|
+
/**
|
|
718
|
+
* Write a `string` value, length-delimited data converted to UTF-8 text.
|
|
719
|
+
*/
|
|
720
|
+
string(value) {
|
|
721
|
+
let chunk = this.encodeUtf8(value);
|
|
722
|
+
this.uint32(chunk.byteLength);
|
|
723
|
+
return this.raw(chunk);
|
|
724
|
+
}
|
|
725
|
+
/**
|
|
726
|
+
* Write a `float` value, 32-bit floating point number.
|
|
727
|
+
*/
|
|
728
|
+
float(value) {
|
|
729
|
+
assertFloat32(value);
|
|
730
|
+
let chunk = new Uint8Array(4);
|
|
731
|
+
new DataView(chunk.buffer).setFloat32(0, value, true);
|
|
732
|
+
return this.raw(chunk);
|
|
733
|
+
}
|
|
734
|
+
/**
|
|
735
|
+
* Write a `double` value, a 64-bit floating point number.
|
|
736
|
+
*/
|
|
737
|
+
double(value) {
|
|
738
|
+
let chunk = new Uint8Array(8);
|
|
739
|
+
new DataView(chunk.buffer).setFloat64(0, value, true);
|
|
740
|
+
return this.raw(chunk);
|
|
741
|
+
}
|
|
742
|
+
/**
|
|
743
|
+
* Write a `fixed32` value, an unsigned, fixed-length 32-bit integer.
|
|
744
|
+
*/
|
|
745
|
+
fixed32(value) {
|
|
746
|
+
assertUInt32(value);
|
|
747
|
+
let chunk = new Uint8Array(4);
|
|
748
|
+
new DataView(chunk.buffer).setUint32(0, value, true);
|
|
749
|
+
return this.raw(chunk);
|
|
750
|
+
}
|
|
751
|
+
/**
|
|
752
|
+
* Write a `sfixed32` value, a signed, fixed-length 32-bit integer.
|
|
753
|
+
*/
|
|
754
|
+
sfixed32(value) {
|
|
755
|
+
assertInt32(value);
|
|
756
|
+
let chunk = new Uint8Array(4);
|
|
757
|
+
new DataView(chunk.buffer).setInt32(0, value, true);
|
|
758
|
+
return this.raw(chunk);
|
|
759
|
+
}
|
|
760
|
+
/**
|
|
761
|
+
* Write a `sint32` value, a signed, zigzag-encoded 32-bit varint.
|
|
762
|
+
*/
|
|
763
|
+
sint32(value) {
|
|
764
|
+
assertInt32(value);
|
|
765
|
+
value = (value << 1 ^ value >> 31) >>> 0;
|
|
766
|
+
varint32write(value, this.buf);
|
|
767
|
+
return this;
|
|
768
|
+
}
|
|
769
|
+
/**
|
|
770
|
+
* Write a `fixed64` value, a signed, fixed-length 64-bit integer.
|
|
771
|
+
*/
|
|
772
|
+
sfixed64(value) {
|
|
773
|
+
let chunk = new Uint8Array(8), view = new DataView(chunk.buffer), tc = protoInt64.enc(value);
|
|
774
|
+
view.setInt32(0, tc.lo, true);
|
|
775
|
+
view.setInt32(4, tc.hi, true);
|
|
776
|
+
return this.raw(chunk);
|
|
777
|
+
}
|
|
778
|
+
/**
|
|
779
|
+
* Write a `fixed64` value, an unsigned, fixed-length 64 bit integer.
|
|
780
|
+
*/
|
|
781
|
+
fixed64(value) {
|
|
782
|
+
let chunk = new Uint8Array(8), view = new DataView(chunk.buffer), tc = protoInt64.uEnc(value);
|
|
783
|
+
view.setInt32(0, tc.lo, true);
|
|
784
|
+
view.setInt32(4, tc.hi, true);
|
|
785
|
+
return this.raw(chunk);
|
|
786
|
+
}
|
|
787
|
+
/**
|
|
788
|
+
* Write a `int64` value, a signed 64-bit varint.
|
|
789
|
+
*/
|
|
790
|
+
int64(value) {
|
|
791
|
+
let tc = protoInt64.enc(value);
|
|
792
|
+
varint64write(tc.lo, tc.hi, this.buf);
|
|
793
|
+
return this;
|
|
794
|
+
}
|
|
795
|
+
/**
|
|
796
|
+
* Write a `sint64` value, a signed, zig-zag-encoded 64-bit varint.
|
|
797
|
+
*/
|
|
798
|
+
sint64(value) {
|
|
799
|
+
const tc = protoInt64.enc(value), sign = tc.hi >> 31, lo = tc.lo << 1 ^ sign, hi = (tc.hi << 1 | tc.lo >>> 31) ^ sign;
|
|
800
|
+
varint64write(lo, hi, this.buf);
|
|
801
|
+
return this;
|
|
802
|
+
}
|
|
803
|
+
/**
|
|
804
|
+
* Write a `uint64` value, an unsigned 64-bit varint.
|
|
805
|
+
*/
|
|
806
|
+
uint64(value) {
|
|
807
|
+
const tc = protoInt64.uEnc(value);
|
|
808
|
+
varint64write(tc.lo, tc.hi, this.buf);
|
|
809
|
+
return this;
|
|
810
|
+
}
|
|
811
|
+
}
|
|
812
|
+
class BinaryReader {
|
|
813
|
+
constructor(buf, decodeUtf8 = getTextEncoding().decodeUtf8) {
|
|
814
|
+
this.decodeUtf8 = decodeUtf8;
|
|
815
|
+
this.varint64 = varint64read;
|
|
816
|
+
this.uint32 = varint32read;
|
|
817
|
+
this.buf = buf;
|
|
818
|
+
this.len = buf.length;
|
|
819
|
+
this.pos = 0;
|
|
820
|
+
this.view = new DataView(buf.buffer, buf.byteOffset, buf.byteLength);
|
|
821
|
+
}
|
|
822
|
+
/**
|
|
823
|
+
* Reads a tag - field number and wire type.
|
|
824
|
+
*/
|
|
825
|
+
tag() {
|
|
826
|
+
let tag = this.uint32(), fieldNo = tag >>> 3, wireType = tag & 7;
|
|
827
|
+
if (fieldNo <= 0 || wireType < 0 || wireType > 5)
|
|
828
|
+
throw new Error("illegal tag: field no " + fieldNo + " wire type " + wireType);
|
|
829
|
+
return [fieldNo, wireType];
|
|
830
|
+
}
|
|
831
|
+
/**
|
|
832
|
+
* Skip one element and return the skipped data.
|
|
833
|
+
*
|
|
834
|
+
* When skipping StartGroup, provide the tags field number to check for
|
|
835
|
+
* matching field number in the EndGroup tag.
|
|
836
|
+
*/
|
|
837
|
+
skip(wireType, fieldNo) {
|
|
838
|
+
let start = this.pos;
|
|
839
|
+
switch (wireType) {
|
|
840
|
+
case exports.WireType.Varint:
|
|
841
|
+
while (this.buf[this.pos++] & 128) {
|
|
842
|
+
}
|
|
843
|
+
break;
|
|
844
|
+
case exports.WireType.Bit64:
|
|
845
|
+
this.pos += 4;
|
|
846
|
+
case exports.WireType.Bit32:
|
|
847
|
+
this.pos += 4;
|
|
848
|
+
break;
|
|
849
|
+
case exports.WireType.LengthDelimited:
|
|
850
|
+
let len = this.uint32();
|
|
851
|
+
this.pos += len;
|
|
852
|
+
break;
|
|
853
|
+
case exports.WireType.StartGroup:
|
|
854
|
+
for (; ; ) {
|
|
855
|
+
const [fn, wt] = this.tag();
|
|
856
|
+
if (wt === exports.WireType.EndGroup) {
|
|
857
|
+
if (fieldNo !== void 0 && fn !== fieldNo) {
|
|
858
|
+
throw new Error("invalid end group tag");
|
|
859
|
+
}
|
|
860
|
+
break;
|
|
861
|
+
}
|
|
862
|
+
this.skip(wt, fn);
|
|
863
|
+
}
|
|
864
|
+
break;
|
|
865
|
+
default:
|
|
866
|
+
throw new Error("cant skip wire type " + wireType);
|
|
867
|
+
}
|
|
868
|
+
this.assertBounds();
|
|
869
|
+
return this.buf.subarray(start, this.pos);
|
|
870
|
+
}
|
|
871
|
+
/**
|
|
872
|
+
* Throws error if position in byte array is out of range.
|
|
873
|
+
*/
|
|
874
|
+
assertBounds() {
|
|
875
|
+
if (this.pos > this.len)
|
|
876
|
+
throw new RangeError("premature EOF");
|
|
877
|
+
}
|
|
878
|
+
/**
|
|
879
|
+
* Read a `int32` field, a signed 32 bit varint.
|
|
880
|
+
*/
|
|
881
|
+
int32() {
|
|
882
|
+
return this.uint32() | 0;
|
|
883
|
+
}
|
|
884
|
+
/**
|
|
885
|
+
* Read a `sint32` field, a signed, zigzag-encoded 32-bit varint.
|
|
886
|
+
*/
|
|
887
|
+
sint32() {
|
|
888
|
+
let zze = this.uint32();
|
|
889
|
+
return zze >>> 1 ^ -(zze & 1);
|
|
890
|
+
}
|
|
891
|
+
/**
|
|
892
|
+
* Read a `int64` field, a signed 64-bit varint.
|
|
893
|
+
*/
|
|
894
|
+
int64() {
|
|
895
|
+
return protoInt64.dec(...this.varint64());
|
|
896
|
+
}
|
|
897
|
+
/**
|
|
898
|
+
* Read a `uint64` field, an unsigned 64-bit varint.
|
|
899
|
+
*/
|
|
900
|
+
uint64() {
|
|
901
|
+
return protoInt64.uDec(...this.varint64());
|
|
902
|
+
}
|
|
903
|
+
/**
|
|
904
|
+
* Read a `sint64` field, a signed, zig-zag-encoded 64-bit varint.
|
|
905
|
+
*/
|
|
906
|
+
sint64() {
|
|
907
|
+
let [lo, hi] = this.varint64();
|
|
908
|
+
let s = -(lo & 1);
|
|
909
|
+
lo = (lo >>> 1 | (hi & 1) << 31) ^ s;
|
|
910
|
+
hi = hi >>> 1 ^ s;
|
|
911
|
+
return protoInt64.dec(lo, hi);
|
|
912
|
+
}
|
|
913
|
+
/**
|
|
914
|
+
* Read a `bool` field, a variant.
|
|
915
|
+
*/
|
|
916
|
+
bool() {
|
|
917
|
+
let [lo, hi] = this.varint64();
|
|
918
|
+
return lo !== 0 || hi !== 0;
|
|
919
|
+
}
|
|
920
|
+
/**
|
|
921
|
+
* Read a `fixed32` field, an unsigned, fixed-length 32-bit integer.
|
|
922
|
+
*/
|
|
923
|
+
fixed32() {
|
|
924
|
+
return this.view.getUint32((this.pos += 4) - 4, true);
|
|
925
|
+
}
|
|
926
|
+
/**
|
|
927
|
+
* Read a `sfixed32` field, a signed, fixed-length 32-bit integer.
|
|
928
|
+
*/
|
|
929
|
+
sfixed32() {
|
|
930
|
+
return this.view.getInt32((this.pos += 4) - 4, true);
|
|
931
|
+
}
|
|
932
|
+
/**
|
|
933
|
+
* Read a `fixed64` field, an unsigned, fixed-length 64 bit integer.
|
|
934
|
+
*/
|
|
935
|
+
fixed64() {
|
|
936
|
+
return protoInt64.uDec(this.sfixed32(), this.sfixed32());
|
|
937
|
+
}
|
|
938
|
+
/**
|
|
939
|
+
* Read a `fixed64` field, a signed, fixed-length 64-bit integer.
|
|
940
|
+
*/
|
|
941
|
+
sfixed64() {
|
|
942
|
+
return protoInt64.dec(this.sfixed32(), this.sfixed32());
|
|
943
|
+
}
|
|
944
|
+
/**
|
|
945
|
+
* Read a `float` field, 32-bit floating point number.
|
|
946
|
+
*/
|
|
947
|
+
float() {
|
|
948
|
+
return this.view.getFloat32((this.pos += 4) - 4, true);
|
|
949
|
+
}
|
|
950
|
+
/**
|
|
951
|
+
* Read a `double` field, a 64-bit floating point number.
|
|
952
|
+
*/
|
|
953
|
+
double() {
|
|
954
|
+
return this.view.getFloat64((this.pos += 8) - 8, true);
|
|
955
|
+
}
|
|
956
|
+
/**
|
|
957
|
+
* Read a `bytes` field, length-delimited arbitrary data.
|
|
958
|
+
*/
|
|
959
|
+
bytes() {
|
|
960
|
+
let len = this.uint32(), start = this.pos;
|
|
961
|
+
this.pos += len;
|
|
962
|
+
this.assertBounds();
|
|
963
|
+
return this.buf.subarray(start, start + len);
|
|
964
|
+
}
|
|
965
|
+
/**
|
|
966
|
+
* Read a `string` field, length-delimited data converted to UTF-8 text.
|
|
967
|
+
*/
|
|
968
|
+
string() {
|
|
969
|
+
return this.decodeUtf8(this.bytes());
|
|
970
|
+
}
|
|
971
|
+
}
|
|
972
|
+
function assertInt32(arg) {
|
|
973
|
+
if (typeof arg == "string") {
|
|
974
|
+
arg = Number(arg);
|
|
975
|
+
} else if (typeof arg != "number") {
|
|
976
|
+
throw new Error("invalid int32: " + typeof arg);
|
|
977
|
+
}
|
|
978
|
+
if (!Number.isInteger(arg) || arg > INT32_MAX || arg < INT32_MIN)
|
|
979
|
+
throw new Error("invalid int32: " + arg);
|
|
980
|
+
}
|
|
981
|
+
function assertUInt32(arg) {
|
|
982
|
+
if (typeof arg == "string") {
|
|
983
|
+
arg = Number(arg);
|
|
984
|
+
} else if (typeof arg != "number") {
|
|
985
|
+
throw new Error("invalid uint32: " + typeof arg);
|
|
986
|
+
}
|
|
987
|
+
if (!Number.isInteger(arg) || arg > UINT32_MAX || arg < 0)
|
|
988
|
+
throw new Error("invalid uint32: " + arg);
|
|
989
|
+
}
|
|
990
|
+
function assertFloat32(arg) {
|
|
991
|
+
if (typeof arg == "string") {
|
|
992
|
+
const o = arg;
|
|
993
|
+
arg = Number(arg);
|
|
994
|
+
if (Number.isNaN(arg) && o !== "NaN") {
|
|
995
|
+
throw new Error("invalid float32: " + o);
|
|
996
|
+
}
|
|
997
|
+
} else if (typeof arg != "number") {
|
|
998
|
+
throw new Error("invalid float32: " + typeof arg);
|
|
999
|
+
}
|
|
1000
|
+
if (Number.isFinite(arg) && (arg > FLOAT32_MAX || arg < FLOAT32_MIN))
|
|
1001
|
+
throw new Error("invalid float32: " + arg);
|
|
1002
|
+
}
|
|
1003
|
+
function checkField(field, value) {
|
|
1004
|
+
const check = field.fieldKind == "list" ? isReflectList(value, field) : field.fieldKind == "map" ? isReflectMap(value, field) : checkSingular(field, value);
|
|
1005
|
+
if (check === true) {
|
|
1006
|
+
return void 0;
|
|
1007
|
+
}
|
|
1008
|
+
let reason;
|
|
1009
|
+
switch (field.fieldKind) {
|
|
1010
|
+
case "list":
|
|
1011
|
+
reason = `expected ${formatReflectList(field)}, got ${formatVal(value)}`;
|
|
1012
|
+
break;
|
|
1013
|
+
case "map":
|
|
1014
|
+
reason = `expected ${formatReflectMap(field)}, got ${formatVal(value)}`;
|
|
1015
|
+
break;
|
|
1016
|
+
default: {
|
|
1017
|
+
reason = reasonSingular(field, value, check);
|
|
1018
|
+
}
|
|
1019
|
+
}
|
|
1020
|
+
return new FieldError(field, reason);
|
|
1021
|
+
}
|
|
1022
|
+
function checkListItem(field, index, value) {
|
|
1023
|
+
const check = checkSingular(field, value);
|
|
1024
|
+
if (check !== true) {
|
|
1025
|
+
return new FieldError(field, `list item #${index + 1}: ${reasonSingular(field, value, check)}`);
|
|
1026
|
+
}
|
|
1027
|
+
return void 0;
|
|
1028
|
+
}
|
|
1029
|
+
function checkMapEntry(field, key, value) {
|
|
1030
|
+
const checkKey = checkScalarValue(key, field.mapKey);
|
|
1031
|
+
if (checkKey !== true) {
|
|
1032
|
+
return new FieldError(field, `invalid map key: ${reasonSingular({ scalar: field.mapKey }, key, checkKey)}`);
|
|
1033
|
+
}
|
|
1034
|
+
const checkVal = checkSingular(field, value);
|
|
1035
|
+
if (checkVal !== true) {
|
|
1036
|
+
return new FieldError(field, `map entry ${formatVal(key)}: ${reasonSingular(field, value, checkVal)}`);
|
|
1037
|
+
}
|
|
1038
|
+
return void 0;
|
|
1039
|
+
}
|
|
1040
|
+
function checkSingular(field, value) {
|
|
1041
|
+
if (field.scalar !== void 0) {
|
|
1042
|
+
return checkScalarValue(value, field.scalar);
|
|
1043
|
+
}
|
|
1044
|
+
if (field.enum !== void 0) {
|
|
1045
|
+
if (field.enum.open) {
|
|
1046
|
+
return Number.isInteger(value);
|
|
1047
|
+
}
|
|
1048
|
+
return field.enum.values.some((v) => v.number === value);
|
|
1049
|
+
}
|
|
1050
|
+
return isReflectMessage(value, field.message);
|
|
1051
|
+
}
|
|
1052
|
+
function checkScalarValue(value, scalar) {
|
|
1053
|
+
switch (scalar) {
|
|
1054
|
+
case exports.ScalarType.DOUBLE:
|
|
1055
|
+
return typeof value == "number";
|
|
1056
|
+
case exports.ScalarType.FLOAT:
|
|
1057
|
+
if (typeof value != "number") {
|
|
1058
|
+
return false;
|
|
1059
|
+
}
|
|
1060
|
+
if (Number.isNaN(value) || !Number.isFinite(value)) {
|
|
1061
|
+
return true;
|
|
1062
|
+
}
|
|
1063
|
+
if (value > FLOAT32_MAX || value < FLOAT32_MIN) {
|
|
1064
|
+
return `${value.toFixed()} out of range`;
|
|
1065
|
+
}
|
|
1066
|
+
return true;
|
|
1067
|
+
case exports.ScalarType.INT32:
|
|
1068
|
+
case exports.ScalarType.SFIXED32:
|
|
1069
|
+
case exports.ScalarType.SINT32:
|
|
1070
|
+
if (typeof value !== "number" || !Number.isInteger(value)) {
|
|
1071
|
+
return false;
|
|
1072
|
+
}
|
|
1073
|
+
if (value > INT32_MAX || value < INT32_MIN) {
|
|
1074
|
+
return `${value.toFixed()} out of range`;
|
|
1075
|
+
}
|
|
1076
|
+
return true;
|
|
1077
|
+
case exports.ScalarType.FIXED32:
|
|
1078
|
+
case exports.ScalarType.UINT32:
|
|
1079
|
+
if (typeof value !== "number" || !Number.isInteger(value)) {
|
|
1080
|
+
return false;
|
|
1081
|
+
}
|
|
1082
|
+
if (value > UINT32_MAX || value < 0) {
|
|
1083
|
+
return `${value.toFixed()} out of range`;
|
|
1084
|
+
}
|
|
1085
|
+
return true;
|
|
1086
|
+
case exports.ScalarType.BOOL:
|
|
1087
|
+
return typeof value == "boolean";
|
|
1088
|
+
case exports.ScalarType.STRING:
|
|
1089
|
+
if (typeof value != "string") {
|
|
1090
|
+
return false;
|
|
1091
|
+
}
|
|
1092
|
+
return getTextEncoding().checkUtf8(value) || "invalid UTF8";
|
|
1093
|
+
case exports.ScalarType.BYTES:
|
|
1094
|
+
return value instanceof Uint8Array;
|
|
1095
|
+
case exports.ScalarType.INT64:
|
|
1096
|
+
case exports.ScalarType.SFIXED64:
|
|
1097
|
+
case exports.ScalarType.SINT64:
|
|
1098
|
+
if (typeof value == "bigint" || typeof value == "number" || typeof value == "string" && value.length > 0) {
|
|
1099
|
+
try {
|
|
1100
|
+
protoInt64.parse(value);
|
|
1101
|
+
return true;
|
|
1102
|
+
} catch (_) {
|
|
1103
|
+
return `${value} out of range`;
|
|
1104
|
+
}
|
|
1105
|
+
}
|
|
1106
|
+
return false;
|
|
1107
|
+
case exports.ScalarType.FIXED64:
|
|
1108
|
+
case exports.ScalarType.UINT64:
|
|
1109
|
+
if (typeof value == "bigint" || typeof value == "number" || typeof value == "string" && value.length > 0) {
|
|
1110
|
+
try {
|
|
1111
|
+
protoInt64.uParse(value);
|
|
1112
|
+
return true;
|
|
1113
|
+
} catch (_) {
|
|
1114
|
+
return `${value} out of range`;
|
|
1115
|
+
}
|
|
1116
|
+
}
|
|
1117
|
+
return false;
|
|
1118
|
+
}
|
|
1119
|
+
}
|
|
1120
|
+
function reasonSingular(field, val, details) {
|
|
1121
|
+
details = typeof details == "string" ? `: ${details}` : `, got ${formatVal(val)}`;
|
|
1122
|
+
if (field.scalar !== void 0) {
|
|
1123
|
+
return `expected ${scalarTypeDescription(field.scalar)}` + details;
|
|
1124
|
+
}
|
|
1125
|
+
if (field.enum !== void 0) {
|
|
1126
|
+
return `expected ${field.enum.toString()}` + details;
|
|
1127
|
+
}
|
|
1128
|
+
return `expected ${formatReflectMessage(field.message)}` + details;
|
|
1129
|
+
}
|
|
1130
|
+
function formatVal(val) {
|
|
1131
|
+
switch (typeof val) {
|
|
1132
|
+
case "object":
|
|
1133
|
+
if (val === null) {
|
|
1134
|
+
return "null";
|
|
1135
|
+
}
|
|
1136
|
+
if (val instanceof Uint8Array) {
|
|
1137
|
+
return `Uint8Array(${val.length})`;
|
|
1138
|
+
}
|
|
1139
|
+
if (Array.isArray(val)) {
|
|
1140
|
+
return `Array(${val.length})`;
|
|
1141
|
+
}
|
|
1142
|
+
if (isReflectList(val)) {
|
|
1143
|
+
return formatReflectList(val.field());
|
|
1144
|
+
}
|
|
1145
|
+
if (isReflectMap(val)) {
|
|
1146
|
+
return formatReflectMap(val.field());
|
|
1147
|
+
}
|
|
1148
|
+
if (isReflectMessage(val)) {
|
|
1149
|
+
return formatReflectMessage(val.desc);
|
|
1150
|
+
}
|
|
1151
|
+
if (isMessage(val)) {
|
|
1152
|
+
return `message ${val.$typeName}`;
|
|
1153
|
+
}
|
|
1154
|
+
return "object";
|
|
1155
|
+
case "string":
|
|
1156
|
+
return val.length > 30 ? "string" : `"${val.split('"').join('\\"')}"`;
|
|
1157
|
+
case "boolean":
|
|
1158
|
+
return String(val);
|
|
1159
|
+
case "number":
|
|
1160
|
+
return String(val);
|
|
1161
|
+
case "bigint":
|
|
1162
|
+
return String(val) + "n";
|
|
1163
|
+
default:
|
|
1164
|
+
return typeof val;
|
|
1165
|
+
}
|
|
1166
|
+
}
|
|
1167
|
+
function formatReflectMessage(desc) {
|
|
1168
|
+
return `ReflectMessage (${desc.typeName})`;
|
|
1169
|
+
}
|
|
1170
|
+
function formatReflectList(field) {
|
|
1171
|
+
switch (field.listKind) {
|
|
1172
|
+
case "message":
|
|
1173
|
+
return `ReflectList (${field.message.toString()})`;
|
|
1174
|
+
case "enum":
|
|
1175
|
+
return `ReflectList (${field.enum.toString()})`;
|
|
1176
|
+
case "scalar":
|
|
1177
|
+
return `ReflectList (${exports.ScalarType[field.scalar]})`;
|
|
1178
|
+
}
|
|
1179
|
+
}
|
|
1180
|
+
function formatReflectMap(field) {
|
|
1181
|
+
switch (field.mapKind) {
|
|
1182
|
+
case "message":
|
|
1183
|
+
return `ReflectMap (${exports.ScalarType[field.mapKey]}, ${field.message.toString()})`;
|
|
1184
|
+
case "enum":
|
|
1185
|
+
return `ReflectMap (${exports.ScalarType[field.mapKey]}, ${field.enum.toString()})`;
|
|
1186
|
+
case "scalar":
|
|
1187
|
+
return `ReflectMap (${exports.ScalarType[field.mapKey]}, ${exports.ScalarType[field.scalar]})`;
|
|
1188
|
+
}
|
|
1189
|
+
}
|
|
1190
|
+
function scalarTypeDescription(scalar) {
|
|
1191
|
+
switch (scalar) {
|
|
1192
|
+
case exports.ScalarType.STRING:
|
|
1193
|
+
return "string";
|
|
1194
|
+
case exports.ScalarType.BOOL:
|
|
1195
|
+
return "boolean";
|
|
1196
|
+
case exports.ScalarType.INT64:
|
|
1197
|
+
case exports.ScalarType.SINT64:
|
|
1198
|
+
case exports.ScalarType.SFIXED64:
|
|
1199
|
+
return "bigint (int64)";
|
|
1200
|
+
case exports.ScalarType.UINT64:
|
|
1201
|
+
case exports.ScalarType.FIXED64:
|
|
1202
|
+
return "bigint (uint64)";
|
|
1203
|
+
case exports.ScalarType.BYTES:
|
|
1204
|
+
return "Uint8Array";
|
|
1205
|
+
case exports.ScalarType.DOUBLE:
|
|
1206
|
+
return "number (float64)";
|
|
1207
|
+
case exports.ScalarType.FLOAT:
|
|
1208
|
+
return "number (float32)";
|
|
1209
|
+
case exports.ScalarType.FIXED32:
|
|
1210
|
+
case exports.ScalarType.UINT32:
|
|
1211
|
+
return "number (uint32)";
|
|
1212
|
+
case exports.ScalarType.INT32:
|
|
1213
|
+
case exports.ScalarType.SFIXED32:
|
|
1214
|
+
case exports.ScalarType.SINT32:
|
|
1215
|
+
return "number (int32)";
|
|
1216
|
+
}
|
|
1217
|
+
}
|
|
1218
|
+
function reflect(messageDesc, message, check = true) {
|
|
1219
|
+
return new ReflectMessageImpl(messageDesc, message, check);
|
|
1220
|
+
}
|
|
1221
|
+
const messageSortedFields = /* @__PURE__ */ new WeakMap();
|
|
1222
|
+
class ReflectMessageImpl {
|
|
1223
|
+
get sortedFields() {
|
|
1224
|
+
const cached = messageSortedFields.get(this.desc);
|
|
1225
|
+
if (cached) {
|
|
1226
|
+
return cached;
|
|
1227
|
+
}
|
|
1228
|
+
const sortedFields = this.desc.fields.concat().sort((a, b) => a.number - b.number);
|
|
1229
|
+
messageSortedFields.set(this.desc, sortedFields);
|
|
1230
|
+
return sortedFields;
|
|
1231
|
+
}
|
|
1232
|
+
constructor(messageDesc, message, check = true) {
|
|
1233
|
+
this.lists = /* @__PURE__ */ new Map();
|
|
1234
|
+
this.maps = /* @__PURE__ */ new Map();
|
|
1235
|
+
this.check = check;
|
|
1236
|
+
this.desc = messageDesc;
|
|
1237
|
+
this.message = this[unsafeLocal] = message !== null && message !== void 0 ? message : create(messageDesc);
|
|
1238
|
+
this.fields = messageDesc.fields;
|
|
1239
|
+
this.oneofs = messageDesc.oneofs;
|
|
1240
|
+
this.members = messageDesc.members;
|
|
1241
|
+
}
|
|
1242
|
+
findNumber(number) {
|
|
1243
|
+
if (!this._fieldsByNumber) {
|
|
1244
|
+
this._fieldsByNumber = new Map(this.desc.fields.map((f) => [f.number, f]));
|
|
1245
|
+
}
|
|
1246
|
+
return this._fieldsByNumber.get(number);
|
|
1247
|
+
}
|
|
1248
|
+
oneofCase(oneof) {
|
|
1249
|
+
assertOwn(this.message, oneof);
|
|
1250
|
+
return unsafeOneofCase(this.message, oneof);
|
|
1251
|
+
}
|
|
1252
|
+
isSet(field) {
|
|
1253
|
+
assertOwn(this.message, field);
|
|
1254
|
+
return unsafeIsSet(this.message, field);
|
|
1255
|
+
}
|
|
1256
|
+
clear(field) {
|
|
1257
|
+
assertOwn(this.message, field);
|
|
1258
|
+
unsafeClear(this.message, field);
|
|
1259
|
+
}
|
|
1260
|
+
get(field) {
|
|
1261
|
+
assertOwn(this.message, field);
|
|
1262
|
+
const value = unsafeGet(this.message, field);
|
|
1263
|
+
switch (field.fieldKind) {
|
|
1264
|
+
case "list":
|
|
1265
|
+
let list = this.lists.get(field);
|
|
1266
|
+
if (!list || list[unsafeLocal] !== value) {
|
|
1267
|
+
this.lists.set(
|
|
1268
|
+
field,
|
|
1269
|
+
// biome-ignore lint/suspicious/noAssignInExpressions: no
|
|
1270
|
+
list = new ReflectListImpl(field, value, this.check)
|
|
1271
|
+
);
|
|
1272
|
+
}
|
|
1273
|
+
return list;
|
|
1274
|
+
case "map":
|
|
1275
|
+
let map = this.maps.get(field);
|
|
1276
|
+
if (!map || map[unsafeLocal] !== value) {
|
|
1277
|
+
this.maps.set(
|
|
1278
|
+
field,
|
|
1279
|
+
// biome-ignore lint/suspicious/noAssignInExpressions: no
|
|
1280
|
+
map = new ReflectMapImpl(field, value, this.check)
|
|
1281
|
+
);
|
|
1282
|
+
}
|
|
1283
|
+
return map;
|
|
1284
|
+
case "message":
|
|
1285
|
+
return messageToReflect(field, value, this.check);
|
|
1286
|
+
case "scalar":
|
|
1287
|
+
return value === void 0 ? scalarZeroValue(field.scalar, false) : longToReflect(field, value);
|
|
1288
|
+
case "enum":
|
|
1289
|
+
return value !== null && value !== void 0 ? value : field.enum.values[0].number;
|
|
1290
|
+
}
|
|
1291
|
+
}
|
|
1292
|
+
set(field, value) {
|
|
1293
|
+
assertOwn(this.message, field);
|
|
1294
|
+
if (this.check) {
|
|
1295
|
+
const err = checkField(field, value);
|
|
1296
|
+
if (err) {
|
|
1297
|
+
throw err;
|
|
1298
|
+
}
|
|
1299
|
+
}
|
|
1300
|
+
let local;
|
|
1301
|
+
if (field.fieldKind == "message") {
|
|
1302
|
+
local = messageToLocal(field, value);
|
|
1303
|
+
} else if (isReflectMap(value) || isReflectList(value)) {
|
|
1304
|
+
local = value[unsafeLocal];
|
|
1305
|
+
} else {
|
|
1306
|
+
local = longToLocal(field, value);
|
|
1307
|
+
}
|
|
1308
|
+
unsafeSet(this.message, field, local);
|
|
1309
|
+
}
|
|
1310
|
+
getUnknown() {
|
|
1311
|
+
return this.message.$unknown;
|
|
1312
|
+
}
|
|
1313
|
+
setUnknown(value) {
|
|
1314
|
+
this.message.$unknown = value;
|
|
1315
|
+
}
|
|
1316
|
+
}
|
|
1317
|
+
function assertOwn(owner, member) {
|
|
1318
|
+
if (member.parent.typeName !== owner.$typeName) {
|
|
1319
|
+
throw new FieldError(member, `cannot use ${member.toString()} with message ${owner.$typeName}`, "ForeignFieldError");
|
|
1320
|
+
}
|
|
1321
|
+
}
|
|
1322
|
+
class ReflectListImpl {
|
|
1323
|
+
field() {
|
|
1324
|
+
return this._field;
|
|
1325
|
+
}
|
|
1326
|
+
get size() {
|
|
1327
|
+
return this._arr.length;
|
|
1328
|
+
}
|
|
1329
|
+
constructor(field, unsafeInput, check) {
|
|
1330
|
+
this._field = field;
|
|
1331
|
+
this._arr = this[unsafeLocal] = unsafeInput;
|
|
1332
|
+
this.check = check;
|
|
1333
|
+
}
|
|
1334
|
+
get(index) {
|
|
1335
|
+
const item = this._arr[index];
|
|
1336
|
+
return item === void 0 ? void 0 : listItemToReflect(this._field, item, this.check);
|
|
1337
|
+
}
|
|
1338
|
+
set(index, item) {
|
|
1339
|
+
if (index < 0 || index >= this._arr.length) {
|
|
1340
|
+
throw new FieldError(this._field, `list item #${index + 1}: out of range`);
|
|
1341
|
+
}
|
|
1342
|
+
if (this.check) {
|
|
1343
|
+
const err = checkListItem(this._field, index, item);
|
|
1344
|
+
if (err) {
|
|
1345
|
+
throw err;
|
|
1346
|
+
}
|
|
1347
|
+
}
|
|
1348
|
+
this._arr[index] = listItemToLocal(this._field, item);
|
|
1349
|
+
}
|
|
1350
|
+
add(item) {
|
|
1351
|
+
if (this.check) {
|
|
1352
|
+
const err = checkListItem(this._field, this._arr.length, item);
|
|
1353
|
+
if (err) {
|
|
1354
|
+
throw err;
|
|
1355
|
+
}
|
|
1356
|
+
}
|
|
1357
|
+
this._arr.push(listItemToLocal(this._field, item));
|
|
1358
|
+
return void 0;
|
|
1359
|
+
}
|
|
1360
|
+
clear() {
|
|
1361
|
+
this._arr.splice(0, this._arr.length);
|
|
1362
|
+
}
|
|
1363
|
+
[Symbol.iterator]() {
|
|
1364
|
+
return this.values();
|
|
1365
|
+
}
|
|
1366
|
+
keys() {
|
|
1367
|
+
return this._arr.keys();
|
|
1368
|
+
}
|
|
1369
|
+
*values() {
|
|
1370
|
+
for (const item of this._arr) {
|
|
1371
|
+
yield listItemToReflect(this._field, item, this.check);
|
|
1372
|
+
}
|
|
1373
|
+
}
|
|
1374
|
+
*entries() {
|
|
1375
|
+
for (let i = 0; i < this._arr.length; i++) {
|
|
1376
|
+
yield [i, listItemToReflect(this._field, this._arr[i], this.check)];
|
|
1377
|
+
}
|
|
1378
|
+
}
|
|
1379
|
+
}
|
|
1380
|
+
class ReflectMapImpl {
|
|
1381
|
+
constructor(field, unsafeInput, check = true) {
|
|
1382
|
+
this.obj = this[unsafeLocal] = unsafeInput !== null && unsafeInput !== void 0 ? unsafeInput : {};
|
|
1383
|
+
this.check = check;
|
|
1384
|
+
this._field = field;
|
|
1385
|
+
}
|
|
1386
|
+
field() {
|
|
1387
|
+
return this._field;
|
|
1388
|
+
}
|
|
1389
|
+
set(key, value) {
|
|
1390
|
+
if (this.check) {
|
|
1391
|
+
const err = checkMapEntry(this._field, key, value);
|
|
1392
|
+
if (err) {
|
|
1393
|
+
throw err;
|
|
1394
|
+
}
|
|
1395
|
+
}
|
|
1396
|
+
this.obj[mapKeyToLocal(key)] = mapValueToLocal(this._field, value);
|
|
1397
|
+
return this;
|
|
1398
|
+
}
|
|
1399
|
+
delete(key) {
|
|
1400
|
+
const k = mapKeyToLocal(key);
|
|
1401
|
+
const has = Object.prototype.hasOwnProperty.call(this.obj, k);
|
|
1402
|
+
if (has) {
|
|
1403
|
+
delete this.obj[k];
|
|
1404
|
+
}
|
|
1405
|
+
return has;
|
|
1406
|
+
}
|
|
1407
|
+
clear() {
|
|
1408
|
+
for (const key of Object.keys(this.obj)) {
|
|
1409
|
+
delete this.obj[key];
|
|
1410
|
+
}
|
|
1411
|
+
}
|
|
1412
|
+
get(key) {
|
|
1413
|
+
let val = this.obj[mapKeyToLocal(key)];
|
|
1414
|
+
if (val !== void 0) {
|
|
1415
|
+
val = mapValueToReflect(this._field, val, this.check);
|
|
1416
|
+
}
|
|
1417
|
+
return val;
|
|
1418
|
+
}
|
|
1419
|
+
has(key) {
|
|
1420
|
+
return Object.prototype.hasOwnProperty.call(this.obj, mapKeyToLocal(key));
|
|
1421
|
+
}
|
|
1422
|
+
*keys() {
|
|
1423
|
+
for (const objKey of Object.keys(this.obj)) {
|
|
1424
|
+
yield mapKeyToReflect(objKey, this._field.mapKey);
|
|
1425
|
+
}
|
|
1426
|
+
}
|
|
1427
|
+
*entries() {
|
|
1428
|
+
for (const objEntry of Object.entries(this.obj)) {
|
|
1429
|
+
yield [
|
|
1430
|
+
mapKeyToReflect(objEntry[0], this._field.mapKey),
|
|
1431
|
+
mapValueToReflect(this._field, objEntry[1], this.check)
|
|
1432
|
+
];
|
|
1433
|
+
}
|
|
1434
|
+
}
|
|
1435
|
+
[Symbol.iterator]() {
|
|
1436
|
+
return this.entries();
|
|
1437
|
+
}
|
|
1438
|
+
get size() {
|
|
1439
|
+
return Object.keys(this.obj).length;
|
|
1440
|
+
}
|
|
1441
|
+
*values() {
|
|
1442
|
+
for (const val of Object.values(this.obj)) {
|
|
1443
|
+
yield mapValueToReflect(this._field, val, this.check);
|
|
1444
|
+
}
|
|
1445
|
+
}
|
|
1446
|
+
forEach(callbackfn, thisArg) {
|
|
1447
|
+
for (const mapEntry of this.entries()) {
|
|
1448
|
+
callbackfn.call(thisArg, mapEntry[1], mapEntry[0], this);
|
|
1449
|
+
}
|
|
1450
|
+
}
|
|
1451
|
+
}
|
|
1452
|
+
function messageToLocal(field, value) {
|
|
1453
|
+
if (!isReflectMessage(value)) {
|
|
1454
|
+
return value;
|
|
1455
|
+
}
|
|
1456
|
+
if (isWrapper(value.message) && !field.oneof && field.fieldKind == "message") {
|
|
1457
|
+
return value.message.value;
|
|
1458
|
+
}
|
|
1459
|
+
if (value.desc.typeName == "google.protobuf.Struct" && field.parent.typeName != "google.protobuf.Value") {
|
|
1460
|
+
return wktStructToLocal(value.message);
|
|
1461
|
+
}
|
|
1462
|
+
return value.message;
|
|
1463
|
+
}
|
|
1464
|
+
function messageToReflect(field, value, check) {
|
|
1465
|
+
if (value !== void 0) {
|
|
1466
|
+
if (isWrapperDesc(field.message) && !field.oneof && field.fieldKind == "message") {
|
|
1467
|
+
value = {
|
|
1468
|
+
$typeName: field.message.typeName,
|
|
1469
|
+
value: longToReflect(field.message.fields[0], value)
|
|
1470
|
+
};
|
|
1471
|
+
} else if (field.message.typeName == "google.protobuf.Struct" && field.parent.typeName != "google.protobuf.Value" && isObject(value)) {
|
|
1472
|
+
value = wktStructToReflect(value);
|
|
1473
|
+
}
|
|
1474
|
+
}
|
|
1475
|
+
return new ReflectMessageImpl(field.message, value, check);
|
|
1476
|
+
}
|
|
1477
|
+
function listItemToLocal(field, value) {
|
|
1478
|
+
if (field.listKind == "message") {
|
|
1479
|
+
return messageToLocal(field, value);
|
|
1480
|
+
}
|
|
1481
|
+
return longToLocal(field, value);
|
|
1482
|
+
}
|
|
1483
|
+
function listItemToReflect(field, value, check) {
|
|
1484
|
+
if (field.listKind == "message") {
|
|
1485
|
+
return messageToReflect(field, value, check);
|
|
1486
|
+
}
|
|
1487
|
+
return longToReflect(field, value);
|
|
1488
|
+
}
|
|
1489
|
+
function mapValueToLocal(field, value) {
|
|
1490
|
+
if (field.mapKind == "message") {
|
|
1491
|
+
return messageToLocal(field, value);
|
|
1492
|
+
}
|
|
1493
|
+
return longToLocal(field, value);
|
|
1494
|
+
}
|
|
1495
|
+
function mapValueToReflect(field, value, check) {
|
|
1496
|
+
if (field.mapKind == "message") {
|
|
1497
|
+
return messageToReflect(field, value, check);
|
|
1498
|
+
}
|
|
1499
|
+
return value;
|
|
1500
|
+
}
|
|
1501
|
+
function mapKeyToLocal(key) {
|
|
1502
|
+
return typeof key == "string" || typeof key == "number" ? key : String(key);
|
|
1503
|
+
}
|
|
1504
|
+
function mapKeyToReflect(key, type) {
|
|
1505
|
+
switch (type) {
|
|
1506
|
+
case exports.ScalarType.STRING:
|
|
1507
|
+
return key;
|
|
1508
|
+
case exports.ScalarType.INT32:
|
|
1509
|
+
case exports.ScalarType.FIXED32:
|
|
1510
|
+
case exports.ScalarType.UINT32:
|
|
1511
|
+
case exports.ScalarType.SFIXED32:
|
|
1512
|
+
case exports.ScalarType.SINT32: {
|
|
1513
|
+
const n = Number.parseInt(key);
|
|
1514
|
+
if (Number.isFinite(n)) {
|
|
1515
|
+
return n;
|
|
1516
|
+
}
|
|
1517
|
+
break;
|
|
1518
|
+
}
|
|
1519
|
+
case exports.ScalarType.BOOL:
|
|
1520
|
+
switch (key) {
|
|
1521
|
+
case "true":
|
|
1522
|
+
return true;
|
|
1523
|
+
case "false":
|
|
1524
|
+
return false;
|
|
1525
|
+
}
|
|
1526
|
+
break;
|
|
1527
|
+
case exports.ScalarType.UINT64:
|
|
1528
|
+
case exports.ScalarType.FIXED64:
|
|
1529
|
+
try {
|
|
1530
|
+
return protoInt64.uParse(key);
|
|
1531
|
+
} catch (_a) {
|
|
1532
|
+
}
|
|
1533
|
+
break;
|
|
1534
|
+
default:
|
|
1535
|
+
try {
|
|
1536
|
+
return protoInt64.parse(key);
|
|
1537
|
+
} catch (_b) {
|
|
1538
|
+
}
|
|
1539
|
+
break;
|
|
1540
|
+
}
|
|
1541
|
+
return key;
|
|
1542
|
+
}
|
|
1543
|
+
function longToReflect(field, value) {
|
|
1544
|
+
switch (field.scalar) {
|
|
1545
|
+
case exports.ScalarType.INT64:
|
|
1546
|
+
case exports.ScalarType.SFIXED64:
|
|
1547
|
+
case exports.ScalarType.SINT64:
|
|
1548
|
+
if ("longAsString" in field && field.longAsString && typeof value == "string") {
|
|
1549
|
+
value = protoInt64.parse(value);
|
|
1550
|
+
}
|
|
1551
|
+
break;
|
|
1552
|
+
case exports.ScalarType.FIXED64:
|
|
1553
|
+
case exports.ScalarType.UINT64:
|
|
1554
|
+
if ("longAsString" in field && field.longAsString && typeof value == "string") {
|
|
1555
|
+
value = protoInt64.uParse(value);
|
|
1556
|
+
}
|
|
1557
|
+
break;
|
|
1558
|
+
}
|
|
1559
|
+
return value;
|
|
1560
|
+
}
|
|
1561
|
+
function longToLocal(field, value) {
|
|
1562
|
+
switch (field.scalar) {
|
|
1563
|
+
case exports.ScalarType.INT64:
|
|
1564
|
+
case exports.ScalarType.SFIXED64:
|
|
1565
|
+
case exports.ScalarType.SINT64:
|
|
1566
|
+
if ("longAsString" in field && field.longAsString) {
|
|
1567
|
+
value = String(value);
|
|
1568
|
+
} else if (typeof value == "string" || typeof value == "number") {
|
|
1569
|
+
value = protoInt64.parse(value);
|
|
1570
|
+
}
|
|
1571
|
+
break;
|
|
1572
|
+
case exports.ScalarType.FIXED64:
|
|
1573
|
+
case exports.ScalarType.UINT64:
|
|
1574
|
+
if ("longAsString" in field && field.longAsString) {
|
|
1575
|
+
value = String(value);
|
|
1576
|
+
} else if (typeof value == "string" || typeof value == "number") {
|
|
1577
|
+
value = protoInt64.uParse(value);
|
|
1578
|
+
}
|
|
1579
|
+
break;
|
|
1580
|
+
}
|
|
1581
|
+
return value;
|
|
1582
|
+
}
|
|
1583
|
+
function wktStructToReflect(json) {
|
|
1584
|
+
const struct = {
|
|
1585
|
+
$typeName: "google.protobuf.Struct",
|
|
1586
|
+
fields: {}
|
|
1587
|
+
};
|
|
1588
|
+
if (isObject(json)) {
|
|
1589
|
+
for (const [k, v] of Object.entries(json)) {
|
|
1590
|
+
struct.fields[k] = wktValueToReflect(v);
|
|
1591
|
+
}
|
|
1592
|
+
}
|
|
1593
|
+
return struct;
|
|
1594
|
+
}
|
|
1595
|
+
function wktStructToLocal(val) {
|
|
1596
|
+
const json = {};
|
|
1597
|
+
for (const [k, v] of Object.entries(val.fields)) {
|
|
1598
|
+
json[k] = wktValueToLocal(v);
|
|
1599
|
+
}
|
|
1600
|
+
return json;
|
|
1601
|
+
}
|
|
1602
|
+
function wktValueToLocal(val) {
|
|
1603
|
+
switch (val.kind.case) {
|
|
1604
|
+
case "structValue":
|
|
1605
|
+
return wktStructToLocal(val.kind.value);
|
|
1606
|
+
case "listValue":
|
|
1607
|
+
return val.kind.value.values.map(wktValueToLocal);
|
|
1608
|
+
case "nullValue":
|
|
1609
|
+
case void 0:
|
|
1610
|
+
return null;
|
|
1611
|
+
default:
|
|
1612
|
+
return val.kind.value;
|
|
1613
|
+
}
|
|
1614
|
+
}
|
|
1615
|
+
function wktValueToReflect(json) {
|
|
1616
|
+
const value = {
|
|
1617
|
+
$typeName: "google.protobuf.Value",
|
|
1618
|
+
kind: { case: void 0 }
|
|
1619
|
+
};
|
|
1620
|
+
switch (typeof json) {
|
|
1621
|
+
case "number":
|
|
1622
|
+
value.kind = { case: "numberValue", value: json };
|
|
1623
|
+
break;
|
|
1624
|
+
case "string":
|
|
1625
|
+
value.kind = { case: "stringValue", value: json };
|
|
1626
|
+
break;
|
|
1627
|
+
case "boolean":
|
|
1628
|
+
value.kind = { case: "boolValue", value: json };
|
|
1629
|
+
break;
|
|
1630
|
+
case "object":
|
|
1631
|
+
if (json === null) {
|
|
1632
|
+
const nullValue = 0;
|
|
1633
|
+
value.kind = { case: "nullValue", value: nullValue };
|
|
1634
|
+
} else if (Array.isArray(json)) {
|
|
1635
|
+
const listValue = {
|
|
1636
|
+
$typeName: "google.protobuf.ListValue",
|
|
1637
|
+
values: []
|
|
1638
|
+
};
|
|
1639
|
+
if (Array.isArray(json)) {
|
|
1640
|
+
for (const e of json) {
|
|
1641
|
+
listValue.values.push(wktValueToReflect(e));
|
|
1642
|
+
}
|
|
1643
|
+
}
|
|
1644
|
+
value.kind = {
|
|
1645
|
+
case: "listValue",
|
|
1646
|
+
value: listValue
|
|
1647
|
+
};
|
|
1648
|
+
} else {
|
|
1649
|
+
value.kind = {
|
|
1650
|
+
case: "structValue",
|
|
1651
|
+
value: wktStructToReflect(json)
|
|
1652
|
+
};
|
|
1653
|
+
}
|
|
1654
|
+
break;
|
|
1655
|
+
}
|
|
1656
|
+
return value;
|
|
1657
|
+
}
|
|
1658
|
+
const readDefaults = {
|
|
1659
|
+
readUnknownFields: true
|
|
1660
|
+
};
|
|
1661
|
+
function makeReadOptions(options) {
|
|
1662
|
+
return options ? Object.assign(Object.assign({}, readDefaults), options) : readDefaults;
|
|
1663
|
+
}
|
|
1664
|
+
function fromBinary(schema, bytes, options) {
|
|
1665
|
+
const msg = reflect(schema, void 0, false);
|
|
1666
|
+
readMessage(msg, new BinaryReader(bytes), makeReadOptions(options), false, bytes.byteLength);
|
|
1667
|
+
return msg.message;
|
|
1668
|
+
}
|
|
1669
|
+
function readMessage(message, reader, options, delimited, lengthOrDelimitedFieldNo) {
|
|
1670
|
+
var _a;
|
|
1671
|
+
const end = delimited ? reader.len : reader.pos + lengthOrDelimitedFieldNo;
|
|
1672
|
+
let fieldNo;
|
|
1673
|
+
let wireType;
|
|
1674
|
+
const unknownFields = (_a = message.getUnknown()) !== null && _a !== void 0 ? _a : [];
|
|
1675
|
+
while (reader.pos < end) {
|
|
1676
|
+
[fieldNo, wireType] = reader.tag();
|
|
1677
|
+
if (delimited && wireType == exports.WireType.EndGroup) {
|
|
1678
|
+
break;
|
|
1679
|
+
}
|
|
1680
|
+
const field = message.findNumber(fieldNo);
|
|
1681
|
+
if (!field) {
|
|
1682
|
+
const data = reader.skip(wireType, fieldNo);
|
|
1683
|
+
if (options.readUnknownFields) {
|
|
1684
|
+
unknownFields.push({ no: fieldNo, wireType, data });
|
|
1685
|
+
}
|
|
1686
|
+
continue;
|
|
1687
|
+
}
|
|
1688
|
+
readField(message, reader, field, wireType, options);
|
|
1689
|
+
}
|
|
1690
|
+
if (delimited) {
|
|
1691
|
+
if (wireType != exports.WireType.EndGroup || fieldNo !== lengthOrDelimitedFieldNo) {
|
|
1692
|
+
throw new Error("invalid end group tag");
|
|
1693
|
+
}
|
|
1694
|
+
}
|
|
1695
|
+
if (unknownFields.length > 0) {
|
|
1696
|
+
message.setUnknown(unknownFields);
|
|
1697
|
+
}
|
|
1698
|
+
}
|
|
1699
|
+
function readField(message, reader, field, wireType, options) {
|
|
1700
|
+
var _a;
|
|
1701
|
+
switch (field.fieldKind) {
|
|
1702
|
+
case "scalar":
|
|
1703
|
+
message.set(field, readScalar(reader, field.scalar));
|
|
1704
|
+
break;
|
|
1705
|
+
case "enum":
|
|
1706
|
+
const val = readScalar(reader, exports.ScalarType.INT32);
|
|
1707
|
+
if (field.enum.open) {
|
|
1708
|
+
message.set(field, val);
|
|
1709
|
+
} else {
|
|
1710
|
+
const ok = field.enum.values.some((v) => v.number === val);
|
|
1711
|
+
if (ok) {
|
|
1712
|
+
message.set(field, val);
|
|
1713
|
+
} else if (options.readUnknownFields) {
|
|
1714
|
+
const bytes = [];
|
|
1715
|
+
varint32write(val, bytes);
|
|
1716
|
+
const unknownFields = (_a = message.getUnknown()) !== null && _a !== void 0 ? _a : [];
|
|
1717
|
+
unknownFields.push({
|
|
1718
|
+
no: field.number,
|
|
1719
|
+
wireType,
|
|
1720
|
+
data: new Uint8Array(bytes)
|
|
1721
|
+
});
|
|
1722
|
+
message.setUnknown(unknownFields);
|
|
1723
|
+
}
|
|
1724
|
+
}
|
|
1725
|
+
break;
|
|
1726
|
+
case "message":
|
|
1727
|
+
message.set(field, readMessageField(reader, options, field, message.get(field)));
|
|
1728
|
+
break;
|
|
1729
|
+
case "list":
|
|
1730
|
+
readListField(reader, wireType, message.get(field), options);
|
|
1731
|
+
break;
|
|
1732
|
+
case "map":
|
|
1733
|
+
readMapEntry(reader, message.get(field), options);
|
|
1734
|
+
break;
|
|
1735
|
+
}
|
|
1736
|
+
}
|
|
1737
|
+
function readMapEntry(reader, map, options) {
|
|
1738
|
+
const field = map.field();
|
|
1739
|
+
let key;
|
|
1740
|
+
let val;
|
|
1741
|
+
const len = reader.uint32();
|
|
1742
|
+
const end = reader.pos + len;
|
|
1743
|
+
while (reader.pos < end) {
|
|
1744
|
+
const [fieldNo] = reader.tag();
|
|
1745
|
+
switch (fieldNo) {
|
|
1746
|
+
case 1:
|
|
1747
|
+
key = readScalar(reader, field.mapKey);
|
|
1748
|
+
break;
|
|
1749
|
+
case 2:
|
|
1750
|
+
switch (field.mapKind) {
|
|
1751
|
+
case "scalar":
|
|
1752
|
+
val = readScalar(reader, field.scalar);
|
|
1753
|
+
break;
|
|
1754
|
+
case "enum":
|
|
1755
|
+
val = reader.int32();
|
|
1756
|
+
break;
|
|
1757
|
+
case "message":
|
|
1758
|
+
val = readMessageField(reader, options, field);
|
|
1759
|
+
break;
|
|
1760
|
+
}
|
|
1761
|
+
break;
|
|
1762
|
+
}
|
|
1763
|
+
}
|
|
1764
|
+
if (key === void 0) {
|
|
1765
|
+
key = scalarZeroValue(field.mapKey, false);
|
|
1766
|
+
}
|
|
1767
|
+
if (val === void 0) {
|
|
1768
|
+
switch (field.mapKind) {
|
|
1769
|
+
case "scalar":
|
|
1770
|
+
val = scalarZeroValue(field.scalar, false);
|
|
1771
|
+
break;
|
|
1772
|
+
case "enum":
|
|
1773
|
+
val = field.enum.values[0].number;
|
|
1774
|
+
break;
|
|
1775
|
+
case "message":
|
|
1776
|
+
val = reflect(field.message, void 0, false);
|
|
1777
|
+
break;
|
|
1778
|
+
}
|
|
1779
|
+
}
|
|
1780
|
+
map.set(key, val);
|
|
1781
|
+
}
|
|
1782
|
+
function readListField(reader, wireType, list, options) {
|
|
1783
|
+
var _a;
|
|
1784
|
+
const field = list.field();
|
|
1785
|
+
if (field.listKind === "message") {
|
|
1786
|
+
list.add(readMessageField(reader, options, field));
|
|
1787
|
+
return;
|
|
1788
|
+
}
|
|
1789
|
+
const scalarType = (_a = field.scalar) !== null && _a !== void 0 ? _a : exports.ScalarType.INT32;
|
|
1790
|
+
const packed = wireType == exports.WireType.LengthDelimited && scalarType != exports.ScalarType.STRING && scalarType != exports.ScalarType.BYTES;
|
|
1791
|
+
if (!packed) {
|
|
1792
|
+
list.add(readScalar(reader, scalarType));
|
|
1793
|
+
return;
|
|
1794
|
+
}
|
|
1795
|
+
const e = reader.uint32() + reader.pos;
|
|
1796
|
+
while (reader.pos < e) {
|
|
1797
|
+
list.add(readScalar(reader, scalarType));
|
|
1798
|
+
}
|
|
1799
|
+
}
|
|
1800
|
+
function readMessageField(reader, options, field, mergeMessage) {
|
|
1801
|
+
const delimited = field.delimitedEncoding;
|
|
1802
|
+
const message = mergeMessage !== null && mergeMessage !== void 0 ? mergeMessage : reflect(field.message, void 0, false);
|
|
1803
|
+
readMessage(message, reader, options, delimited, delimited ? field.number : reader.uint32());
|
|
1804
|
+
return message;
|
|
1805
|
+
}
|
|
1806
|
+
function readScalar(reader, type) {
|
|
1807
|
+
switch (type) {
|
|
1808
|
+
case exports.ScalarType.STRING:
|
|
1809
|
+
return reader.string();
|
|
1810
|
+
case exports.ScalarType.BOOL:
|
|
1811
|
+
return reader.bool();
|
|
1812
|
+
case exports.ScalarType.DOUBLE:
|
|
1813
|
+
return reader.double();
|
|
1814
|
+
case exports.ScalarType.FLOAT:
|
|
1815
|
+
return reader.float();
|
|
1816
|
+
case exports.ScalarType.INT32:
|
|
1817
|
+
return reader.int32();
|
|
1818
|
+
case exports.ScalarType.INT64:
|
|
1819
|
+
return reader.int64();
|
|
1820
|
+
case exports.ScalarType.UINT64:
|
|
1821
|
+
return reader.uint64();
|
|
1822
|
+
case exports.ScalarType.FIXED64:
|
|
1823
|
+
return reader.fixed64();
|
|
1824
|
+
case exports.ScalarType.BYTES:
|
|
1825
|
+
return reader.bytes();
|
|
1826
|
+
case exports.ScalarType.FIXED32:
|
|
1827
|
+
return reader.fixed32();
|
|
1828
|
+
case exports.ScalarType.SFIXED32:
|
|
1829
|
+
return reader.sfixed32();
|
|
1830
|
+
case exports.ScalarType.SFIXED64:
|
|
1831
|
+
return reader.sfixed64();
|
|
1832
|
+
case exports.ScalarType.SINT64:
|
|
1833
|
+
return reader.sint64();
|
|
1834
|
+
case exports.ScalarType.UINT32:
|
|
1835
|
+
return reader.uint32();
|
|
1836
|
+
case exports.ScalarType.SINT32:
|
|
1837
|
+
return reader.sint32();
|
|
1838
|
+
}
|
|
1839
|
+
}
|
|
3
1840
|
class MeshtasticError extends Error {
|
|
4
1841
|
constructor(message, cause) {
|
|
5
1842
|
super(message);
|
|
@@ -68,7 +1905,7 @@ function ensureUint8Array(input) {
|
|
|
68
1905
|
function decodeServiceEnvelope(buffer) {
|
|
69
1906
|
try {
|
|
70
1907
|
const uint8 = ensureUint8Array(buffer);
|
|
71
|
-
return protobufs.
|
|
1908
|
+
return fromBinary(protobufs.Mqtt.ServiceEnvelopeSchema, uint8);
|
|
72
1909
|
} catch (error) {
|
|
73
1910
|
throw new ProtobufError(
|
|
74
1911
|
`Failed to decode ServiceEnvelope: ${error instanceof Error ? error.message : String(error)}`,
|
|
@@ -79,7 +1916,7 @@ function decodeServiceEnvelope(buffer) {
|
|
|
79
1916
|
function decodeData(buffer) {
|
|
80
1917
|
try {
|
|
81
1918
|
const uint8 = ensureUint8Array(buffer);
|
|
82
|
-
return protobufs.
|
|
1919
|
+
return fromBinary(protobufs.Mesh.DataSchema, uint8);
|
|
83
1920
|
} catch (error) {
|
|
84
1921
|
throw new ProtobufError(
|
|
85
1922
|
`Failed to decode Data: ${error instanceof Error ? error.message : String(error)}`,
|
|
@@ -91,47 +1928,47 @@ function decodeMessageByPortNum(portNum, payload) {
|
|
|
91
1928
|
try {
|
|
92
1929
|
const uint8 = ensureUint8Array(payload);
|
|
93
1930
|
switch (portNum) {
|
|
94
|
-
case protobufs.
|
|
1931
|
+
case protobufs.Portnums.PortNum.TEXT_MESSAGE_APP:
|
|
95
1932
|
return new TextDecoder().decode(uint8);
|
|
96
|
-
case protobufs.
|
|
97
|
-
return protobufs.
|
|
98
|
-
case protobufs.
|
|
99
|
-
return protobufs.
|
|
100
|
-
case protobufs.
|
|
101
|
-
return protobufs.
|
|
102
|
-
case protobufs.
|
|
103
|
-
return protobufs.
|
|
104
|
-
case protobufs.
|
|
105
|
-
return protobufs.
|
|
106
|
-
case protobufs.
|
|
107
|
-
return protobufs.
|
|
108
|
-
case protobufs.
|
|
109
|
-
return protobufs.
|
|
110
|
-
case protobufs.
|
|
111
|
-
return protobufs.
|
|
112
|
-
case protobufs.
|
|
1933
|
+
case protobufs.Portnums.PortNum.POSITION_APP:
|
|
1934
|
+
return fromBinary(protobufs.Mesh.PositionSchema, uint8);
|
|
1935
|
+
case protobufs.Portnums.PortNum.NODEINFO_APP:
|
|
1936
|
+
return fromBinary(protobufs.Mesh.UserSchema, uint8);
|
|
1937
|
+
case protobufs.Portnums.PortNum.TELEMETRY_APP:
|
|
1938
|
+
return fromBinary(protobufs.Telemetry.TelemetrySchema, uint8);
|
|
1939
|
+
case protobufs.Portnums.PortNum.ROUTING_APP:
|
|
1940
|
+
return fromBinary(protobufs.Mesh.RoutingSchema, uint8);
|
|
1941
|
+
case protobufs.Portnums.PortNum.ADMIN_APP:
|
|
1942
|
+
return fromBinary(protobufs.Admin.AdminMessageSchema, uint8);
|
|
1943
|
+
case protobufs.Portnums.PortNum.WAYPOINT_APP:
|
|
1944
|
+
return fromBinary(protobufs.Mesh.WaypointSchema, uint8);
|
|
1945
|
+
case protobufs.Portnums.PortNum.NEIGHBORINFO_APP:
|
|
1946
|
+
return fromBinary(protobufs.Mesh.NeighborInfoSchema, uint8);
|
|
1947
|
+
case protobufs.Portnums.PortNum.STORE_FORWARD_APP:
|
|
1948
|
+
return fromBinary(protobufs.StoreForward.StoreAndForwardSchema, uint8);
|
|
1949
|
+
case protobufs.Portnums.PortNum.RANGE_TEST_APP:
|
|
113
1950
|
return new TextDecoder("ascii").decode(uint8);
|
|
114
|
-
case protobufs.
|
|
115
|
-
return protobufs.
|
|
116
|
-
case protobufs.
|
|
1951
|
+
case protobufs.Portnums.PortNum.REMOTE_HARDWARE_APP:
|
|
1952
|
+
return fromBinary(protobufs.RemoteHardware.HardwareMessageSchema, uint8);
|
|
1953
|
+
case protobufs.Portnums.PortNum.DETECTION_SENSOR_APP:
|
|
117
1954
|
return new TextDecoder().decode(uint8);
|
|
118
|
-
case protobufs.
|
|
1955
|
+
case protobufs.Portnums.PortNum.REPLY_APP:
|
|
119
1956
|
return new TextDecoder("ascii").decode(uint8);
|
|
120
|
-
case protobufs.
|
|
121
|
-
return protobufs.
|
|
122
|
-
case protobufs.
|
|
123
|
-
return protobufs.
|
|
124
|
-
case protobufs.
|
|
125
|
-
return protobufs.
|
|
126
|
-
case protobufs.
|
|
127
|
-
case protobufs.
|
|
128
|
-
case protobufs.
|
|
129
|
-
case protobufs.
|
|
130
|
-
case protobufs.
|
|
131
|
-
case protobufs.
|
|
132
|
-
case protobufs.
|
|
133
|
-
case protobufs.
|
|
134
|
-
case protobufs.
|
|
1957
|
+
case protobufs.Portnums.PortNum.TRACEROUTE_APP:
|
|
1958
|
+
return fromBinary(protobufs.Mesh.RouteDiscoverySchema, uint8);
|
|
1959
|
+
case protobufs.Portnums.PortNum.PAXCOUNTER_APP:
|
|
1960
|
+
return fromBinary(protobufs.Paxcount.PaxcountSchema, uint8);
|
|
1961
|
+
case protobufs.Portnums.PortNum.MAP_REPORT_APP:
|
|
1962
|
+
return fromBinary(protobufs.Mqtt.MapReportSchema, uint8);
|
|
1963
|
+
case protobufs.Portnums.PortNum.UNKNOWN_APP:
|
|
1964
|
+
case protobufs.Portnums.PortNum.IP_TUNNEL_APP:
|
|
1965
|
+
case protobufs.Portnums.PortNum.SERIAL_APP:
|
|
1966
|
+
case protobufs.Portnums.PortNum.AUDIO_APP:
|
|
1967
|
+
case protobufs.Portnums.PortNum.ZPS_APP:
|
|
1968
|
+
case protobufs.Portnums.PortNum.SIMULATOR_APP:
|
|
1969
|
+
case protobufs.Portnums.PortNum.PRIVATE_APP:
|
|
1970
|
+
case protobufs.Portnums.PortNum.ATAK_FORWARDER:
|
|
1971
|
+
case protobufs.Portnums.PortNum.TEXT_MESSAGE_COMPRESSED_APP:
|
|
135
1972
|
default:
|
|
136
1973
|
return {
|
|
137
1974
|
raw: Buffer.from(uint8),
|
|
@@ -147,9 +1984,10 @@ function decodeMessageByPortNum(portNum, payload) {
|
|
|
147
1984
|
}
|
|
148
1985
|
}
|
|
149
1986
|
function getPortNumName(portNum) {
|
|
150
|
-
const name = protobufs.
|
|
1987
|
+
const name = protobufs.Portnums.PortNum[portNum];
|
|
151
1988
|
return name || `UNKNOWN(${portNum})`;
|
|
152
1989
|
}
|
|
1990
|
+
exports.BinaryWriter = BinaryWriter;
|
|
153
1991
|
exports.InvalidKeyError = InvalidKeyError;
|
|
154
1992
|
exports.InvalidNonceError = InvalidNonceError;
|
|
155
1993
|
exports.MeshtasticDecodeError = MeshtasticDecodeError;
|
|
@@ -163,4 +2001,5 @@ exports.decodeMessageByPortNum = decodeMessageByPortNum;
|
|
|
163
2001
|
exports.decodeServiceEnvelope = decodeServiceEnvelope;
|
|
164
2002
|
exports.ensureBuffer = ensureBuffer;
|
|
165
2003
|
exports.getPortNumName = getPortNumName;
|
|
2004
|
+
exports.reflect = reflect;
|
|
166
2005
|
//# sourceMappingURL=decoder.js.map
|