protobufjs 7.2.6 → 7.3.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +50 -63
- package/index.d.ts +1 -1
- package/package.json +3 -2
- package/src/parse.js +18 -1
- package/src/type.js +1 -1
- package/dist/light/protobuf.js +0 -7381
- package/dist/light/protobuf.js.map +0 -1
- package/dist/light/protobuf.min.js +0 -8
- package/dist/light/protobuf.min.js.map +0 -1
- package/dist/minimal/protobuf.js +0 -2736
- package/dist/minimal/protobuf.js.map +0 -1
- package/dist/minimal/protobuf.min.js +0 -8
- package/dist/minimal/protobuf.min.js.map +0 -1
- package/dist/protobuf.js +0 -9088
- package/dist/protobuf.js.map +0 -1
- package/dist/protobuf.min.js +0 -8
- package/dist/protobuf.min.js.map +0 -1
package/README.md
CHANGED
|
@@ -1,9 +1,15 @@
|
|
|
1
|
-
<h1><p align="center"><img alt="protobuf.js" src="https://github.com/
|
|
2
|
-
<p align="center"
|
|
1
|
+
<h1><p align="center"><img alt="protobuf.js" src="https://github.com/protobufjs/protobuf.js/raw/master/pbjs.svg" height="100" /><br/>protobuf.js</p></h1>
|
|
2
|
+
<p align="center">
|
|
3
|
+
<a href="https://github.com/protobufjs/protobuf.js/actions/workflows/test.yml"><img src="https://img.shields.io/github/actions/workflow/status/protobufjs/protobuf.js/test.yml?branch=master&label=build&logo=github" alt=""></a>
|
|
4
|
+
<a href="https://github.com/protobufjs/protobuf.js/actions/workflows/release.yaml"><img src="https://img.shields.io/github/actions/workflow/status/protobufjs/protobuf.js/release.yaml?branch=master&label=release&logo=github" alt=""></a>
|
|
5
|
+
<a href="https://npmjs.org/package/protobufjs"><img src="https://img.shields.io/npm/v/protobufjs.svg?logo=npm" alt=""></a>
|
|
6
|
+
<a href="https://npmjs.org/package/protobufjs"><img src="https://img.shields.io/npm/dm/protobufjs.svg?label=downloads&logo=npm" alt=""></a>
|
|
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
|
+
</p>
|
|
3
9
|
|
|
4
|
-
**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://
|
|
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/)).
|
|
5
11
|
|
|
6
|
-
**protobuf.js** is a pure JavaScript implementation with [TypeScript](https://www.typescriptlang.org) support for [
|
|
12
|
+
**protobuf.js** is a pure JavaScript implementation with [TypeScript](https://www.typescriptlang.org) support for [Node.js](https://nodejs.org) and the browser. It's easy to use, does not sacrifice on performance, has good conformance and works out of the box with [.proto](https://protobuf.dev/programming-guides/proto3/) files!
|
|
7
13
|
|
|
8
14
|
Contents
|
|
9
15
|
--------
|
|
@@ -42,68 +48,49 @@ Contents
|
|
|
42
48
|
Installation
|
|
43
49
|
---------------
|
|
44
50
|
|
|
45
|
-
###
|
|
51
|
+
### Node.js
|
|
46
52
|
|
|
47
|
-
```
|
|
48
|
-
|
|
53
|
+
```sh
|
|
54
|
+
npm install protobufjs --save
|
|
49
55
|
```
|
|
50
56
|
|
|
51
57
|
```js
|
|
58
|
+
// Static code + Reflection + .proto parser
|
|
52
59
|
var protobuf = require("protobufjs");
|
|
53
|
-
```
|
|
54
60
|
|
|
55
|
-
|
|
61
|
+
// Static code + Reflection
|
|
62
|
+
var protobuf = require("protobufjs/light");
|
|
56
63
|
|
|
64
|
+
// Static code only
|
|
65
|
+
var protobuf = require("protobufjs/minimal");
|
|
57
66
|
```
|
|
58
|
-
$> npm install protobufjs-cli [--save --save-prefix=~]
|
|
59
|
-
```
|
|
60
|
-
|
|
61
|
-
**Note** that this library's versioning scheme is not semver-compatible for historical reasons. For guaranteed backward compatibility, always depend on `~6.A.B` instead of `^6.A.B` (hence the `--save-prefix` above).
|
|
62
|
-
|
|
63
|
-
### Browsers
|
|
64
67
|
|
|
65
|
-
|
|
68
|
+
The optional [command line utility](./cli/) to generate static code and reflection bundles lives in the `protobufjs-cli` package and can be installed separately:
|
|
66
69
|
|
|
67
|
-
```
|
|
68
|
-
|
|
70
|
+
```sh
|
|
71
|
+
npm install protobufjs-cli --save-dev
|
|
69
72
|
```
|
|
70
73
|
|
|
71
|
-
|
|
74
|
+
### Browsers
|
|
72
75
|
|
|
73
|
-
|
|
76
|
+
Pick the variant matching your needs and replace the version tag with the exact [release](https://github.com/protobufjs/protobuf.js/tags) your project depends upon. For example, to use the minified full variant:
|
|
77
|
+
|
|
78
|
+
```html
|
|
74
79
|
<script src="//cdn.jsdelivr.net/npm/protobufjs@7.X.X/dist/protobuf.min.js"></script>
|
|
75
80
|
```
|
|
76
81
|
|
|
77
|
-
**Remember** to replace the version tag with the exact [release](https://github.com/protobufjs/protobuf.js/tags) your project depends upon.
|
|
78
|
-
|
|
79
|
-
The library supports CommonJS and AMD loaders and also exports globally as `protobuf`.
|
|
80
|
-
|
|
81
|
-
### Distributions
|
|
82
|
-
|
|
83
|
-
Where bundle size is a factor, there are additional stripped-down versions of the [full library][dist-full] (~19kb gzipped) available that exclude certain functionality:
|
|
84
|
-
|
|
85
|
-
* When working with JSON descriptors (i.e. generated by [pbjs](cli/README.md#pbjs-for-javascript)) and/or reflection only, see the [light library][dist-light] (~16kb gzipped) that excludes the parser. CommonJS entry point is:
|
|
86
|
-
|
|
87
|
-
```js
|
|
88
|
-
var protobuf = require("protobufjs/light");
|
|
89
|
-
```
|
|
90
|
-
|
|
91
|
-
* When working with statically generated code only, see the [minimal library][dist-minimal] (~6.5kb gzipped) that also excludes reflection. CommonJS entry point is:
|
|
92
|
-
|
|
93
|
-
```js
|
|
94
|
-
var protobuf = require("protobufjs/minimal");
|
|
95
|
-
```
|
|
96
|
-
|
|
97
82
|
| Distribution | Location
|
|
98
|
-
|
|
99
|
-
| Full
|
|
100
|
-
| Light
|
|
101
|
-
| Minimal
|
|
83
|
+
|--------------|--------------------------------------------------------
|
|
84
|
+
| Full | <https://cdn.jsdelivr.net/npm/protobufjs/dist/>
|
|
85
|
+
| Light | <https://cdn.jsdelivr.net/npm/protobufjs/dist/light/>
|
|
86
|
+
| Minimal | <https://cdn.jsdelivr.net/npm/protobufjs/dist/minimal/>
|
|
87
|
+
|
|
88
|
+
All variants support CommonJS and AMD loaders and export globally as `window.protobuf`.
|
|
102
89
|
|
|
103
90
|
Usage
|
|
104
91
|
-----
|
|
105
92
|
|
|
106
|
-
Because JavaScript is a dynamically typed language, protobuf.js
|
|
93
|
+
Because JavaScript is a dynamically typed language, protobuf.js utilizes the concept of a **valid message** in order to provide the best possible [performance](#performance) (and, as a side product, proper typings):
|
|
107
94
|
|
|
108
95
|
### Valid message
|
|
109
96
|
|
|
@@ -111,7 +98,7 @@ Because JavaScript is a dynamically typed language, protobuf.js introduces the c
|
|
|
111
98
|
|
|
112
99
|
There are two possible types of valid messages and the encoder is able to work with both of these for convenience:
|
|
113
100
|
|
|
114
|
-
* **Message instances** (explicit instances of message classes with default values on their prototype)
|
|
101
|
+
* **Message instances** (explicit instances of message classes with default values on their prototype) naturally satisfy the requirements of a valid message and
|
|
115
102
|
* **Plain JavaScript objects** that just so happen to be composed in a way satisfying the requirements of a valid message as well.
|
|
116
103
|
|
|
117
104
|
In a nutshell, the wire format writer understands the following types:
|
|
@@ -126,11 +113,11 @@ In a nutshell, the wire format writer understands the following types:
|
|
|
126
113
|
| bytes | `Uint8Array` (optimal)<br />`Buffer` (optimal under node)<br />`Array.<number>` (8 bit integers) | `base64.decode(value)` if a `string`<br />`Object` with non-zero `.length` is assumed to be buffer-like
|
|
127
114
|
| enum | `number` (32 bit integer) | Looks up the numeric id if a `string`
|
|
128
115
|
| message | Valid message | `Message.fromObject(value)`
|
|
116
|
+
| repeated T | `Array<T>` | Copy
|
|
117
|
+
| map<K, V> | `Object<K,V>` | Copy
|
|
129
118
|
|
|
130
119
|
* Explicit `undefined` and `null` are considered as not set if the field is optional.
|
|
131
|
-
*
|
|
132
|
-
* Map fields are `Object.<string,T>` with the key being the string representation of the respective value or an 8 characters long binary hash string for `Long`-likes.
|
|
133
|
-
* Types marked as *optimal* provide the best performance because no conversion step (i.e. number to low and high bits or base64 string to buffer) is required.
|
|
120
|
+
* Maps are objects where the key is the string representation of the respective value or an 8 characters long hash string for `Long`-likes.
|
|
134
121
|
|
|
135
122
|
### Toolset
|
|
136
123
|
|
|
@@ -210,7 +197,7 @@ For reference, the following diagram aims to display relationships between the d
|
|
|
210
197
|
|
|
211
198
|
<p align="center"><img alt="Toolset Diagram" src="https://protobufjs.github.io/protobuf.js/toolset.svg" /></p>
|
|
212
199
|
|
|
213
|
-
> In other words: `verify` indicates that calling `create` or `encode` directly on the plain object will [result in a valid message respectively] succeed. `fromObject`, on the other hand, does conversion from a broader range of plain objects to create valid messages. ([ref](https://github.com/
|
|
200
|
+
> In other words: `verify` indicates that calling `create` or `encode` directly on the plain object will [result in a valid message respectively] succeed. `fromObject`, on the other hand, does conversion from a broader range of plain objects to create valid messages. ([ref](https://github.com/protobufjs/protobuf.js/issues/748#issuecomment-291925749))
|
|
214
201
|
|
|
215
202
|
Examples
|
|
216
203
|
--------
|
|
@@ -482,13 +469,13 @@ greeter.sayHello({ name: 'you' })
|
|
|
482
469
|
});
|
|
483
470
|
```
|
|
484
471
|
|
|
485
|
-
There is also an [example for streaming RPC](https://github.com/
|
|
472
|
+
There is also an [example for streaming RPC](https://github.com/protobufjs/protobuf.js/blob/master/examples/streaming-rpc.js).
|
|
486
473
|
|
|
487
474
|
Note that the service API is meant for clients. Implementing a server-side endpoint pretty much always requires transport channel (i.e. http, websocket, etc.) specific code with the only common denominator being that it decodes and encodes messages.
|
|
488
475
|
|
|
489
476
|
### Usage with TypeScript
|
|
490
477
|
|
|
491
|
-
The library ships with its own [type definitions](https://github.com/
|
|
478
|
+
The library ships with its own [type definitions](https://github.com/protobufjs/protobuf.js/blob/master/index.d.ts) and modern editors like [Visual Studio Code](https://code.visualstudio.com/) will automatically detect and use them for code completion.
|
|
492
479
|
|
|
493
480
|
The npm package depends on [@types/node](https://www.npmjs.com/package/@types/node) because of `Buffer` and [@types/long](https://www.npmjs.com/package/@types/long) because of `Long`. If you are not building for node and/or not using long.js, it should be safe to exclude them manually.
|
|
494
481
|
|
|
@@ -595,18 +582,18 @@ Other notes:
|
|
|
595
582
|
* Default values must be specified as arguments to the decorator instead of using a property initializer for proper prototype behavior.
|
|
596
583
|
* Property names on decorated classes must not be renamed on compile time (i.e. by a minifier) because decorators just receive the original field name as a string.
|
|
597
584
|
|
|
598
|
-
**ProTip!** Not as pretty, but you can [use decorators in plain JavaScript](https://github.com/
|
|
585
|
+
**ProTip!** Not as pretty, but you can [use decorators in plain JavaScript](https://github.com/protobufjs/protobuf.js/blob/master/examples/js-decorators.js) as well.
|
|
599
586
|
|
|
600
587
|
Additional documentation
|
|
601
588
|
------------------------
|
|
602
589
|
|
|
603
590
|
#### Protocol Buffers
|
|
604
|
-
* [Google's Developer Guide](https://
|
|
591
|
+
* [Google's Developer Guide](https://protobuf.dev/overview/)
|
|
605
592
|
|
|
606
593
|
#### protobuf.js
|
|
607
594
|
* [API Documentation](https://protobufjs.github.io/protobuf.js)
|
|
608
|
-
* [CHANGELOG](https://github.com/
|
|
609
|
-
* [Frequently asked questions](https://github.com/
|
|
595
|
+
* [CHANGELOG](https://github.com/protobufjs/protobuf.js/blob/master/CHANGELOG.md)
|
|
596
|
+
* [Frequently asked questions](https://github.com/protobufjs/protobuf.js/wiki) on our wiki
|
|
610
597
|
|
|
611
598
|
#### Community
|
|
612
599
|
* [Questions and answers](http://stackoverflow.com/search?tab=newest&q=protobuf.js) on StackOverflow
|
|
@@ -666,13 +653,13 @@ These results are achieved by
|
|
|
666
653
|
* using node-specific functionality where beneficial and, of course
|
|
667
654
|
* avoiding unnecessary operations through splitting up [the toolset](#toolset).
|
|
668
655
|
|
|
669
|
-
You can also run [the benchmark](https://github.com/
|
|
656
|
+
You can also run [the benchmark](https://github.com/protobufjs/protobuf.js/blob/master/bench/index.js) ...
|
|
670
657
|
|
|
671
658
|
```
|
|
672
659
|
$> npm run bench
|
|
673
660
|
```
|
|
674
661
|
|
|
675
|
-
and [the profiler](https://github.com/
|
|
662
|
+
and [the profiler](https://github.com/protobufjs/protobuf.js/blob/master/bench/prof.js) yourself (the latter requires a recent version of node):
|
|
676
663
|
|
|
677
664
|
```
|
|
678
665
|
$> npm run prof <encode|decode|encode-browser|decode-browser> [iterations=10000000]
|
|
@@ -686,10 +673,10 @@ Compatibility
|
|
|
686
673
|
* Works in all modern and not-so-modern browsers except IE8.
|
|
687
674
|
* Because the internals of this package do not rely on `google/protobuf/descriptor.proto`, options are parsed and presented literally.
|
|
688
675
|
* If typed arrays are not supported by the environment, plain arrays will be used instead.
|
|
689
|
-
* Support for pre-ES5 environments (except IE8) can be achieved by [using a polyfill](https://github.com/
|
|
690
|
-
* Support for [Content Security Policy](https://w3c.github.io/webappsec-csp/)-restricted environments (like Chrome extensions without
|
|
676
|
+
* Support for pre-ES5 environments (except IE8) can be achieved by [using a polyfill](https://github.com/protobufjs/protobuf.js/blob/master/lib/polyfill.js).
|
|
677
|
+
* Support for [Content Security Policy](https://w3c.github.io/webappsec-csp/)-restricted environments (like Chrome extensions without unsafe-eval) can be achieved by generating and using static code instead.
|
|
691
678
|
* If a proper way to work with 64 bit values (uint64, int64 etc.) is required, just install [long.js](https://github.com/dcodeIO/long.js) alongside this library. All 64 bit numbers will then be returned as a `Long` instance instead of a possibly unsafe JavaScript number ([see](https://github.com/dcodeIO/long.js)).
|
|
692
|
-
* For descriptor.proto interoperability, see [ext/descriptor](https://github.com/
|
|
679
|
+
* For descriptor.proto interoperability, see [ext/descriptor](https://github.com/protobufjs/protobuf.js/tree/master/ext/descriptor)
|
|
693
680
|
|
|
694
681
|
Building
|
|
695
682
|
--------
|
|
@@ -697,7 +684,7 @@ Building
|
|
|
697
684
|
To build the library or its components yourself, clone it from GitHub and install the development dependencies:
|
|
698
685
|
|
|
699
686
|
```
|
|
700
|
-
$> git clone https://github.com/
|
|
687
|
+
$> git clone https://github.com/protobufjs/protobuf.js.git
|
|
701
688
|
$> cd protobuf.js
|
|
702
689
|
$> npm install
|
|
703
690
|
```
|
|
@@ -735,6 +722,6 @@ By default, protobuf.js integrates into any browserify build-process without req
|
|
|
735
722
|
protobuf.configure();
|
|
736
723
|
```
|
|
737
724
|
|
|
738
|
-
* If you have any special requirements, there is [the bundler](https://github.com/
|
|
725
|
+
* If you have any special requirements, there is [the bundler](https://github.com/protobufjs/protobuf.js/blob/master/scripts/bundle.js) for reference.
|
|
739
726
|
|
|
740
727
|
**License:** [BSD 3-Clause License](https://opensource.org/licenses/BSD-3-Clause)
|
package/index.d.ts
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "protobufjs",
|
|
3
|
-
"version": "7.
|
|
3
|
+
"version": "7.3.1",
|
|
4
4
|
"versionScheme": "~",
|
|
5
5
|
"description": "Protocol Buffers for JavaScript (& TypeScript).",
|
|
6
6
|
"author": "Daniel Wirtz <dcode+protobufjs@dcode.io>",
|
|
@@ -59,7 +59,8 @@
|
|
|
59
59
|
"@protobufjs/pool": "^1.1.0",
|
|
60
60
|
"@protobufjs/utf8": "^1.1.0",
|
|
61
61
|
"@types/node": ">=13.7.0",
|
|
62
|
-
"long": "^5.0.0"
|
|
62
|
+
"long": "^5.0.0",
|
|
63
|
+
"packument": "^2.0.0"
|
|
63
64
|
},
|
|
64
65
|
"devDependencies": {
|
|
65
66
|
"benchmark": "^2.1.4",
|
package/src/parse.js
CHANGED
|
@@ -144,7 +144,24 @@ function parse(source, root, options) {
|
|
|
144
144
|
else
|
|
145
145
|
target.push([ start = parseId(next()), skip("to", true) ? parseId(next()) : start ]);
|
|
146
146
|
} while (skip(",", true));
|
|
147
|
-
|
|
147
|
+
var dummy = {options: undefined};
|
|
148
|
+
dummy.setOption = function(name, value) {
|
|
149
|
+
if (this.options === undefined) this.options = {};
|
|
150
|
+
this.options[name] = value;
|
|
151
|
+
};
|
|
152
|
+
ifBlock(
|
|
153
|
+
dummy,
|
|
154
|
+
function parseRange_block(token) {
|
|
155
|
+
/* istanbul ignore else */
|
|
156
|
+
if (token === "option") {
|
|
157
|
+
parseOption(dummy, token); // skip
|
|
158
|
+
skip(";");
|
|
159
|
+
} else
|
|
160
|
+
throw illegal(token);
|
|
161
|
+
},
|
|
162
|
+
function parseRange_line() {
|
|
163
|
+
parseInlineOptions(dummy); // skip
|
|
164
|
+
});
|
|
148
165
|
}
|
|
149
166
|
|
|
150
167
|
function parseNumber(token, insideTryCatch) {
|
package/src/type.js
CHANGED
|
@@ -224,7 +224,7 @@ function clearCache(type) {
|
|
|
224
224
|
* @property {Object.<string,IOneOf>} [oneofs] Oneof descriptors
|
|
225
225
|
* @property {Object.<string,IField>} fields Field descriptors
|
|
226
226
|
* @property {number[][]} [extensions] Extension ranges
|
|
227
|
-
* @property {number[]
|
|
227
|
+
* @property {Array.<number[]|string>} [reserved] Reserved ranges
|
|
228
228
|
* @property {boolean} [group=false] Whether a legacy group or not
|
|
229
229
|
*/
|
|
230
230
|
|