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 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
- **Protocol Buffers** are a language-neutral, platform-neutral, extensible way of serializing structured data for use in communications protocols, data storage, and more, originally designed at Google ([see](https://protobuf.dev/)).
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 `.proto` file, and you are all set to encode and decode Protobuf messages. From there, protobuf.js grows with your requirements: Add any combination of capabilities, such as [code generation](#code-generation), [TypeScript declarations](#typescript-integration), [transport-agnostic services](#services), [programmatic schemas](#programmatic-schemas), [optional extensions](#extensions), and more as needed. All in one flexible toolkit.
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 for each runtime variant 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.
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
- Unknown fields present on the wire are discarded by default. To preserve and forward unknown fields, set `reader.discardUnknown = false` before decoding with that reader, or make this the default for subsequently created readers with `Reader.discardUnknown = false`. Preserved unknown field data can be dropped from a decoded message with `delete message.$unknowns`.
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, so they can be tested with `instanceof`. Their `toJSON` method integrates them with `JSON.stringify`.
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 reflection bundles, static JavaScript code, and matching TypeScript declarations, either directly with `pbjs` or through the optional `protoc-gen-pbjs` plugin for `protoc`.
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
- Reflection keeps schemas as JSON metadata and generates optimized functions at runtime. Static code emits schema-specific, reflection-free functions ahead of time. The main tradeoffs are how schemas are loaded, how bundle size scales with schema size, and whether reflection metadata should remain available at runtime.
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 | Minimum Runtime |
166
- |--------|--------|-----------------|
167
- | `json` | JSON bundle | `protobufjs/light.js` |
168
- | `json-module` | JSON bundle module | `protobufjs/light.js` |
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, so they only need `protobufjs/minimal.js` at runtime.
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
- While static code is verbose by design, its repeated patterns compress well with Brotli or gzip, and it works in [CSP](https://w3c.github.io/webappsec-csp/)-restricted environments that disallow unsafe-eval without sacrificing performance.
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 bundles store schemas as compact JSON metadata, avoiding `.proto` parsing at runtime and letting browsers load schema metadata in one request. While they require at least `protobufjs/light.js`, large schemas can produce smaller combined bundles than equivalent static modules because common code is shared through reflection.
174
+ ### Reflection modules
192
175
 
193
- ```sh
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
- JSON modules export the reflection root and, with `-w esm`, also provide top-level named exports that align with static modules. Their declarations mirror `static-module` typings, but because JSON modules are backed by reflection objects, message instances should be created with `MyMessage.create(...)` instead of constructors. Code using `create(...)` works with static modules as well.
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: the runtime API is typed, and generated JavaScript can be paired with strong TypeScript declarations in the same CLI invocation. Generated output is directly usable from JavaScript without a transpile step, and strongly typed in TypeScript projects, with type-checked oneofs and JavaScript-friendly plain-object input.
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
- Plain objects can use the same narrowed shape through a collision-free scoped type:
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
- The full and light builds can construct schemas directly through reflection:
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
- Integration example with [@grpc/grpc-js](https://www.npmjs.com/package/@grpc/grpc-js):
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 that is easy to embed and fast to parse, so schemas can be loaded directly without first decoding binary descriptor blobs or postprocessing their full JSON representation. See [ext/descriptor](./ext/README.md#descriptor) for use cases that need conversion between reflected roots and `protoc` descriptor messages.
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, achieving complete binary wire-format conformance for **Proto2**, **Proto3** and **Editions**, plus complete **ProtoJSON** and **Text Format** conformance in its default configuration with reflection metadata present.
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. In case of contradicting claims by your favorite LLM, [see](https://dev.to/dcode/when-the-model-is-the-marketing-device-a-protobuf-short-story-2p7p).
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
- In both reflection and reflection-free modes, protobuf.js builds specialized encoders and decoders on top of hand-tuned reader and writer primitives, making it a strong fit from battery-powered devices to high-traffic servers, or generally for projects and their downstream users adopting protobuf as a faster, smaller alternative to JSON.
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 [small benchmark](./bench) over a common message shape, plus Mapbox's vector tile fixture and Buf's perf payload, both unmodified. For each case, it compares protobuf.js encode and decode throughput against JSON encode/decode, Google's protoc-gen-js, and Buf's protoc-gen-es. Results show that protobuf.js is consistently faster than the other Protobuf implementations, up to an order of magnitude on real-world data, and among the libraries tested, it is the only one that is an upgrade over using JSON.
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
- ![Encode benchmark](./bench/results/encode.svg)
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** &nbsp; <small>1.0x</small> | **3.09K ops/s** &nbsp; <small>1.0x</small> | 43.1K ops/s &nbsp; <small>1.0x</small> |
347
+ | protobuf.js reflect | 4.89M ops/s &nbsp; <small>1.1x</small> | 3.03K ops/s &nbsp; <small>1.0x</small> | **43.3K ops/s** &nbsp; <small>1.0x</small> |
348
+ | JSON | 2.09M ops/s &nbsp; <small>2.6x</small> | 897 ops/s &nbsp; <small>3.4x</small> | 6.70K ops/s &nbsp; <small>6.5x</small> |
349
+ | protoc-gen-js | 1.03M ops/s &nbsp; <small>5.2x</small> | 700 ops/s &nbsp; <small>4.4x</small> | 13.9K ops/s &nbsp; <small>3.1x</small> |
350
+ | protoc-gen-es | 402K ops/s &nbsp; <small>13.3x</small> | 235 ops/s &nbsp; <small>13.2x</small> | 8.22K ops/s &nbsp; <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
- | Case | protobuf.js static | protobuf.js reflect | JSON | protoc-gen-js | protoc-gen-es |
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
- ![Decode benchmark](./bench/results/decode.svg)
363
+ | Implementation | Common | Vector tile | Buf perf |
364
+ | --- | ---: | ---: | ---: |
365
+ | protobuf.js static | 6.45M ops/s &nbsp; <small>1.1x</small> | 2.70K ops/s &nbsp; <small>1.1x</small> | **81.7K ops/s** &nbsp; <small>1.0x</small> |
366
+ | protobuf.js reflect | **6.93M ops/s** &nbsp; <small>1.0x</small> | **2.99K ops/s** &nbsp; <small>1.0x</small> | 80.3K ops/s &nbsp; <small>1.0x</small> |
367
+ | JSON | 1.37M ops/s &nbsp; <small>5.0x</small> | 1.06K ops/s &nbsp; <small>2.8x</small> | 19.5K ops/s &nbsp; <small>4.2x</small> |
368
+ | protoc-gen-js | 811K ops/s &nbsp; <small>8.5x</small> | 851 ops/s &nbsp; <small>3.5x</small> | 21.7K ops/s &nbsp; <small>3.8x</small> |
369
+ | protoc-gen-es | 691K ops/s &nbsp; <small>10.0x</small> | 376 ops/s &nbsp; <small>8.0x</small> | 14.3K ops/s &nbsp; <small>5.7x</small> |
389
370
 
390
- | Case | protobuf.js static | protobuf.js reflect | JSON | protoc-gen-js | protoc-gen-es |
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) of this run are available as committed artifacts.
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 yourself on your own hardware:
377
+ To run the benchmark on your own hardware:
401
378
 
402
379
  ```sh
403
380
  npm --prefix bench install
@@ -1,6 +1,6 @@
1
1
  /*!
2
- * protobuf.js v8.7.0 (c) 2016, daniel wirtz
3
- * compiled mon, 06 jul 2026 13:50:00 utc
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, String.fromCharCode.apply(String, field.typeDefault))
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 gen
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.valuesById[ this.values[keys[i]] = values[keys[i]] ] = keys[i];
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
- this.typeDefault = util.Long.fromNumber(this.typeDefault, this.type === "uint64" || this.type === "fixed64");
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 (this.pos < end)
3767
- array.push(this.uint32());
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 (this.pos < end)
3780
- array.push(this.int32());
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 (this.pos < end)
3806
- array.push(this.bool());
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": return String(Number(value));
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 util = require(33);
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 (util.isString(value)) {
7226
+ if (typeof value === "string" || value instanceof String) {
7185
7227
  /* istanbul ignore else */
7186
- if (util.Long)
7187
- value = util.Long.fromString(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 util.Long
7217
- ? new util.Long(this.lo | 0, this.hi | 0, Boolean(unsigned))
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
- },{"33":33}],33:[function(require,module,exports){
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 utf8_read_js(buffer, i, end, str);
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 utf8_read_js(buffer, i, end, str);
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(64);
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