protobufjs 8.6.5 → 8.7.0
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 +52 -53
- package/dist/light/protobuf.js +733 -334
- 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 +717 -320
- 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 +759 -347
- package/dist/protobuf.js.map +1 -1
- package/dist/protobuf.min.js +3 -3
- package/dist/protobuf.min.js.map +1 -1
- package/index.d.ts +211 -23
- package/package.json +2 -2
- package/src/decoder.js +4 -7
- package/src/encoder.js +1 -4
- package/src/index-minimal.js +0 -1
- package/src/parse.js +26 -13
- package/src/reader.js +251 -21
- package/src/reader_buffer.js +1 -3
- package/src/type.js +9 -1
- package/src/util/minimal.js +12 -40
- package/src/util/utf8.js +19 -17
- package/src/wrappers.js +2 -2
- package/src/writer.js +399 -194
- package/src/writer_buffer.js +33 -42
package/README.md
CHANGED
|
@@ -9,12 +9,14 @@
|
|
|
9
9
|
|
|
10
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
11
|
|
|
12
|
-
**protobuf.js** is a
|
|
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.
|
|
13
13
|
|
|
14
|
-
If protobuf.js is important to your project or organization,
|
|
14
|
+
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
15
|
|
|
16
16
|
## Getting started
|
|
17
17
|
|
|
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.
|
|
19
|
+
|
|
18
20
|
### Install
|
|
19
21
|
|
|
20
22
|
```sh
|
|
@@ -314,6 +316,23 @@ const myService = MyService.create(myRpcImpl/*, requestDelimited?, responseDelim
|
|
|
314
316
|
|
|
315
317
|
See [examples/streaming-rpc.js](./examples/streaming-rpc.js) for a streaming example.
|
|
316
318
|
|
|
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.
|
|
335
|
+
|
|
317
336
|
### Extensions
|
|
318
337
|
|
|
319
338
|
The following extensions provide descriptor conversion and text-based protobuf formats when reflection metadata is available. Most applications only need the binary APIs above.
|
|
@@ -332,73 +351,53 @@ Protocol Buffers [Text Format](https://protobuf.dev/reference/protobuf/textforma
|
|
|
332
351
|
|
|
333
352
|
## Conformance
|
|
334
353
|
|
|
335
|
-
protobuf.js
|
|
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.
|
|
355
|
+
|
|
356
|
+
<!-- BEGIN CONFORMANCE DATA -->
|
|
336
357
|
|
|
337
358
|
| Category | Total | Required | Recommended |
|
|
338
359
|
| ---------- | ------------------: | ------------------: | ------------------: |
|
|
339
360
|
| Binary | 100.00% (2835/2835) | 100.00% (1958/1958) | 100.00% (877/877) |
|
|
340
361
|
| ↳ Proto2 | 100.00% (707/707) | 100.00% (489/489) | 100.00% (218/218) |
|
|
341
362
|
| ↳ Proto3 | 100.00% (707/707) | 100.00% (486/486) | 100.00% (221/221) |
|
|
342
|
-
| ↳ Editions | 100.00% (
|
|
363
|
+
| ↳ Editions | 100.00% (1421/1421) | 100.00% (983/983) | 100.00% (438/438) |
|
|
343
364
|
| ProtoJSON | 100.00% (2796/2796) | 100.00% (2362/2362) | 100.00% (434/434) |
|
|
344
365
|
| TextFormat | 100.00% (909/909) | 100.00% (845/845) | 100.00% (64/64) |
|
|
345
366
|
| Overall | 100.00% (6540/6540) | 100.00% (5165/5165) | 100.00% (1375/1375) |
|
|
346
367
|
|
|
368
|
+
<!-- END CONFORMANCE DATA -->
|
|
369
|
+
|
|
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).
|
|
371
|
+
|
|
347
372
|
## Performance
|
|
348
373
|
|
|
349
|
-
In both reflection and reflection-free modes, protobuf.js builds specialized encoders and decoders
|
|
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.
|
|
350
375
|
|
|
351
|
-
The repository includes a [small benchmark](./bench).
|
|
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.
|
|
352
377
|
|
|
353
|
-
|
|
354
|
-
<summary>Benchmark run on AMD Ryzen 9 9950X3D with Node.js 24.15.0</summary>
|
|
378
|
+
<!-- BEGIN BENCHMARK DATA -->
|
|
355
379
|
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
JSON decode x 1,409,923 ops/sec ±0.11% (97 runs sampled)
|
|
376
|
-
protoc-gen-js x 947,647 ops/sec ±0.15% (99 runs sampled)
|
|
377
|
-
protoc-gen-es x 731,819 ops/sec ±0.28% (98 runs sampled)
|
|
378
|
-
|
|
379
|
-
protobuf.js static was fastest
|
|
380
|
-
protobuf.js reflect was 0.3% ops/sec slower (factor 1.0)
|
|
381
|
-
JSON decode was 78.2% ops/sec slower (factor 4.6)
|
|
382
|
-
protoc-gen-js was 85.3% ops/sec slower (factor 6.8)
|
|
383
|
-
protoc-gen-es was 88.7% ops/sec slower (factor 8.8)
|
|
384
|
-
|
|
385
|
-
benchmarking round-trip performance ...
|
|
386
|
-
|
|
387
|
-
protobuf.js reflect x 1,310,677 ops/sec ±0.21% (97 runs sampled)
|
|
388
|
-
protobuf.js static x 1,310,926 ops/sec ±0.26% (101 runs sampled)
|
|
389
|
-
JSON encode/decode x 741,714 ops/sec ±0.24% (99 runs sampled)
|
|
390
|
-
protoc-gen-js x 472,844 ops/sec ±0.09% (96 runs sampled)
|
|
391
|
-
protoc-gen-es x 254,044 ops/sec ±0.05% (101 runs sampled)
|
|
392
|
-
|
|
393
|
-
protobuf.js reflect was fastest
|
|
394
|
-
protobuf.js static was 0.0% ops/sec slower (factor 1.0)
|
|
395
|
-
JSON encode/decode was 43.4% ops/sec slower (factor 1.8)
|
|
396
|
-
protoc-gen-js was 63.9% ops/sec slower (factor 2.8)
|
|
397
|
-
protoc-gen-es was 80.6% ops/sec slower (factor 5.2)
|
|
398
|
-
```
|
|
399
|
-
</details>
|
|
380
|
+

|
|
381
|
+
|
|
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 |
|
|
387
|
+
|
|
388
|
+

|
|
389
|
+
|
|
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 |
|
|
395
|
+
|
|
396
|
+
<!-- END BENCHMARK DATA -->
|
|
397
|
+
|
|
398
|
+
[Structured results](./bench/results/latest.json) of this run are available as committed artifacts.
|
|
400
399
|
|
|
401
|
-
|
|
400
|
+
To run the benchmark yourself on your own hardware:
|
|
402
401
|
|
|
403
402
|
```sh
|
|
404
403
|
npm --prefix bench install
|