protobufjs 8.7.0 → 8.7.2
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 +62 -85
- package/dist/light/protobuf.js +80 -54
- package/dist/light/protobuf.js.map +1 -1
- package/dist/light/protobuf.min.js +3 -3
- package/dist/light/protobuf.min.js.map +1 -1
- package/dist/minimal/protobuf.js +59 -47
- package/dist/minimal/protobuf.js.map +1 -1
- package/dist/minimal/protobuf.min.js +3 -3
- package/dist/minimal/protobuf.min.js.map +1 -1
- package/dist/protobuf.js +162 -99
- package/dist/protobuf.js.map +1 -1
- package/dist/protobuf.min.js +3 -3
- package/dist/protobuf.min.js.map +1 -1
- package/ext/descriptor.js +26 -10
- package/ext/protojson.js +5 -1
- package/google/api/annotations.json +3 -1
- package/google/api/http.json +2 -1
- package/google/protobuf/api.json +12 -6
- package/google/protobuf/descriptor.json +170 -87
- package/google/protobuf/descriptor.proto +0 -8
- package/google/protobuf/source_context.json +2 -1
- package/google/protobuf/type.json +14 -7
- package/index.d.ts +3 -0
- package/package.json +4 -4
- package/src/common.js +12 -6
- package/src/converter.js +6 -2
- package/src/decoder.js +1 -1
- package/src/enum.js +5 -2
- package/src/field.js +6 -1
- package/src/index-minimal.js +1 -0
- package/src/parse.js +70 -39
- package/src/reader.js +36 -9
- package/src/util/codegen.js +3 -1
- package/src/util/longbits.js +10 -6
- package/src/util/utf8.js +2 -28
- package/src/writer.js +7 -1
package/README.md
CHANGED
|
@@ -7,15 +7,13 @@
|
|
|
7
7
|
<a href="https://www.jsdelivr.com/package/npm/protobufjs"><img src="https://img.shields.io/jsdelivr/npm/hm/protobufjs?label=requests&logo=jsdelivr" alt=""></a>
|
|
8
8
|
</p>
|
|
9
9
|
|
|
10
|
-
**
|
|
11
|
-
|
|
12
|
-
**protobuf.js** is a very fast, conformant, and unusually versatile JavaScript implementation of Protocol Buffers for Node.js and browsers. It works with `.proto` files out of the box, does not require protoc, and supports runtime reflection as well as specialized code generation with strong TypeScript declarations.
|
|
10
|
+
**protobuf.js** is a very fast, conformant, and unusually versatile JavaScript implementation of [Protocol Buffers](https://protobuf.dev) for Node.js and browsers. It is independently maintained with contributions from the upstream Protocol Buffers project, works with `.proto` schemas without requiring `protoc`, and supports runtime reflection as well as specialized code generation with matching TypeScript declarations.
|
|
13
11
|
|
|
14
12
|
If protobuf.js is important to your project or organization, or if you depend on it commercially, [consider supporting](https://github.com/sponsors/dcodeIO) its ongoing maintenance. Sponsorship helps make bug fixes, releases, LTS/security handling, and user support more sustainable.
|
|
15
13
|
|
|
16
14
|
## Getting started
|
|
17
15
|
|
|
18
|
-
Getting up and running is simple: Install the package, load a
|
|
16
|
+
Getting up and running is simple: Install the package, load a schema, and you are all set to encode and decode Protobuf messages. From there, protobuf.js grows with your requirements: Add code generation with TypeScript declarations, transport-agnostic services, support for text-based formats, and more as needed.
|
|
19
17
|
|
|
20
18
|
### Install
|
|
21
19
|
|
|
@@ -33,7 +31,7 @@ The CLI is a JS-native protobuf.js toolchain that does not require setting up `p
|
|
|
33
31
|
|
|
34
32
|
#### Browser builds
|
|
35
33
|
|
|
36
|
-
Canonical browser builds
|
|
34
|
+
Canonical browser builds are [provided via the jsDelivr CDN](https://cdn.jsdelivr.net/npm/protobufjs@8.X.X/dist/), supporting CommonJS, AMD and global `window.protobuf`. Make sure to pin an exact version in production.
|
|
37
35
|
|
|
38
36
|
## Usage
|
|
39
37
|
|
|
@@ -60,7 +58,7 @@ const root = await protobuf.load("awesome.proto");
|
|
|
60
58
|
const AwesomeMessage = root.lookupType("awesomepackage.AwesomeMessage");
|
|
61
59
|
```
|
|
62
60
|
|
|
63
|
-
Optionally use `load()` with a callback, or `loadSync()` for synchronous loading on Node.js.
|
|
61
|
+
Optionally use `load()` with a callback, or `loadSync()` for synchronous loading on Node.js. Imports resolve relative to the importing file by default. To resolve imports against a specific base directory, create a `Root` and override `root.resolvePath` before calling `root.load()`.
|
|
64
62
|
|
|
65
63
|
### Encode and decode
|
|
66
64
|
|
|
@@ -78,7 +76,7 @@ const decoded = AwesomeMessage.decode(encoded);
|
|
|
78
76
|
|
|
79
77
|
Plain objects can be encoded directly when they already use protobuf.js runtime types: numbers for 32-bit numeric fields, booleans for `bool`, strings for `string`, `Uint8Array` or `Buffer` for `bytes`, arrays for repeated fields, and plain objects for maps. Map keys are the string representation of the respective value or an 8-character hash string for 64-bit keys.
|
|
80
78
|
|
|
81
|
-
|
|
79
|
+
Note that, as with any structured binary format, decoded structures incur runtime memory overhead beyond their encoded representation. Applications processing untrusted input should therefore apply appropriate input-size and concurrency limits to bound memory use. For this reason, unknown fields present on the wire are intentionally discarded as the safer default, but can be retained by setting `reader.discardUnknown = false` per reader, or by setting `Reader.discardUnknown = false` to make it the default for subsequently created readers. Preserved unknown field data can also be explicitly dropped with `delete message.$unknowns`.
|
|
82
80
|
|
|
83
81
|
### Convert plain objects
|
|
84
82
|
|
|
@@ -138,41 +136,28 @@ Message types expose focused methods for validation, conversion, and binary I/O.
|
|
|
138
136
|
* **message.toJSON**(): `object`
|
|
139
137
|
Converts a message instance to JSON-compatible output using default conversion options.
|
|
140
138
|
|
|
141
|
-
Message instances provide runtime identity
|
|
139
|
+
Message instances provide stable runtime identity for testing with `instanceof`.
|
|
142
140
|
|
|
143
141
|
Length-delimited methods read and write a varint byte length before the message, which is useful for streams and framed protocols.
|
|
144
142
|
|
|
145
143
|
If required fields are missing while decoding proto2 data, `decode` throws `protobuf.util.ProtocolError` with the partially decoded message available as `err.instance`.
|
|
146
144
|
|
|
147
|
-
## Runtimes
|
|
148
|
-
|
|
149
|
-
protobuf.js provides three runtime entry points, keeping parser and reflection support optional: Runtime `.proto` loading needs the parser, JSON/reflection bundles need reflection support, and generated static modules only need the minimal runtime.
|
|
150
|
-
|
|
151
|
-
| Import | Includes | Use when
|
|
152
|
-
| ----------------------- | ------------------ | --------
|
|
153
|
-
| `protobufjs` | Reflection, Parser | You load `.proto` files at runtime
|
|
154
|
-
| `protobufjs/light.js` | Reflection | You load JSON bundles or build schemas programmatically
|
|
155
|
-
| `protobufjs/minimal.js` | Static runtime | You use generated static code
|
|
156
|
-
|
|
157
|
-
The full build includes the light build, and the light build includes the minimal runtime.
|
|
158
|
-
|
|
159
145
|
## Code generation
|
|
160
146
|
|
|
161
|
-
Use [`protobufjs-cli`](./cli/#readme) to generate
|
|
147
|
+
Use [`protobufjs-cli`](./cli/#readme) to generate schema-specific code, either directly with `pbjs` or through the optional `protoc-gen-pbjs` plugin for `protoc`.
|
|
162
148
|
|
|
163
|
-
|
|
149
|
+
protobuf.js offers two code-generation modes, both with matching TypeScript declarations: reflection modules generate optimized code at runtime with reflection metadata retained; static modules generate reflection-free code ahead of time. Both use the same runtime package and automatically import only the runtime capabilities they need.
|
|
164
150
|
|
|
165
|
-
| Target | Output |
|
|
166
|
-
|
|
167
|
-
| `json` |
|
|
168
|
-
| `
|
|
169
|
-
| `static-module` | Static code module | `protobufjs/minimal.js` |
|
|
151
|
+
| Target | Output | Runtime entry |
|
|
152
|
+
|--------|--------|---------------|
|
|
153
|
+
| `json-module` | Reflection module | `protobufjs/light.js` (without parser) |
|
|
154
|
+
| `static-module` | Static code module | `protobufjs/minimal.js` (without reflection) |
|
|
170
155
|
|
|
171
156
|
Module targets support `--wrap default` for CommonJS and AMD, plus `esm`, `commonjs`, `amd`, and `closure`; `--wrap` can also load a custom wrapper module.
|
|
172
157
|
|
|
173
158
|
### Static modules
|
|
174
159
|
|
|
175
|
-
Static modules emit dedicated JavaScript for your schema
|
|
160
|
+
Static modules emit dedicated, reflection-free JavaScript code for your schema.
|
|
176
161
|
|
|
177
162
|
```sh
|
|
178
163
|
npx pbjs -t static-module -w esm -o awesome.js --dts awesome.proto
|
|
@@ -184,22 +169,11 @@ import { awesomepackage } from "./awesome.js";
|
|
|
184
169
|
const message = awesomepackage.AwesomeMessage.create({ awesomeField: "hello" });
|
|
185
170
|
```
|
|
186
171
|
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
### Reflection bundles
|
|
172
|
+
Static code is repetitive by design, but compresses unusually well with Brotli or gzip and works in [CSP](https://w3c.github.io/webappsec-csp/)-restricted environments.
|
|
190
173
|
|
|
191
|
-
Reflection
|
|
174
|
+
### Reflection modules
|
|
192
175
|
|
|
193
|
-
|
|
194
|
-
npx pbjs -t json -o awesome.json awesome1.proto awesome2.proto ...
|
|
195
|
-
```
|
|
196
|
-
|
|
197
|
-
```ts
|
|
198
|
-
const bundle = require("./awesome.json");
|
|
199
|
-
|
|
200
|
-
const root = protobuf.Root.fromJSON(bundle);
|
|
201
|
-
const AwesomeMessage = root.lookupType("awesomepackage.AwesomeMessage");
|
|
202
|
-
```
|
|
176
|
+
Reflection modules wrap schemas as compact JSON metadata while avoiding `.proto` parsing at runtime.
|
|
203
177
|
|
|
204
178
|
```sh
|
|
205
179
|
npx pbjs -t json-module -w esm -o awesome.js --dts awesome.proto
|
|
@@ -211,13 +185,11 @@ import { awesomepackage } from "./awesome.js";
|
|
|
211
185
|
const AwesomeMessage = awesomepackage.AwesomeMessage;
|
|
212
186
|
```
|
|
213
187
|
|
|
214
|
-
|
|
188
|
+
Declarations for reflection modules mirror `static-module` typings. Because JSON modules export reflection objects, message instances should be created with `MyMessage.create(...)` rather than constructors. Code using `create(...)` works with static modules as well. Separately, `-t json` can serialize reflection metadata as bare JSON bundles for use with `load()` or `Root.fromJSON()`.
|
|
215
189
|
|
|
216
190
|
### TypeScript integration
|
|
217
191
|
|
|
218
|
-
protobuf.js works with TypeScript out of the box:
|
|
219
|
-
|
|
220
|
-
For example, given the oneof:
|
|
192
|
+
protobuf.js works with TypeScript out of the box: its runtime API is typed, and generated code can be paired with matching TypeScript declarations in a single CLI invocation. Declarations are strongly typed, including discriminated unions for oneofs and scoped types for plain-object usage:
|
|
221
193
|
|
|
222
194
|
```proto
|
|
223
195
|
message Profile {
|
|
@@ -228,8 +200,6 @@ message Profile {
|
|
|
228
200
|
}
|
|
229
201
|
```
|
|
230
202
|
|
|
231
|
-
Generated declarations narrow both the `contact` oneof and the concrete values:
|
|
232
|
-
|
|
233
203
|
```ts
|
|
234
204
|
const profile = Profile.create({
|
|
235
205
|
contact: "email",
|
|
@@ -246,7 +216,7 @@ if (decoded.contact === "phone") {
|
|
|
246
216
|
}
|
|
247
217
|
```
|
|
248
218
|
|
|
249
|
-
|
|
219
|
+
The same narrowed shape is available for plain-object inputs:
|
|
250
220
|
|
|
251
221
|
```ts
|
|
252
222
|
const object: Profile.$Shape = {
|
|
@@ -259,7 +229,7 @@ const object: Profile.$Shape = {
|
|
|
259
229
|
|
|
260
230
|
### Programmatic schemas
|
|
261
231
|
|
|
262
|
-
|
|
232
|
+
Schemas can be constructed directly through reflection:
|
|
263
233
|
|
|
264
234
|
```ts
|
|
265
235
|
const AwesomeMessage = new protobuf.Type("AwesomeMessage")
|
|
@@ -316,22 +286,7 @@ const myService = MyService.create(myRpcImpl/*, requestDelimited?, responseDelim
|
|
|
316
286
|
|
|
317
287
|
See [examples/streaming-rpc.js](./examples/streaming-rpc.js) for a streaming example.
|
|
318
288
|
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
```js
|
|
322
|
-
const grpc = require('@grpc/grpc-js');
|
|
323
|
-
|
|
324
|
-
const Client = grpc.makeGenericClientConstructor({});
|
|
325
|
-
const client = new Client(serverAddress, grpc.credentials.createInsecure());
|
|
326
|
-
|
|
327
|
-
const rpcImpl = (method, requestData, callback) =>
|
|
328
|
-
client.makeUnaryRequest(method.path, (data) => data, (data) => data, requestData, callback);
|
|
329
|
-
|
|
330
|
-
const greeter = root.lookupService("example.Greeter").create(rpcImpl);
|
|
331
|
-
const reply = await greeter.sayHello({ name: "world" });
|
|
332
|
-
```
|
|
333
|
-
|
|
334
|
-
See [examples/grpc-service.js](./examples/grpc-service.js) for a complete example.
|
|
289
|
+
See [examples/grpc-service.js](./examples/grpc-service.js) for an integration example with [@grpc/grpc-js](https://www.npmjs.com/package/@grpc/grpc-js).
|
|
335
290
|
|
|
336
291
|
### Extensions
|
|
337
292
|
|
|
@@ -339,7 +294,7 @@ The following extensions provide descriptor conversion and text-based protobuf f
|
|
|
339
294
|
|
|
340
295
|
#### Descriptors
|
|
341
296
|
|
|
342
|
-
protobuf.js uses a compact JSON-based reflection representation internally
|
|
297
|
+
protobuf.js uses a compact JSON-based reflection representation internally. See [ext/descriptor](./ext/README.md#descriptor) for use cases that need conversion between reflected roots and `protoc` descriptor messages.
|
|
343
298
|
|
|
344
299
|
#### ProtoJSON
|
|
345
300
|
|
|
@@ -351,7 +306,7 @@ Protocol Buffers [Text Format](https://protobuf.dev/reference/protobuf/textforma
|
|
|
351
306
|
|
|
352
307
|
## Conformance
|
|
353
308
|
|
|
354
|
-
protobuf.js is validated against the official Protocol Buffers conformance suite
|
|
309
|
+
protobuf.js is validated against the official Protocol Buffers conformance suite. It passes all required and recommended tests for the **Proto2**, **Proto3** and **Editions** binary wire formats, with complete **ProtoJSON** and **Text Format** support available as optional extensions when those formats are needed.
|
|
355
310
|
|
|
356
311
|
<!-- BEGIN CONFORMANCE DATA -->
|
|
357
312
|
|
|
@@ -367,37 +322,59 @@ protobuf.js is validated against the official Protocol Buffers conformance suite
|
|
|
367
322
|
|
|
368
323
|
<!-- END CONFORMANCE DATA -->
|
|
369
324
|
|
|
370
|
-
[Structured results](https://github.com/protobufjs/protobuf.js/actions/workflows/test.yml?query=branch%3Amaster+event%3Apush) are available as CI artifacts.
|
|
325
|
+
[Structured results](https://github.com/protobufjs/protobuf.js/actions/workflows/test.yml?query=branch%3Amaster+event%3Apush) of the conformance tests are also available as CI artifacts.
|
|
371
326
|
|
|
372
327
|
## Performance
|
|
373
328
|
|
|
374
|
-
|
|
329
|
+
Both reflection and static modes use specialized encoders and decoders backed by the same hand-tuned reader and writer primitives.
|
|
375
330
|
|
|
376
|
-
The repository includes a [
|
|
331
|
+
The repository includes a [benchmark suite](./bench) you can run yourself. It compares protobuf.js with other general-purpose JavaScript implementations across three substantially different cases: our classic common message shape and two unmodified, structurally distinct fixtures sourced externally. The suite measures each library's recommended serialization and deserialization path using identical schemas and inputs, with JSON included as an additional baseline. Across these cases, protobuf.js is a clear upgrade over using JSON and consistently the fastest Protobuf implementation by a considerable margin.
|
|
377
332
|
|
|
378
333
|
<!-- BEGIN BENCHMARK DATA -->
|
|
379
334
|
|
|
380
|
-
|
|
335
|
+
<picture>
|
|
336
|
+
<source media="(prefers-color-scheme: dark)" srcset="./bench/results/encode-dark.svg">
|
|
337
|
+
<source media="(prefers-color-scheme: light)" srcset="./bench/results/encode-light.svg">
|
|
338
|
+
<img alt="Encode benchmark" src="./bench/results/encode.svg">
|
|
339
|
+
</picture>
|
|
340
|
+
|
|
341
|
+
<details>
|
|
342
|
+
<summary>Show table</summary>
|
|
343
|
+
|
|
344
|
+
| Implementation | Common | Vector tile | Buf perf |
|
|
345
|
+
| --- | ---: | ---: | ---: |
|
|
346
|
+
| protobuf.js static | **5.34M ops/s** <small>1.0x</small> | **3.09K ops/s** <small>1.0x</small> | 43.1K ops/s <small>1.0x</small> |
|
|
347
|
+
| protobuf.js reflect | 4.89M ops/s <small>1.1x</small> | 3.03K ops/s <small>1.0x</small> | **43.3K ops/s** <small>1.0x</small> |
|
|
348
|
+
| JSON | 2.09M ops/s <small>2.6x</small> | 897 ops/s <small>3.4x</small> | 6.70K ops/s <small>6.5x</small> |
|
|
349
|
+
| protoc-gen-js | 1.03M ops/s <small>5.2x</small> | 700 ops/s <small>4.4x</small> | 13.9K ops/s <small>3.1x</small> |
|
|
350
|
+
| protoc-gen-es | 402K ops/s <small>13.3x</small> | 235 ops/s <small>13.2x</small> | 8.22K ops/s <small>5.3x</small> |
|
|
351
|
+
|
|
352
|
+
</details>
|
|
353
|
+
|
|
354
|
+
<picture>
|
|
355
|
+
<source media="(prefers-color-scheme: dark)" srcset="./bench/results/decode-dark.svg">
|
|
356
|
+
<source media="(prefers-color-scheme: light)" srcset="./bench/results/decode-light.svg">
|
|
357
|
+
<img alt="Decode benchmark" src="./bench/results/decode.svg">
|
|
358
|
+
</picture>
|
|
381
359
|
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
| Common | 3.18M ops/s | 3.25M ops/s | 2.07M ops/s | 1.01M ops/s | 395K ops/s |
|
|
385
|
-
| Vector tile | 2.82K ops/s | 2.76K ops/s | 859 ops/s | 680 ops/s | 231 ops/s |
|
|
386
|
-
| Buf perf | 41.4K ops/s | 39.9K ops/s | 6.59K ops/s | 13.5K ops/s | 8.00K ops/s |
|
|
360
|
+
<details>
|
|
361
|
+
<summary>Show table</summary>
|
|
387
362
|
|
|
388
|
-
|
|
363
|
+
| Implementation | Common | Vector tile | Buf perf |
|
|
364
|
+
| --- | ---: | ---: | ---: |
|
|
365
|
+
| protobuf.js static | 6.45M ops/s <small>1.1x</small> | 2.70K ops/s <small>1.1x</small> | **81.7K ops/s** <small>1.0x</small> |
|
|
366
|
+
| protobuf.js reflect | **6.93M ops/s** <small>1.0x</small> | **2.99K ops/s** <small>1.0x</small> | 80.3K ops/s <small>1.0x</small> |
|
|
367
|
+
| JSON | 1.37M ops/s <small>5.0x</small> | 1.06K ops/s <small>2.8x</small> | 19.5K ops/s <small>4.2x</small> |
|
|
368
|
+
| protoc-gen-js | 811K ops/s <small>8.5x</small> | 851 ops/s <small>3.5x</small> | 21.7K ops/s <small>3.8x</small> |
|
|
369
|
+
| protoc-gen-es | 691K ops/s <small>10.0x</small> | 376 ops/s <small>8.0x</small> | 14.3K ops/s <small>5.7x</small> |
|
|
389
370
|
|
|
390
|
-
|
|
391
|
-
| --- | ---: | ---: | ---: | ---: | ---: |
|
|
392
|
-
| Common | 6.11M ops/s | 6.09M ops/s | 1.31M ops/s | 790K ops/s | 710K ops/s |
|
|
393
|
-
| Vector tile | 2.45K ops/s | 2.78K ops/s | 1.04K ops/s | 858 ops/s | 392 ops/s |
|
|
394
|
-
| Buf perf | 72.5K ops/s | 66.4K ops/s | 19.0K ops/s | 21.1K ops/s | 14.2K ops/s |
|
|
371
|
+
</details>
|
|
395
372
|
|
|
396
373
|
<!-- END BENCHMARK DATA -->
|
|
397
374
|
|
|
398
|
-
[Structured results](./bench/results/latest.json)
|
|
375
|
+
[Structured results](./bench/results/latest.json) and environment details for this run are also available as committed artifacts.
|
|
399
376
|
|
|
400
|
-
To run the benchmark
|
|
377
|
+
To run the benchmark on your own hardware:
|
|
401
378
|
|
|
402
379
|
```sh
|
|
403
380
|
npm --prefix bench install
|
package/dist/light/protobuf.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/*!
|
|
2
|
-
* protobuf.js v8.7.
|
|
3
|
-
* compiled
|
|
2
|
+
* protobuf.js v8.7.2 (c) 2016, daniel wirtz
|
|
3
|
+
* compiled sat, 08 aug 2026 13:15:56 utc
|
|
4
4
|
* licensed under the bsd-3-clause license
|
|
5
5
|
* see: https://github.com/dcodeio/protobuf.js for details
|
|
6
6
|
*/
|
|
@@ -340,12 +340,16 @@ converter.toObject = function toObject(mtype) {
|
|
|
340
340
|
else if (field.bytes) {
|
|
341
341
|
var arrayDefault = Array.prototype.slice.call(field.typeDefault);
|
|
342
342
|
gen
|
|
343
|
-
("if(o.bytes===String)d%s=%j", prop,
|
|
343
|
+
("if(o.bytes===String)d%s=%j", prop, util.base64.encode(field.typeDefault, 0, field.typeDefault.length))
|
|
344
344
|
("else{")
|
|
345
345
|
("d%s=%j", prop, arrayDefault)
|
|
346
346
|
("if(o.bytes!==Array)d%s=util.newBuffer(d%s)", prop, prop)
|
|
347
347
|
("}");
|
|
348
|
-
} else
|
|
348
|
+
} else if ((field.type === "double" || field.type === "float") && typeof field.typeDefault === "number"
|
|
349
|
+
&& (!isFinite(field.typeDefault) || Object.is(field.typeDefault, -0))) gen
|
|
350
|
+
("d%s=%f", prop, field.typeDefault)
|
|
351
|
+
("if(o.json&&!isFinite(d%s))d%s=String(d%s)", prop, prop, prop);
|
|
352
|
+
else gen
|
|
349
353
|
("d%s=%j", prop, field.typeDefault); // also messages (=null)
|
|
350
354
|
} gen
|
|
351
355
|
("}");
|
|
@@ -498,7 +502,7 @@ function decoder(mtype) {
|
|
|
498
502
|
("break");
|
|
499
503
|
|
|
500
504
|
if (types.basic[type] === undefined) gen
|
|
501
|
-
("v=types[%i].decode(r,r.uint32(),undefined,q+1)", i); // can't be groups
|
|
505
|
+
("v=types[%i].decode(r,r.uint32(),undefined,q+1,v)", i); // can't be groups
|
|
502
506
|
else gen
|
|
503
507
|
("v=r.%s()", type === "string" ? stringMethod(field) : type);
|
|
504
508
|
|
|
@@ -884,8 +888,11 @@ function Enum(name, values, options, comment, comments, valuesOptions) {
|
|
|
884
888
|
|
|
885
889
|
if (values)
|
|
886
890
|
for (var keys = Object.keys(values), i = 0; i < keys.length; ++i)
|
|
887
|
-
if (keys[i] !== "__proto__" && typeof values[keys[i]] === "number") // use forward entries only
|
|
888
|
-
this.
|
|
891
|
+
if (keys[i] !== "__proto__" && typeof values[keys[i]] === "number") { // use forward entries only
|
|
892
|
+
this.values[keys[i]] = values[keys[i]];
|
|
893
|
+
if (this.valuesById[values[keys[i]]] === undefined)
|
|
894
|
+
this.valuesById[values[keys[i]]] = keys[i];
|
|
895
|
+
}
|
|
889
896
|
}
|
|
890
897
|
|
|
891
898
|
/**
|
|
@@ -1414,12 +1421,17 @@ Field.prototype.resolve = function resolve() {
|
|
|
1414
1421
|
|
|
1415
1422
|
// convert to internal data type if necesssary
|
|
1416
1423
|
if (this.long) {
|
|
1417
|
-
|
|
1424
|
+
var unsigned = this.type === "uint64" || this.type === "fixed64";
|
|
1425
|
+
this.typeDefault = typeof this.typeDefault === "string"
|
|
1426
|
+
? util.Long.fromString(this.typeDefault, unsigned)
|
|
1427
|
+
: util.Long.fromNumber(this.typeDefault, unsigned);
|
|
1418
1428
|
|
|
1419
1429
|
/* istanbul ignore else */
|
|
1420
1430
|
if (Object.freeze)
|
|
1421
1431
|
Object.freeze(this.typeDefault); // long instances are meant to be immutable anyway (i.e. use small int cache that even requires it)
|
|
1422
1432
|
|
|
1433
|
+
} else if (types.long[this.type] !== undefined && typeof this.typeDefault === "string") {
|
|
1434
|
+
this.typeDefault = parseInt(this.typeDefault, 10);
|
|
1423
1435
|
} else if (this.bytes && typeof this.typeDefault === "string") {
|
|
1424
1436
|
var buf;
|
|
1425
1437
|
if (util.base64.test(this.typeDefault))
|
|
@@ -1682,6 +1694,7 @@ exports.configure = configure;
|
|
|
1682
1694
|
* @returns {undefined}
|
|
1683
1695
|
*/
|
|
1684
1696
|
function configure() {
|
|
1697
|
+
exports.util.LongBits._configure(exports.util.Long);
|
|
1685
1698
|
exports.Writer._configure(exports.BufferWriter);
|
|
1686
1699
|
exports.Reader._configure(exports.BufferReader);
|
|
1687
1700
|
}
|
|
@@ -3762,9 +3775,18 @@ Reader.prototype.double = function read_double() {
|
|
|
3762
3775
|
*/
|
|
3763
3776
|
Reader.prototype.uint32s = function read_uint32s(array) {
|
|
3764
3777
|
if (array === undefined) array = [];
|
|
3765
|
-
var end = this.uint32() + this.pos;
|
|
3766
|
-
while (
|
|
3767
|
-
|
|
3778
|
+
var end = this.uint32() + this.pos, buf = this.buf, pos = this.pos, value;
|
|
3779
|
+
while (pos < end) {
|
|
3780
|
+
value = buf[pos++];
|
|
3781
|
+
if (value < 128)
|
|
3782
|
+
array.push(value);
|
|
3783
|
+
else {
|
|
3784
|
+
this.pos = pos - 1;
|
|
3785
|
+
array.push(this.uint32());
|
|
3786
|
+
pos = this.pos;
|
|
3787
|
+
}
|
|
3788
|
+
}
|
|
3789
|
+
this.pos = pos;
|
|
3768
3790
|
return array;
|
|
3769
3791
|
};
|
|
3770
3792
|
|
|
@@ -3775,9 +3797,18 @@ Reader.prototype.uint32s = function read_uint32s(array) {
|
|
|
3775
3797
|
*/
|
|
3776
3798
|
Reader.prototype.int32s = function read_int32s(array) {
|
|
3777
3799
|
if (array === undefined) array = [];
|
|
3778
|
-
var end = this.uint32() + this.pos;
|
|
3779
|
-
while (
|
|
3780
|
-
|
|
3800
|
+
var end = this.uint32() + this.pos, buf = this.buf, pos = this.pos, value;
|
|
3801
|
+
while (pos < end) {
|
|
3802
|
+
value = buf[pos++];
|
|
3803
|
+
if (value < 128)
|
|
3804
|
+
array.push(value);
|
|
3805
|
+
else {
|
|
3806
|
+
this.pos = pos - 1;
|
|
3807
|
+
array.push(this.int32());
|
|
3808
|
+
pos = this.pos;
|
|
3809
|
+
}
|
|
3810
|
+
}
|
|
3811
|
+
this.pos = pos;
|
|
3781
3812
|
return array;
|
|
3782
3813
|
};
|
|
3783
3814
|
|
|
@@ -3801,9 +3832,18 @@ Reader.prototype.sint32s = function read_sint32s(array) {
|
|
|
3801
3832
|
*/
|
|
3802
3833
|
Reader.prototype.bools = function read_bools(array) {
|
|
3803
3834
|
if (array === undefined) array = [];
|
|
3804
|
-
var end = this.uint32() + this.pos;
|
|
3805
|
-
while (
|
|
3806
|
-
|
|
3835
|
+
var end = this.uint32() + this.pos, buf = this.buf, pos = this.pos, value;
|
|
3836
|
+
while (pos < end) {
|
|
3837
|
+
value = buf[pos++];
|
|
3838
|
+
if (value < 128)
|
|
3839
|
+
array.push(value !== 0);
|
|
3840
|
+
else {
|
|
3841
|
+
this.pos = pos - 1;
|
|
3842
|
+
array.push(this.bool());
|
|
3843
|
+
pos = this.pos;
|
|
3844
|
+
}
|
|
3845
|
+
}
|
|
3846
|
+
this.pos = pos;
|
|
3807
3847
|
return array;
|
|
3808
3848
|
};
|
|
3809
3849
|
|
|
@@ -6493,7 +6533,9 @@ function codegen(functionParams, functionName) {
|
|
|
6493
6533
|
formatStringOrScope = formatStringOrScope.replace(/%([%dfijs])/g, function replace($0, $1) {
|
|
6494
6534
|
var value = formatParams[formatOffset++];
|
|
6495
6535
|
switch ($1) {
|
|
6496
|
-
case "d": case "f":
|
|
6536
|
+
case "d": case "f":
|
|
6537
|
+
value = Number(value);
|
|
6538
|
+
return Object.is(value, -0) ? "-0" : String(value);
|
|
6497
6539
|
case "i": return String(Math.floor(value));
|
|
6498
6540
|
case "j": return JSON.stringify(value);
|
|
6499
6541
|
case "s": return String(value);
|
|
@@ -7102,7 +7144,7 @@ module.exports = fs;
|
|
|
7102
7144
|
"use strict";
|
|
7103
7145
|
module.exports = LongBits;
|
|
7104
7146
|
|
|
7105
|
-
var
|
|
7147
|
+
var Long;
|
|
7106
7148
|
|
|
7107
7149
|
/**
|
|
7108
7150
|
* Constructs new long bits.
|
|
@@ -7181,10 +7223,10 @@ LongBits.fromNumber = function fromNumber(value) {
|
|
|
7181
7223
|
LongBits.from = function from(value) {
|
|
7182
7224
|
if (typeof value === "number")
|
|
7183
7225
|
return LongBits.fromNumber(value);
|
|
7184
|
-
if (
|
|
7226
|
+
if (typeof value === "string" || value instanceof String) {
|
|
7185
7227
|
/* istanbul ignore else */
|
|
7186
|
-
if (
|
|
7187
|
-
value =
|
|
7228
|
+
if (Long)
|
|
7229
|
+
value = Long.fromString(value);
|
|
7188
7230
|
else
|
|
7189
7231
|
return LongBits.fromNumber(parseInt(value, 10));
|
|
7190
7232
|
}
|
|
@@ -7213,8 +7255,8 @@ LongBits.prototype.toNumber = function toNumber(unsigned) {
|
|
|
7213
7255
|
* @returns {Long} Long
|
|
7214
7256
|
*/
|
|
7215
7257
|
LongBits.prototype.toLong = function toLong(unsigned) {
|
|
7216
|
-
return
|
|
7217
|
-
? new
|
|
7258
|
+
return Long
|
|
7259
|
+
? new Long(this.lo | 0, this.hi | 0, Boolean(unsigned))
|
|
7218
7260
|
/* istanbul ignore next */
|
|
7219
7261
|
: { low: this.lo | 0, high: this.hi | 0, unsigned: Boolean(unsigned) };
|
|
7220
7262
|
};
|
|
@@ -7300,7 +7342,11 @@ LongBits.prototype.length = function length() {
|
|
|
7300
7342
|
: part2 < 128 ? 9 : 10;
|
|
7301
7343
|
};
|
|
7302
7344
|
|
|
7303
|
-
|
|
7345
|
+
LongBits._configure = function(Long_) {
|
|
7346
|
+
Long = Long_;
|
|
7347
|
+
};
|
|
7348
|
+
|
|
7349
|
+
},{}],33:[function(require,module,exports){
|
|
7304
7350
|
"use strict";
|
|
7305
7351
|
/* global globalThis */
|
|
7306
7352
|
var util = exports;
|
|
@@ -7983,7 +8029,6 @@ function pool(alloc, slice, size) {
|
|
|
7983
8029
|
* @namespace
|
|
7984
8030
|
*/
|
|
7985
8031
|
var utf8 = exports,
|
|
7986
|
-
replacementChar = "\ufffd",
|
|
7987
8032
|
looseDecoder = new TextDecoder("utf-8", { ignoreBOM: true }),
|
|
7988
8033
|
strictDecoder;
|
|
7989
8034
|
var TEXT_DECODER_MIN_LENGTH = 64;
|
|
@@ -8018,31 +8063,6 @@ utf8.length = function utf8_length(string) {
|
|
|
8018
8063
|
return len;
|
|
8019
8064
|
};
|
|
8020
8065
|
|
|
8021
|
-
function utf8_read_js(buffer, start, end, str) {
|
|
8022
|
-
for (var i = start; i < end;) {
|
|
8023
|
-
var t = buffer[i++];
|
|
8024
|
-
if (t <= 0x7F) {
|
|
8025
|
-
str += String.fromCharCode(t);
|
|
8026
|
-
} else if (t >= 0xC0 && t < 0xE0) {
|
|
8027
|
-
var c2 = (t & 0x1F) << 6 | buffer[i++] & 0x3F;
|
|
8028
|
-
str += c2 >= 0x80 ? String.fromCharCode(c2) : replacementChar;
|
|
8029
|
-
} else if (t >= 0xE0 && t < 0xF0) {
|
|
8030
|
-
var c3 = (t & 0xF) << 12 | (buffer[i++] & 0x3F) << 6 | buffer[i++] & 0x3F;
|
|
8031
|
-
str += c3 >= 0x800 ? String.fromCharCode(c3) : replacementChar;
|
|
8032
|
-
} else if (t >= 0xF0) {
|
|
8033
|
-
var t2 = (t & 7) << 18 | (buffer[i++] & 0x3F) << 12 | (buffer[i++] & 0x3F) << 6 | buffer[i++] & 0x3F;
|
|
8034
|
-
if (t2 < 0x10000 || t2 > 0x10FFFF)
|
|
8035
|
-
str += replacementChar;
|
|
8036
|
-
else {
|
|
8037
|
-
t2 -= 0x10000;
|
|
8038
|
-
str += String.fromCharCode(0xD800 + (t2 >> 10));
|
|
8039
|
-
str += String.fromCharCode(0xDC00 + (t2 & 0x3FF));
|
|
8040
|
-
}
|
|
8041
|
-
}
|
|
8042
|
-
}
|
|
8043
|
-
return str;
|
|
8044
|
-
}
|
|
8045
|
-
|
|
8046
8066
|
function utf8_read_decoder(decoder, buffer, start, end) {
|
|
8047
8067
|
var source = start === 0 && end === buffer.length
|
|
8048
8068
|
? buffer
|
|
@@ -8077,14 +8097,14 @@ utf8.read = function utf8_read_loose(buffer, start, end) {
|
|
|
8077
8097
|
c7 = buffer[i + 6];
|
|
8078
8098
|
c8 = buffer[i + 7];
|
|
8079
8099
|
if ((c1 | c2 | c3 | c4 | c5 | c6 | c7 | c8) & 0x80)
|
|
8080
|
-
return
|
|
8100
|
+
return str + utf8_read_decoder(looseDecoder, buffer, i, end);
|
|
8081
8101
|
str += String.fromCharCode(c1, c2, c3, c4, c5, c6, c7, c8);
|
|
8082
8102
|
}
|
|
8083
8103
|
|
|
8084
8104
|
for (; i < end; ++i) {
|
|
8085
8105
|
c1 = buffer[i];
|
|
8086
8106
|
if (c1 & 0x80)
|
|
8087
|
-
return
|
|
8107
|
+
return str + utf8_read_decoder(looseDecoder, buffer, i, end);
|
|
8088
8108
|
str += String.fromCharCode(c1);
|
|
8089
8109
|
}
|
|
8090
8110
|
|
|
@@ -8490,7 +8510,7 @@ function Writer() {
|
|
|
8490
8510
|
* Backing buffer.
|
|
8491
8511
|
* @type {Uint8Array}
|
|
8492
8512
|
*/
|
|
8493
|
-
this.buf = this.constructor.alloc(
|
|
8513
|
+
this.buf = this.constructor.alloc(Writer.initialBufferSize);
|
|
8494
8514
|
|
|
8495
8515
|
/**
|
|
8496
8516
|
* Cached DataView over {@link Writer#buf}.
|
|
@@ -8505,6 +8525,12 @@ function Writer() {
|
|
|
8505
8525
|
this.states = null;
|
|
8506
8526
|
}
|
|
8507
8527
|
|
|
8528
|
+
/**
|
|
8529
|
+
* Initial backing buffer size in bytes. Defaults to 128.
|
|
8530
|
+
* @type {number}
|
|
8531
|
+
*/
|
|
8532
|
+
Writer.initialBufferSize = 128;
|
|
8533
|
+
|
|
8508
8534
|
/**
|
|
8509
8535
|
* Current write position.
|
|
8510
8536
|
* @name Writer#len
|