@bufbuild/protobuf 0.0.9 → 0.1.1
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/README.md +1 -1
- package/dist/cjs/create-registry-from-desc.js +10 -116
- package/dist/cjs/create-registry.js +1 -1
- package/dist/cjs/google/protobuf/descriptor_pb.js +2 -2
- package/dist/cjs/google/protobuf/empty_pb.js +0 -1
- package/dist/cjs/google/protobuf/struct_pb.js +1 -1
- package/dist/cjs/google/protobuf/type_pb.js +1 -1
- package/dist/cjs/google/varint.js +85 -37
- package/dist/cjs/index.js +1 -7
- package/dist/cjs/private/binary-format-proto2.js +1 -1
- package/dist/cjs/private/json-format-common.js +6 -6
- package/dist/cjs/proto-int64.js +23 -40
- package/dist/esm/create-registry-from-desc.js +9 -114
- package/dist/esm/create-registry.js +1 -1
- package/dist/esm/google/protobuf/descriptor_pb.js +2 -2
- package/dist/esm/google/protobuf/empty_pb.js +0 -1
- package/dist/esm/google/protobuf/struct_pb.js +1 -1
- package/dist/esm/google/protobuf/type_pb.js +1 -1
- package/dist/esm/google/varint.js +81 -34
- package/dist/esm/index.js +0 -3
- package/dist/esm/private/binary-format-proto2.js +1 -1
- package/dist/esm/private/json-format-common.js +6 -6
- package/dist/esm/proto-int64.js +24 -41
- package/dist/types/create-registry-from-desc.d.ts +0 -34
- package/dist/types/create-registry.d.ts +1 -1
- package/dist/types/google/protobuf/descriptor_pb.d.ts +6 -6
- package/dist/types/google/protobuf/empty_pb.d.ts +0 -1
- package/dist/types/google/varint.d.ts +21 -9
- package/dist/types/index.d.ts +0 -3
- package/dist/types/json-format.d.ts +1 -1
- package/dist/types/message.d.ts +3 -1
- package/dist/types/proto-int64.d.ts +14 -13
- package/package.json +5 -8
- package/dist/cjs/legacy-descriptor-registry.js +0 -468
- package/dist/cjs/legacy-descriptor-set.js +0 -453
- package/dist/cjs/legacy-type-registry.js +0 -104
- package/dist/esm/legacy-descriptor-registry.js +0 -464
- package/dist/esm/legacy-descriptor-set.js +0 -449
- package/dist/esm/legacy-type-registry.js +0 -100
- package/dist/types/legacy-descriptor-registry.d.ts +0 -45
- package/dist/types/legacy-descriptor-set.d.ts +0 -152
- package/dist/types/legacy-type-registry.d.ts +0 -44
|
@@ -1,464 +0,0 @@
|
|
|
1
|
-
// Copyright 2021-2022 Buf Technologies, Inc.
|
|
2
|
-
//
|
|
3
|
-
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
-
// you may not use this file except in compliance with the License.
|
|
5
|
-
// You may obtain a copy of the License at
|
|
6
|
-
//
|
|
7
|
-
// http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
-
//
|
|
9
|
-
// Unless required by applicable law or agreed to in writing, software
|
|
10
|
-
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
-
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
-
// See the License for the specific language governing permissions and
|
|
13
|
-
// limitations under the License.
|
|
14
|
-
import { FileDescriptorSet } from "./google/protobuf/descriptor_pb.js";
|
|
15
|
-
import { assert } from "./private/assert.js";
|
|
16
|
-
import { proto3 } from "./proto3.js";
|
|
17
|
-
import { proto2 } from "./proto2.js";
|
|
18
|
-
import { ScalarType } from "./field.js";
|
|
19
|
-
import { LegacyDescriptorSet } from "./legacy-descriptor-set.js";
|
|
20
|
-
import { protoInt64 } from "./proto-int64.js";
|
|
21
|
-
import { Timestamp } from "./google/protobuf/timestamp_pb.js";
|
|
22
|
-
import { Duration } from "./google/protobuf/duration_pb.js";
|
|
23
|
-
import { Any } from "./google/protobuf/any_pb.js";
|
|
24
|
-
import { Empty } from "./google/protobuf/empty_pb.js";
|
|
25
|
-
import { FieldMask } from "./google/protobuf/field_mask_pb.js";
|
|
26
|
-
import { ListValue, NullValue, Struct, Value, } from "./google/protobuf/struct_pb.js";
|
|
27
|
-
import { getEnumType } from "./private/enum.js";
|
|
28
|
-
import { BoolValue, BytesValue, DoubleValue, FloatValue, Int32Value, Int64Value, StringValue, UInt32Value, UInt64Value, } from "./google/protobuf/wrappers_pb.js";
|
|
29
|
-
// well-known message types with specialized JSON representation
|
|
30
|
-
const wkMessages = [
|
|
31
|
-
Any,
|
|
32
|
-
Duration,
|
|
33
|
-
Empty,
|
|
34
|
-
FieldMask,
|
|
35
|
-
Struct,
|
|
36
|
-
Value,
|
|
37
|
-
ListValue,
|
|
38
|
-
Timestamp,
|
|
39
|
-
Duration,
|
|
40
|
-
DoubleValue,
|
|
41
|
-
FloatValue,
|
|
42
|
-
Int64Value,
|
|
43
|
-
Int32Value,
|
|
44
|
-
UInt32Value,
|
|
45
|
-
UInt64Value,
|
|
46
|
-
BoolValue,
|
|
47
|
-
StringValue,
|
|
48
|
-
BytesValue,
|
|
49
|
-
];
|
|
50
|
-
// well-known enum types with specialized JSON representation
|
|
51
|
-
const wkEnums = [getEnumType(NullValue)];
|
|
52
|
-
/**
|
|
53
|
-
* LegacyDescriptorRegistry is a type registry that dynamically creates types
|
|
54
|
-
* from a set of google.protobuf.FileDescriptorProto.
|
|
55
|
-
*
|
|
56
|
-
* By default, all well-known types with a specialized JSON representation
|
|
57
|
-
* are replaced with their generated counterpart in this package.
|
|
58
|
-
*
|
|
59
|
-
* @deprecated
|
|
60
|
-
*/
|
|
61
|
-
export class LegacyDescriptorRegistry {
|
|
62
|
-
constructor(descriptorSet, replaceWkt = true) {
|
|
63
|
-
this.enums = {};
|
|
64
|
-
this.messages = {};
|
|
65
|
-
this.services = {};
|
|
66
|
-
this.ds = descriptorSet !== null && descriptorSet !== void 0 ? descriptorSet : new LegacyDescriptorSet();
|
|
67
|
-
if (replaceWkt) {
|
|
68
|
-
for (const mt of wkMessages) {
|
|
69
|
-
this.messages["." + mt.typeName] = mt;
|
|
70
|
-
}
|
|
71
|
-
for (const et of wkEnums) {
|
|
72
|
-
this.enums["." + et.typeName] = et;
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
/**
|
|
77
|
-
* Conveniently create a DescriptorRegistry from a FileDescriptorSet
|
|
78
|
-
* instance or a FileDescriptorSet in binary format.
|
|
79
|
-
*/
|
|
80
|
-
static fromFileDescriptorSet(bytesOrSet) {
|
|
81
|
-
const set = bytesOrSet instanceof Uint8Array
|
|
82
|
-
? FileDescriptorSet.fromBinary(bytesOrSet)
|
|
83
|
-
: new FileDescriptorSet(bytesOrSet);
|
|
84
|
-
const dr = new LegacyDescriptorRegistry();
|
|
85
|
-
dr.add(...set.file);
|
|
86
|
-
return dr;
|
|
87
|
-
}
|
|
88
|
-
/**
|
|
89
|
-
* May raise an error on invalid descriptors.
|
|
90
|
-
*/
|
|
91
|
-
add(...files) {
|
|
92
|
-
this.ds.add(...files);
|
|
93
|
-
}
|
|
94
|
-
/**
|
|
95
|
-
* May raise an error on invalid descriptors.
|
|
96
|
-
*/
|
|
97
|
-
findEnum(typeName) {
|
|
98
|
-
const protoTypeName = "." + typeName;
|
|
99
|
-
const existing = this.enums[protoTypeName];
|
|
100
|
-
if (existing) {
|
|
101
|
-
return existing;
|
|
102
|
-
}
|
|
103
|
-
const raw = this.ds.enums[protoTypeName];
|
|
104
|
-
if (!raw) {
|
|
105
|
-
return undefined;
|
|
106
|
-
}
|
|
107
|
-
const runtime = raw.file.syntax == "proto3" ? proto3 : proto2;
|
|
108
|
-
const type = runtime.makeEnumType(typeName, raw.values.map((u) => ({
|
|
109
|
-
no: u.number,
|
|
110
|
-
name: u.name,
|
|
111
|
-
localName: u.name,
|
|
112
|
-
})), {});
|
|
113
|
-
this.enums[protoTypeName] = type;
|
|
114
|
-
return type;
|
|
115
|
-
}
|
|
116
|
-
/**
|
|
117
|
-
* May raise an error on invalid descriptors.
|
|
118
|
-
*/
|
|
119
|
-
findMessage(typeName) {
|
|
120
|
-
const protoTypeName = "." + typeName;
|
|
121
|
-
const existing = this.messages[protoTypeName];
|
|
122
|
-
if (existing) {
|
|
123
|
-
return existing;
|
|
124
|
-
}
|
|
125
|
-
const raw = this.ds.messages[protoTypeName];
|
|
126
|
-
if (!raw) {
|
|
127
|
-
return undefined;
|
|
128
|
-
}
|
|
129
|
-
const runtime = raw.file.syntax == "proto3" ? proto3 : proto2;
|
|
130
|
-
const fields = [];
|
|
131
|
-
const type = runtime.makeMessageType(typeName, () => fields, {
|
|
132
|
-
localName: makeTypeLocalName(raw),
|
|
133
|
-
});
|
|
134
|
-
this.messages[protoTypeName] = type;
|
|
135
|
-
for (const field of raw.fields.map((f) => f.resolve(this.ds))) {
|
|
136
|
-
const fieldInfo = makeFieldInfo(field, this);
|
|
137
|
-
fields.push(fieldInfo);
|
|
138
|
-
}
|
|
139
|
-
return type;
|
|
140
|
-
}
|
|
141
|
-
/**
|
|
142
|
-
* May raise an error on invalid descriptors.
|
|
143
|
-
*/
|
|
144
|
-
findService(typeName) {
|
|
145
|
-
const protoTypeName = "." + typeName;
|
|
146
|
-
const existing = this.services[protoTypeName];
|
|
147
|
-
if (existing) {
|
|
148
|
-
return existing;
|
|
149
|
-
}
|
|
150
|
-
const raw = this.ds.services[protoTypeName];
|
|
151
|
-
if (!raw) {
|
|
152
|
-
return undefined;
|
|
153
|
-
}
|
|
154
|
-
const methods = {};
|
|
155
|
-
for (const u of raw.methods) {
|
|
156
|
-
const it = this.findMessage(u.inputTypeName);
|
|
157
|
-
const ot = this.findMessage(u.outputTypeName);
|
|
158
|
-
assert(it, `message "${u.inputTypeName}" for ${u.toString()} not found`);
|
|
159
|
-
assert(ot, `output message "${u.outputTypeName}" for ${u.toString()} not found`);
|
|
160
|
-
const m = {
|
|
161
|
-
name: u.name,
|
|
162
|
-
localName: localMethodName(u.name),
|
|
163
|
-
I: it,
|
|
164
|
-
O: ot,
|
|
165
|
-
kind: u.kind,
|
|
166
|
-
idempotency: u.idempotency,
|
|
167
|
-
options: {},
|
|
168
|
-
};
|
|
169
|
-
methods[m.localName] = m;
|
|
170
|
-
}
|
|
171
|
-
return (this.services[protoTypeName] = {
|
|
172
|
-
typeName: raw.typeName,
|
|
173
|
-
methods,
|
|
174
|
-
});
|
|
175
|
-
}
|
|
176
|
-
}
|
|
177
|
-
function localMethodName(protoName) {
|
|
178
|
-
if (protoName.length == 0) {
|
|
179
|
-
return protoName;
|
|
180
|
-
}
|
|
181
|
-
return protoName[0].toLowerCase() + protoName.substring(1);
|
|
182
|
-
}
|
|
183
|
-
function makeTypeLocalName(type) {
|
|
184
|
-
var _a;
|
|
185
|
-
const typeName = type.typeName;
|
|
186
|
-
const packagePrefix = ((_a = type.file.proto.package) !== null && _a !== void 0 ? _a : "") + ".";
|
|
187
|
-
if (!typeName.startsWith(packagePrefix)) {
|
|
188
|
-
return type.name;
|
|
189
|
-
}
|
|
190
|
-
return typeName.substring(packagePrefix.length).split(".").join("_");
|
|
191
|
-
}
|
|
192
|
-
function makeFieldInfo(field, resolver) {
|
|
193
|
-
if (field.map !== undefined) {
|
|
194
|
-
return makeMapFieldInfo(field, resolver);
|
|
195
|
-
}
|
|
196
|
-
if (field.message) {
|
|
197
|
-
return makeMessageFieldInfo(field, resolver);
|
|
198
|
-
}
|
|
199
|
-
const fi = field.enum
|
|
200
|
-
? makeEnumFieldInfo(field, resolver)
|
|
201
|
-
: makeScalarFieldInfo(field);
|
|
202
|
-
fi.default = parseDefaultValue(field);
|
|
203
|
-
return fi;
|
|
204
|
-
}
|
|
205
|
-
function makeMapFieldInfo(field, resolver) {
|
|
206
|
-
const base = {
|
|
207
|
-
kind: "map",
|
|
208
|
-
name: field.name,
|
|
209
|
-
no: field.number,
|
|
210
|
-
K: field.map.key,
|
|
211
|
-
};
|
|
212
|
-
if (field.map.value.message) {
|
|
213
|
-
const messageType = resolver.findMessage(field.map.value.message.typeName);
|
|
214
|
-
assert(messageType, `message "${field.map.value.message.typeName}" for ${field.toString()} not found`);
|
|
215
|
-
return Object.assign(Object.assign({}, base), { V: {
|
|
216
|
-
kind: "message",
|
|
217
|
-
T: messageType,
|
|
218
|
-
} });
|
|
219
|
-
}
|
|
220
|
-
if (field.map.value.enum) {
|
|
221
|
-
const enumType = resolver.findEnum(field.map.value.enum.typeName);
|
|
222
|
-
assert(enumType, `enum "${field.map.value.enum.typeName}" for ${field.toString()} not found`);
|
|
223
|
-
return Object.assign(Object.assign({}, base), { V: {
|
|
224
|
-
kind: "enum",
|
|
225
|
-
T: enumType,
|
|
226
|
-
} });
|
|
227
|
-
}
|
|
228
|
-
return Object.assign(Object.assign({}, base), { V: {
|
|
229
|
-
kind: "scalar",
|
|
230
|
-
T: field.map.value.scalarType,
|
|
231
|
-
} });
|
|
232
|
-
}
|
|
233
|
-
function makeScalarFieldInfo(field) {
|
|
234
|
-
const base = {
|
|
235
|
-
no: field.number,
|
|
236
|
-
name: field.name,
|
|
237
|
-
kind: "scalar",
|
|
238
|
-
T: field.scalarType,
|
|
239
|
-
};
|
|
240
|
-
if (field.repeated) {
|
|
241
|
-
return Object.assign(Object.assign({}, base), { repeated: true, packed: field.packed, oneof: undefined, T: field.scalarType });
|
|
242
|
-
}
|
|
243
|
-
if (field.oneof) {
|
|
244
|
-
return Object.assign(Object.assign({}, base), { oneof: field.oneof.name });
|
|
245
|
-
}
|
|
246
|
-
if (field.optional) {
|
|
247
|
-
return Object.assign(Object.assign({}, base), { opt: true });
|
|
248
|
-
}
|
|
249
|
-
return base;
|
|
250
|
-
}
|
|
251
|
-
function makeMessageFieldInfo(field, resolver) {
|
|
252
|
-
const messageType = resolver.findMessage(field.message.typeName);
|
|
253
|
-
assert(messageType, `message "${field.message.typeName}" for ${field.toString()} not found`);
|
|
254
|
-
const base = {
|
|
255
|
-
no: field.number,
|
|
256
|
-
name: field.name,
|
|
257
|
-
kind: "message",
|
|
258
|
-
T: messageType,
|
|
259
|
-
};
|
|
260
|
-
if (field.repeated) {
|
|
261
|
-
return Object.assign(Object.assign({}, base), { repeated: true, packed: field.packed, oneof: undefined });
|
|
262
|
-
}
|
|
263
|
-
if (field.oneof) {
|
|
264
|
-
return Object.assign(Object.assign({}, base), { oneof: field.oneof.name });
|
|
265
|
-
}
|
|
266
|
-
if (field.optional) {
|
|
267
|
-
return Object.assign(Object.assign({}, base), { opt: true });
|
|
268
|
-
}
|
|
269
|
-
return base;
|
|
270
|
-
}
|
|
271
|
-
function makeEnumFieldInfo(field, resolver) {
|
|
272
|
-
const enumType = resolver.findEnum(field.enum.typeName);
|
|
273
|
-
assert(enumType, `message "${field.enum.typeName}" for ${field.toString()} not found`);
|
|
274
|
-
const base = {
|
|
275
|
-
no: field.number,
|
|
276
|
-
name: field.name,
|
|
277
|
-
kind: "enum",
|
|
278
|
-
T: enumType,
|
|
279
|
-
};
|
|
280
|
-
if (field.repeated) {
|
|
281
|
-
return Object.assign(Object.assign({}, base), { repeated: true, packed: field.packed, oneof: undefined });
|
|
282
|
-
}
|
|
283
|
-
if (field.oneof) {
|
|
284
|
-
return Object.assign(Object.assign({}, base), { oneof: field.oneof.name });
|
|
285
|
-
}
|
|
286
|
-
if (field.optional) {
|
|
287
|
-
return Object.assign(Object.assign({}, base), { opt: true });
|
|
288
|
-
}
|
|
289
|
-
return base;
|
|
290
|
-
}
|
|
291
|
-
function parseDefaultValue(field) {
|
|
292
|
-
const d = field.proto.defaultValue;
|
|
293
|
-
if (d === undefined) {
|
|
294
|
-
return undefined;
|
|
295
|
-
}
|
|
296
|
-
if (field.enum) {
|
|
297
|
-
const enumValue = field.enum.values.find((v) => v.name === d);
|
|
298
|
-
assert(enumValue, `cannot parse ${field.toString()} default value: ${d}`);
|
|
299
|
-
return enumValue.number;
|
|
300
|
-
}
|
|
301
|
-
if (field.scalarType) {
|
|
302
|
-
switch (field.scalarType) {
|
|
303
|
-
case ScalarType.STRING:
|
|
304
|
-
return d;
|
|
305
|
-
case ScalarType.BYTES: {
|
|
306
|
-
const u = unescapeBytesDefaultValue(d);
|
|
307
|
-
if (u === false) {
|
|
308
|
-
throw new Error(`cannot parse ${field.toString()} default value: ${d}`);
|
|
309
|
-
}
|
|
310
|
-
return u;
|
|
311
|
-
}
|
|
312
|
-
case ScalarType.INT64:
|
|
313
|
-
case ScalarType.SFIXED64:
|
|
314
|
-
case ScalarType.SINT64:
|
|
315
|
-
return protoInt64.parse(d);
|
|
316
|
-
case ScalarType.UINT64:
|
|
317
|
-
case ScalarType.FIXED64:
|
|
318
|
-
return protoInt64.uParse(d);
|
|
319
|
-
case ScalarType.DOUBLE:
|
|
320
|
-
case ScalarType.FLOAT:
|
|
321
|
-
switch (d) {
|
|
322
|
-
case "inf":
|
|
323
|
-
return Number.POSITIVE_INFINITY;
|
|
324
|
-
case "-inf":
|
|
325
|
-
return Number.NEGATIVE_INFINITY;
|
|
326
|
-
case "nan":
|
|
327
|
-
return Number.NaN;
|
|
328
|
-
default:
|
|
329
|
-
return parseFloat(d);
|
|
330
|
-
}
|
|
331
|
-
case ScalarType.BOOL:
|
|
332
|
-
return Boolean(d);
|
|
333
|
-
case ScalarType.INT32:
|
|
334
|
-
case ScalarType.UINT32:
|
|
335
|
-
case ScalarType.SINT32:
|
|
336
|
-
case ScalarType.FIXED32:
|
|
337
|
-
case ScalarType.SFIXED32:
|
|
338
|
-
return parseInt(d, 10);
|
|
339
|
-
}
|
|
340
|
-
}
|
|
341
|
-
return undefined;
|
|
342
|
-
}
|
|
343
|
-
// unescapeBytesDefaultValue parses a text-encoded default value (proto2) of a
|
|
344
|
-
// BYTES field.
|
|
345
|
-
function unescapeBytesDefaultValue(str) {
|
|
346
|
-
const b = [];
|
|
347
|
-
const input = {
|
|
348
|
-
tail: str,
|
|
349
|
-
c: "",
|
|
350
|
-
next() {
|
|
351
|
-
if (this.tail.length == 0) {
|
|
352
|
-
return false;
|
|
353
|
-
}
|
|
354
|
-
this.c = this.tail[0];
|
|
355
|
-
this.tail = this.tail.substring(1);
|
|
356
|
-
return true;
|
|
357
|
-
},
|
|
358
|
-
take(n) {
|
|
359
|
-
if (this.tail.length >= n) {
|
|
360
|
-
const r = this.tail.substring(0, n);
|
|
361
|
-
this.tail = this.tail.substring(n);
|
|
362
|
-
return r;
|
|
363
|
-
}
|
|
364
|
-
return false;
|
|
365
|
-
},
|
|
366
|
-
};
|
|
367
|
-
while (input.next()) {
|
|
368
|
-
switch (input.c) {
|
|
369
|
-
case "\\":
|
|
370
|
-
if (input.next()) {
|
|
371
|
-
switch (input.c) {
|
|
372
|
-
case "\\":
|
|
373
|
-
b.push(input.c.charCodeAt(0));
|
|
374
|
-
break;
|
|
375
|
-
case "b":
|
|
376
|
-
b.push(0x08);
|
|
377
|
-
break;
|
|
378
|
-
case "f":
|
|
379
|
-
b.push(0x0c);
|
|
380
|
-
break;
|
|
381
|
-
case "n":
|
|
382
|
-
b.push(0x0a);
|
|
383
|
-
break;
|
|
384
|
-
case "r":
|
|
385
|
-
b.push(0x0d);
|
|
386
|
-
break;
|
|
387
|
-
case "t":
|
|
388
|
-
b.push(0x09);
|
|
389
|
-
break;
|
|
390
|
-
case "v":
|
|
391
|
-
b.push(0x0b);
|
|
392
|
-
break;
|
|
393
|
-
case "0":
|
|
394
|
-
case "1":
|
|
395
|
-
case "2":
|
|
396
|
-
case "3":
|
|
397
|
-
case "4":
|
|
398
|
-
case "5":
|
|
399
|
-
case "6":
|
|
400
|
-
case "7": {
|
|
401
|
-
const s = input.c;
|
|
402
|
-
const t = input.take(2);
|
|
403
|
-
if (t === false) {
|
|
404
|
-
return false;
|
|
405
|
-
}
|
|
406
|
-
const n = parseInt(s + t, 8);
|
|
407
|
-
if (isNaN(n)) {
|
|
408
|
-
return false;
|
|
409
|
-
}
|
|
410
|
-
b.push(n);
|
|
411
|
-
break;
|
|
412
|
-
}
|
|
413
|
-
case "x": {
|
|
414
|
-
const s = input.c;
|
|
415
|
-
const t = input.take(2);
|
|
416
|
-
if (t === false) {
|
|
417
|
-
return false;
|
|
418
|
-
}
|
|
419
|
-
const n = parseInt(s + t, 16);
|
|
420
|
-
if (isNaN(n)) {
|
|
421
|
-
return false;
|
|
422
|
-
}
|
|
423
|
-
b.push(n);
|
|
424
|
-
break;
|
|
425
|
-
}
|
|
426
|
-
case "u": {
|
|
427
|
-
const s = input.c;
|
|
428
|
-
const t = input.take(4);
|
|
429
|
-
if (t === false) {
|
|
430
|
-
return false;
|
|
431
|
-
}
|
|
432
|
-
const n = parseInt(s + t, 16);
|
|
433
|
-
if (isNaN(n)) {
|
|
434
|
-
return false;
|
|
435
|
-
}
|
|
436
|
-
const chunk = new Uint8Array(4);
|
|
437
|
-
const view = new DataView(chunk.buffer);
|
|
438
|
-
view.setInt32(0, n, true);
|
|
439
|
-
b.push(chunk[0], chunk[1], chunk[2], chunk[3]);
|
|
440
|
-
break;
|
|
441
|
-
}
|
|
442
|
-
case "U": {
|
|
443
|
-
const s = input.c;
|
|
444
|
-
const t = input.take(8);
|
|
445
|
-
if (t === false) {
|
|
446
|
-
return false;
|
|
447
|
-
}
|
|
448
|
-
const tc = protoInt64.uEnc(s + t);
|
|
449
|
-
const chunk = new Uint8Array(8);
|
|
450
|
-
const view = new DataView(chunk.buffer);
|
|
451
|
-
view.setInt32(0, tc.lo, true);
|
|
452
|
-
view.setInt32(4, tc.hi, true);
|
|
453
|
-
b.push(chunk[0], chunk[1], chunk[2], chunk[3], chunk[4], chunk[5], chunk[6], chunk[7]);
|
|
454
|
-
break;
|
|
455
|
-
}
|
|
456
|
-
}
|
|
457
|
-
}
|
|
458
|
-
break;
|
|
459
|
-
default:
|
|
460
|
-
b.push(input.c.charCodeAt(0));
|
|
461
|
-
}
|
|
462
|
-
}
|
|
463
|
-
return new Uint8Array(b);
|
|
464
|
-
}
|