@bufbuild/protobuf 0.0.1-alpha.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.
Files changed (146) hide show
  1. package/README.md +6 -0
  2. package/dist/cjs/binary-encoding.js +434 -0
  3. package/dist/cjs/binary-format.js +2 -0
  4. package/dist/cjs/descriptor-registry.js +518 -0
  5. package/dist/cjs/descriptor-set.js +557 -0
  6. package/dist/cjs/enum.js +2 -0
  7. package/dist/cjs/field-list.js +2 -0
  8. package/dist/cjs/field.js +40 -0
  9. package/dist/cjs/google/protobuf/any_pb.js +280 -0
  10. package/dist/cjs/google/protobuf/api_pb.js +383 -0
  11. package/dist/cjs/google/protobuf/compiler/plugin_pb.js +334 -0
  12. package/dist/cjs/google/protobuf/descriptor_pb.js +2311 -0
  13. package/dist/cjs/google/protobuf/duration_pb.js +201 -0
  14. package/dist/cjs/google/protobuf/empty_pb.js +72 -0
  15. package/dist/cjs/google/protobuf/field_mask_pb.js +347 -0
  16. package/dist/cjs/google/protobuf/source_context_pb.js +74 -0
  17. package/dist/cjs/google/protobuf/struct_pb.js +288 -0
  18. package/dist/cjs/google/protobuf/timestamp_pb.js +271 -0
  19. package/dist/cjs/google/protobuf/type_pb.js +613 -0
  20. package/dist/cjs/google/protobuf/wrappers_pb.js +658 -0
  21. package/dist/cjs/google/varint.js +280 -0
  22. package/dist/cjs/index.js +148 -0
  23. package/dist/cjs/json-format.js +2 -0
  24. package/dist/cjs/message-type.js +2 -0
  25. package/dist/cjs/message.js +98 -0
  26. package/dist/cjs/private/assert.js +52 -0
  27. package/dist/cjs/private/base64.js +118 -0
  28. package/dist/cjs/private/binary-format-common.js +253 -0
  29. package/dist/cjs/private/binary-format-proto2.js +120 -0
  30. package/dist/cjs/private/binary-format-proto3.js +102 -0
  31. package/dist/cjs/private/enum.js +70 -0
  32. package/dist/cjs/private/field-list.js +62 -0
  33. package/dist/cjs/private/field-wrapper.js +25 -0
  34. package/dist/cjs/private/field.js +34 -0
  35. package/dist/cjs/private/json-format-common.js +482 -0
  36. package/dist/cjs/private/json-format-proto2.js +100 -0
  37. package/dist/cjs/private/json-format-proto3.js +103 -0
  38. package/dist/cjs/private/message-type.js +37 -0
  39. package/dist/cjs/private/names.js +101 -0
  40. package/dist/cjs/private/options-map.js +2 -0
  41. package/dist/cjs/private/proto-runtime.js +24 -0
  42. package/dist/cjs/private/scalars.js +138 -0
  43. package/dist/cjs/private/util-common.js +229 -0
  44. package/dist/cjs/private/util.js +2 -0
  45. package/dist/cjs/proto-int64.js +121 -0
  46. package/dist/cjs/proto2.js +86 -0
  47. package/dist/cjs/proto3.js +99 -0
  48. package/dist/cjs/service-type.js +43 -0
  49. package/dist/cjs/type-registry.js +42 -0
  50. package/dist/esm/binary-encoding.js +434 -0
  51. package/dist/esm/binary-format.js +1 -0
  52. package/dist/esm/descriptor-registry.js +521 -0
  53. package/dist/esm/descriptor-set.js +517 -0
  54. package/dist/esm/enum.js +1 -0
  55. package/dist/esm/field-list.js +1 -0
  56. package/dist/esm/field.js +37 -0
  57. package/dist/esm/google/protobuf/any_pb.js +276 -0
  58. package/dist/esm/google/protobuf/api_pb.js +350 -0
  59. package/dist/esm/google/protobuf/compiler/plugin_pb.js +318 -0
  60. package/dist/esm/google/protobuf/descriptor_pb.js +2213 -0
  61. package/dist/esm/google/protobuf/duration_pb.js +197 -0
  62. package/dist/esm/google/protobuf/empty_pb.js +68 -0
  63. package/dist/esm/google/protobuf/field_mask_pb.js +343 -0
  64. package/dist/esm/google/protobuf/source_context_pb.js +70 -0
  65. package/dist/esm/google/protobuf/struct_pb.js +282 -0
  66. package/dist/esm/google/protobuf/timestamp_pb.js +267 -0
  67. package/dist/esm/google/protobuf/type_pb.js +569 -0
  68. package/dist/esm/google/protobuf/wrappers_pb.js +574 -0
  69. package/dist/esm/google/varint.js +265 -0
  70. package/dist/esm/index.js +24 -0
  71. package/dist/esm/json-format.js +1 -0
  72. package/dist/esm/message-type.js +1 -0
  73. package/dist/esm/message.js +94 -0
  74. package/dist/esm/private/assert.js +41 -0
  75. package/dist/esm/private/base64.js +113 -0
  76. package/dist/esm/private/binary-format-common.js +243 -0
  77. package/dist/esm/private/binary-format-proto2.js +87 -0
  78. package/dist/esm/private/binary-format-proto3.js +74 -0
  79. package/dist/esm/private/enum.js +64 -0
  80. package/dist/esm/private/field-list.js +58 -0
  81. package/dist/esm/private/field-wrapper.js +20 -0
  82. package/dist/esm/private/field.js +27 -0
  83. package/dist/esm/private/json-format-common.js +473 -0
  84. package/dist/esm/private/json-format-proto2.js +90 -0
  85. package/dist/esm/private/json-format-proto3.js +89 -0
  86. package/dist/esm/private/message-type.js +33 -0
  87. package/dist/esm/private/names.js +90 -0
  88. package/dist/esm/private/options-map.js +1 -0
  89. package/dist/esm/private/proto-runtime.js +15 -0
  90. package/dist/esm/private/scalars.js +129 -0
  91. package/dist/esm/private/util-common.js +207 -0
  92. package/dist/esm/private/util.js +1 -0
  93. package/dist/esm/proto-int64.js +118 -0
  94. package/dist/esm/proto2.js +77 -0
  95. package/dist/esm/proto3.js +90 -0
  96. package/dist/esm/service-type.js +37 -0
  97. package/dist/esm/type-registry.js +38 -0
  98. package/dist/types/binary-encoding.d.ts +421 -0
  99. package/dist/types/binary-format.d.ts +109 -0
  100. package/dist/types/descriptor-registry.d.ts +42 -0
  101. package/dist/types/descriptor-set.d.ts +171 -0
  102. package/dist/types/enum.d.ts +31 -0
  103. package/dist/types/field-list.d.ts +27 -0
  104. package/dist/types/field.d.ts +295 -0
  105. package/dist/types/google/protobuf/any_pb.d.ts +167 -0
  106. package/dist/types/google/protobuf/api_pb.d.ts +296 -0
  107. package/dist/types/google/protobuf/compiler/plugin_pb.d.ts +294 -0
  108. package/dist/types/google/protobuf/descriptor_pb.d.ts +1959 -0
  109. package/dist/types/google/protobuf/duration_pb.d.ts +117 -0
  110. package/dist/types/google/protobuf/empty_pb.d.ts +44 -0
  111. package/dist/types/google/protobuf/field_mask_pb.d.ts +243 -0
  112. package/dist/types/google/protobuf/source_context_pb.d.ts +44 -0
  113. package/dist/types/google/protobuf/struct_pb.d.ts +205 -0
  114. package/dist/types/google/protobuf/timestamp_pb.d.ts +151 -0
  115. package/dist/types/google/protobuf/type_pb.d.ts +482 -0
  116. package/dist/types/google/protobuf/wrappers_pb.d.ts +379 -0
  117. package/dist/types/google/varint.d.ts +65 -0
  118. package/dist/types/index.d.ts +53 -0
  119. package/dist/types/json-format.d.ts +129 -0
  120. package/dist/types/message-type.d.ts +58 -0
  121. package/dist/types/message.d.ts +124 -0
  122. package/dist/types/private/assert.d.ts +19 -0
  123. package/dist/types/private/base64.d.ts +18 -0
  124. package/dist/types/private/binary-format-common.d.ts +38 -0
  125. package/dist/types/private/binary-format-proto2.d.ts +2 -0
  126. package/dist/types/private/binary-format-proto3.d.ts +2 -0
  127. package/dist/types/private/enum.d.ts +29 -0
  128. package/dist/types/private/field-list.d.ts +25 -0
  129. package/dist/types/private/field-wrapper.d.ts +27 -0
  130. package/dist/types/private/field.d.ts +15 -0
  131. package/dist/types/private/json-format-common.d.ts +30 -0
  132. package/dist/types/private/json-format-proto2.d.ts +2 -0
  133. package/dist/types/private/json-format-proto3.d.ts +2 -0
  134. package/dist/types/private/message-type.d.ts +15 -0
  135. package/dist/types/private/names.d.ts +19 -0
  136. package/dist/types/private/options-map.d.ts +7 -0
  137. package/dist/types/private/proto-runtime.d.ts +55 -0
  138. package/dist/types/private/scalars.d.ts +33 -0
  139. package/dist/types/private/util-common.d.ts +5 -0
  140. package/dist/types/private/util.d.ts +55 -0
  141. package/dist/types/proto-int64.d.ts +94 -0
  142. package/dist/types/proto2.d.ts +4 -0
  143. package/dist/types/proto3.d.ts +4 -0
  144. package/dist/types/service-type.d.ts +118 -0
  145. package/dist/types/type-registry.d.ts +37 -0
  146. package/package.json +31 -0
@@ -0,0 +1,518 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.DescriptorRegistry = void 0;
4
+ const assert_js_1 = require("./private/assert.js");
5
+ const proto3_js_1 = require("./proto3.js");
6
+ const proto2_js_1 = require("./proto2.js");
7
+ const field_js_1 = require("./field.js");
8
+ const descriptor_set_js_1 = require("./descriptor-set.js");
9
+ const proto_int64_js_1 = require("./proto-int64.js");
10
+ const names_js_1 = require("./private/names.js");
11
+ const timestamp_pb_js_1 = require("./google/protobuf/timestamp_pb.js");
12
+ const duration_pb_js_1 = require("./google/protobuf/duration_pb.js");
13
+ const any_pb_js_1 = require("./google/protobuf/any_pb.js");
14
+ const empty_pb_js_1 = require("./google/protobuf/empty_pb.js");
15
+ const field_mask_pb_js_1 = require("./google/protobuf/field_mask_pb.js");
16
+ const struct_pb_js_1 = require("./google/protobuf/struct_pb.js");
17
+ const enum_js_1 = require("./private/enum.js");
18
+ const wrappers_pb_js_1 = require("./google/protobuf/wrappers_pb.js");
19
+ // well-known message types with specialized JSON representation
20
+ const wkMessages = [
21
+ any_pb_js_1.Any,
22
+ duration_pb_js_1.Duration,
23
+ empty_pb_js_1.Empty,
24
+ field_mask_pb_js_1.FieldMask,
25
+ struct_pb_js_1.Struct,
26
+ struct_pb_js_1.Value,
27
+ struct_pb_js_1.ListValue,
28
+ timestamp_pb_js_1.Timestamp,
29
+ duration_pb_js_1.Duration,
30
+ wrappers_pb_js_1.DoubleValue,
31
+ wrappers_pb_js_1.FloatValue,
32
+ wrappers_pb_js_1.Int64Value,
33
+ wrappers_pb_js_1.Int32Value,
34
+ wrappers_pb_js_1.UInt32Value,
35
+ wrappers_pb_js_1.UInt64Value,
36
+ wrappers_pb_js_1.BoolValue,
37
+ wrappers_pb_js_1.StringValue,
38
+ wrappers_pb_js_1.BytesValue,
39
+ ];
40
+ // well-known enum types with specialized JSON representation
41
+ const wkEnums = [(0, enum_js_1.getEnumType)(struct_pb_js_1.NullValue)];
42
+ /**
43
+ * DescriptorRegistry is a type registry that dynamically creates types
44
+ * from a set of google.protobuf.FileDescriptorProto.
45
+ *
46
+ * By default, all well-known types with a specialized JSON representation
47
+ * are replaced with their generated counterpart in this package.
48
+ */
49
+ class DescriptorRegistry {
50
+ constructor(descriptorSet, replaceWkt = true) {
51
+ this.enums = {};
52
+ this.messages = {};
53
+ this.services = {};
54
+ this.ds = descriptorSet ?? new descriptor_set_js_1.DescriptorSet();
55
+ if (replaceWkt) {
56
+ for (const mt of wkMessages) {
57
+ this.messages["." + mt.typeName] = mt;
58
+ }
59
+ for (const et of wkEnums) {
60
+ this.enums["." + et.typeName] = et;
61
+ }
62
+ }
63
+ }
64
+ /**
65
+ * May raise an error on invalid descriptors.
66
+ */
67
+ add(...files) {
68
+ this.ds.add(...files);
69
+ }
70
+ /**
71
+ * May raise an error on invalid descriptors.
72
+ */
73
+ findEnum(typeName) {
74
+ const protoTypeName = "." + typeName;
75
+ const existing = this.enums[protoTypeName];
76
+ if (existing) {
77
+ return existing;
78
+ }
79
+ const raw = this.ds.enums[protoTypeName];
80
+ if (!raw) {
81
+ return undefined;
82
+ }
83
+ const runtime =
84
+ raw.file.syntax == "proto3" ? proto3_js_1.proto3 : proto2_js_1.proto2;
85
+ const type = runtime.makeEnumType(
86
+ typeName,
87
+ raw.values.map((u) => ({
88
+ no: u.number,
89
+ name: u.name,
90
+ })),
91
+ {}
92
+ );
93
+ this.enums[protoTypeName] = type;
94
+ return type;
95
+ }
96
+ /**
97
+ * May raise an error on invalid descriptors.
98
+ */
99
+ findMessage(typeName) {
100
+ const protoTypeName = "." + typeName;
101
+ const existing = this.messages[protoTypeName];
102
+ if (existing) {
103
+ return existing;
104
+ }
105
+ const raw = this.ds.messages[protoTypeName];
106
+ if (!raw) {
107
+ return undefined;
108
+ }
109
+ const runtime =
110
+ raw.file.syntax == "proto3" ? proto3_js_1.proto3 : proto2_js_1.proto2;
111
+ const fields = [];
112
+ const type = runtime.makeMessageType(typeName, () => fields, {
113
+ localName: makeTypeLocalName(raw),
114
+ });
115
+ this.messages[protoTypeName] = type;
116
+ for (const field of raw.fields.map((f) => f.resolve(this.ds))) {
117
+ const fieldInfo = makeFieldInfo(field, this);
118
+ fields.push(fieldInfo);
119
+ }
120
+ return type;
121
+ }
122
+ /**
123
+ * May raise an error on invalid descriptors.
124
+ */
125
+ findService(typeName) {
126
+ const protoTypeName = "." + typeName;
127
+ const existing = this.services[protoTypeName];
128
+ if (existing) {
129
+ return existing;
130
+ }
131
+ const raw = this.ds.services[protoTypeName];
132
+ if (!raw) {
133
+ return undefined;
134
+ }
135
+ const methods = {};
136
+ for (const u of raw.methods) {
137
+ const it = this.findMessage(u.inputTypeName);
138
+ const ot = this.findMessage(u.outputTypeName);
139
+ (0, assert_js_1.assert)(
140
+ it,
141
+ `message "${u.inputTypeName}" for ${u.toString()} not found`
142
+ );
143
+ (0, assert_js_1.assert)(
144
+ ot,
145
+ `output message "${u.outputTypeName}" for ${u.toString()} not found`
146
+ );
147
+ const m = {
148
+ name: u.name,
149
+ localName: (0, names_js_1.makeMethodName)(u.name),
150
+ I: it,
151
+ O: ot,
152
+ kind: u.kind,
153
+ idempotency: u.idempotency,
154
+ options: {},
155
+ };
156
+ methods[m.localName] = m;
157
+ }
158
+ return (this.services[protoTypeName] = {
159
+ typeName: raw.typeName,
160
+ methods,
161
+ });
162
+ }
163
+ }
164
+ exports.DescriptorRegistry = DescriptorRegistry;
165
+ function makeTypeLocalName(type) {
166
+ const typeName = type.typeName;
167
+ const packagePrefix = (type.file.proto.package ?? "") + ".";
168
+ if (!typeName.startsWith(packagePrefix)) {
169
+ return type.name;
170
+ }
171
+ return typeName.substring(packagePrefix.length).split(".").join("_");
172
+ }
173
+ function makeFieldInfo(field, resolver) {
174
+ if (field.map !== undefined) {
175
+ return makeMapFieldInfo(field, resolver);
176
+ }
177
+ if (field.message) {
178
+ return makeMessageFieldInfo(field, resolver);
179
+ }
180
+ const fi = field.enum
181
+ ? makeEnumFieldInfo(field, resolver)
182
+ : makeScalarFieldInfo(field);
183
+ fi.default = parseDefaultValue(field);
184
+ return fi;
185
+ }
186
+ function makeMapFieldInfo(field, resolver) {
187
+ const base = {
188
+ kind: "map",
189
+ name: field.name,
190
+ no: field.number,
191
+ K: field.map.key,
192
+ };
193
+ if (field.map.value.message) {
194
+ const messageType = resolver.findMessage(field.map.value.message.typeName);
195
+ (0, assert_js_1.assert)(
196
+ messageType,
197
+ `message "${
198
+ field.map.value.message.typeName
199
+ }" for ${field.toString()} not found`
200
+ );
201
+ return {
202
+ ...base,
203
+ V: {
204
+ kind: "message",
205
+ T: messageType,
206
+ },
207
+ };
208
+ }
209
+ if (field.map.value.enum) {
210
+ const enumType = resolver.findEnum(field.map.value.enum.typeName);
211
+ (0, assert_js_1.assert)(
212
+ enumType,
213
+ `enum "${
214
+ field.map.value.enum.typeName
215
+ }" for ${field.toString()} not found`
216
+ );
217
+ return {
218
+ ...base,
219
+ V: {
220
+ kind: "enum",
221
+ T: enumType,
222
+ },
223
+ };
224
+ }
225
+ return {
226
+ ...base,
227
+ V: {
228
+ kind: "scalar",
229
+ T: field.map.value.scalarType,
230
+ },
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 {
242
+ ...base,
243
+ repeated: true,
244
+ packed: field.packed,
245
+ oneof: undefined,
246
+ T: field.scalarType,
247
+ };
248
+ }
249
+ if (field.oneof) {
250
+ return {
251
+ ...base,
252
+ oneof: field.oneof.name,
253
+ };
254
+ }
255
+ if (field.optional) {
256
+ return {
257
+ ...base,
258
+ opt: true,
259
+ };
260
+ }
261
+ return base;
262
+ }
263
+ function makeMessageFieldInfo(field, resolver) {
264
+ const messageType = resolver.findMessage(field.message.typeName);
265
+ (0, assert_js_1.assert)(
266
+ messageType,
267
+ `message "${field.message.typeName}" for ${field.toString()} not found`
268
+ );
269
+ const base = {
270
+ no: field.number,
271
+ name: field.name,
272
+ kind: "message",
273
+ T: messageType,
274
+ };
275
+ if (field.repeated) {
276
+ return {
277
+ ...base,
278
+ repeated: true,
279
+ packed: field.packed,
280
+ oneof: undefined,
281
+ };
282
+ }
283
+ if (field.oneof) {
284
+ return {
285
+ ...base,
286
+ oneof: field.oneof.name,
287
+ };
288
+ }
289
+ if (field.optional) {
290
+ return {
291
+ ...base,
292
+ opt: true,
293
+ };
294
+ }
295
+ return base;
296
+ }
297
+ function makeEnumFieldInfo(field, resolver) {
298
+ const enumType = resolver.findEnum(field.enum.typeName);
299
+ (0, assert_js_1.assert)(
300
+ enumType,
301
+ `message "${field.enum.typeName}" for ${field.toString()} not found`
302
+ );
303
+ const base = {
304
+ no: field.number,
305
+ name: field.name,
306
+ kind: "enum",
307
+ T: enumType,
308
+ };
309
+ if (field.repeated) {
310
+ return {
311
+ ...base,
312
+ repeated: true,
313
+ packed: field.packed,
314
+ oneof: undefined,
315
+ };
316
+ }
317
+ if (field.oneof) {
318
+ return {
319
+ ...base,
320
+ oneof: field.oneof.name,
321
+ };
322
+ }
323
+ if (field.optional) {
324
+ return {
325
+ ...base,
326
+ opt: true,
327
+ };
328
+ }
329
+ return base;
330
+ }
331
+ function parseDefaultValue(field) {
332
+ const d = field.proto.defaultValue;
333
+ if (d === undefined) {
334
+ return undefined;
335
+ }
336
+ if (field.enum) {
337
+ const enumValue = field.enum.values.find((v) => v.name === d);
338
+ (0, assert_js_1.assert)(
339
+ enumValue,
340
+ `cannot parse ${field.toString()} default value: ${d}`
341
+ );
342
+ return enumValue.number;
343
+ }
344
+ if (field.scalarType) {
345
+ switch (field.scalarType) {
346
+ case field_js_1.ScalarType.STRING:
347
+ return d;
348
+ case field_js_1.ScalarType.BYTES: {
349
+ const u = unescapeBytesDefaultValue(d);
350
+ if (u === false) {
351
+ throw new Error(
352
+ `cannot parse ${field.toString()} default value: ${d}`
353
+ );
354
+ }
355
+ return u;
356
+ }
357
+ case field_js_1.ScalarType.INT64:
358
+ case field_js_1.ScalarType.SFIXED64:
359
+ case field_js_1.ScalarType.SINT64:
360
+ return proto_int64_js_1.protoInt64.parse(d);
361
+ case field_js_1.ScalarType.UINT64:
362
+ case field_js_1.ScalarType.FIXED64:
363
+ return proto_int64_js_1.protoInt64.uParse(d);
364
+ case field_js_1.ScalarType.DOUBLE:
365
+ case field_js_1.ScalarType.FLOAT:
366
+ switch (d) {
367
+ case "inf":
368
+ return Number.POSITIVE_INFINITY;
369
+ case "-inf":
370
+ return Number.NEGATIVE_INFINITY;
371
+ case "nan":
372
+ return Number.NaN;
373
+ default:
374
+ return parseFloat(d);
375
+ }
376
+ case field_js_1.ScalarType.BOOL:
377
+ return Boolean(d);
378
+ case field_js_1.ScalarType.INT32:
379
+ case field_js_1.ScalarType.UINT32:
380
+ case field_js_1.ScalarType.SINT32:
381
+ case field_js_1.ScalarType.FIXED32:
382
+ case field_js_1.ScalarType.SFIXED32:
383
+ return parseInt(d, 10);
384
+ }
385
+ }
386
+ return undefined;
387
+ }
388
+ // unescapeBytesDefaultValue parses a text-encoded default value (proto2) of a
389
+ // BYTES field.
390
+ function unescapeBytesDefaultValue(str) {
391
+ const b = [];
392
+ const input = {
393
+ tail: str,
394
+ c: "",
395
+ next() {
396
+ if (this.tail.length == 0) {
397
+ return false;
398
+ }
399
+ this.c = this.tail[0];
400
+ this.tail = this.tail.substring(1);
401
+ return true;
402
+ },
403
+ take(n) {
404
+ if (this.tail.length >= n) {
405
+ const r = this.tail.substring(0, n);
406
+ this.tail = this.tail.substring(n);
407
+ return r;
408
+ }
409
+ return false;
410
+ },
411
+ };
412
+ while (input.next()) {
413
+ switch (input.c) {
414
+ case "\\":
415
+ if (input.next()) {
416
+ switch (input.c) {
417
+ case "\\":
418
+ b.push(input.c.charCodeAt(0));
419
+ break;
420
+ case "b":
421
+ b.push(0x08);
422
+ break;
423
+ case "f":
424
+ b.push(0x0c);
425
+ break;
426
+ case "n":
427
+ b.push(0x0a);
428
+ break;
429
+ case "r":
430
+ b.push(0x0d);
431
+ break;
432
+ case "t":
433
+ b.push(0x09);
434
+ break;
435
+ case "v":
436
+ b.push(0x0b);
437
+ break;
438
+ case "0":
439
+ case "1":
440
+ case "2":
441
+ case "3":
442
+ case "4":
443
+ case "5":
444
+ case "6":
445
+ case "7": {
446
+ const s = input.c;
447
+ const t = input.take(2);
448
+ if (t === false) {
449
+ return false;
450
+ }
451
+ const n = parseInt(s + t, 8);
452
+ if (isNaN(n)) {
453
+ return false;
454
+ }
455
+ b.push(n);
456
+ break;
457
+ }
458
+ case "x": {
459
+ const s = input.c;
460
+ const t = input.take(2);
461
+ if (t === false) {
462
+ return false;
463
+ }
464
+ const n = parseInt(s + t, 16);
465
+ if (isNaN(n)) {
466
+ return false;
467
+ }
468
+ b.push(n);
469
+ break;
470
+ }
471
+ case "u": {
472
+ const s = input.c;
473
+ const t = input.take(4);
474
+ if (t === false) {
475
+ return false;
476
+ }
477
+ const n = parseInt(s + t, 16);
478
+ if (isNaN(n)) {
479
+ return false;
480
+ }
481
+ const chunk = new Uint8Array(4);
482
+ const view = new DataView(chunk.buffer);
483
+ view.setInt32(0, n, true);
484
+ b.push(chunk[0], chunk[1], chunk[2], chunk[3]);
485
+ break;
486
+ }
487
+ case "U": {
488
+ const s = input.c;
489
+ const t = input.take(8);
490
+ if (t === false) {
491
+ return false;
492
+ }
493
+ const tc = proto_int64_js_1.protoInt64.uEnc(s + t);
494
+ const chunk = new Uint8Array(8);
495
+ const view = new DataView(chunk.buffer);
496
+ view.setInt32(0, tc.lo, true);
497
+ view.setInt32(4, tc.hi, true);
498
+ b.push(
499
+ chunk[0],
500
+ chunk[1],
501
+ chunk[2],
502
+ chunk[3],
503
+ chunk[4],
504
+ chunk[5],
505
+ chunk[6],
506
+ chunk[7]
507
+ );
508
+ break;
509
+ }
510
+ }
511
+ }
512
+ break;
513
+ default:
514
+ b.push(input.c.charCodeAt(0));
515
+ }
516
+ }
517
+ return new Uint8Array(b);
518
+ }