protobufjs 4.1.2 → 5.0.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/.travis.yml +3 -1
- package/README.md +147 -25
- package/bin/pbjs +2 -2
- package/bower.json +3 -3
- package/cli/pbjs/targets/amd.js +1 -1
- package/cli/pbjs/targets/json.js +9 -1
- package/cli/pbjs/targets/proto.js +48 -24
- package/cli/pbjs/util.js +1 -1
- package/cli/pbjs.js +9 -2
- package/dist/README.md +10 -10
- package/dist/{ProtoBuf-light.js → protobuf-light.js} +207 -152
- package/dist/protobuf-light.min.js +94 -0
- package/dist/protobuf-light.min.js.gz +0 -0
- package/dist/protobuf-light.min.map +8 -0
- package/dist/{ProtoBuf.js → protobuf.js} +265 -175
- package/dist/protobuf.min.js +116 -0
- package/dist/protobuf.min.js.gz +0 -0
- package/dist/protobuf.min.map +8 -0
- package/docs/ProtoBuf.Builder.Message.html +1473 -967
- package/docs/ProtoBuf.Builder.Service.html +266 -197
- package/docs/ProtoBuf.Builder.html +758 -542
- package/docs/ProtoBuf.DotProto.Parser.html +223 -161
- package/docs/ProtoBuf.DotProto.Tokenizer.html +344 -248
- package/docs/ProtoBuf.DotProto.html +20 -12
- package/docs/ProtoBuf.Element.html +554 -554
- package/docs/ProtoBuf.Map.html +158 -123
- package/docs/ProtoBuf.Reflect.Element.html +286 -143
- package/docs/ProtoBuf.Reflect.Enum.Value.html +329 -228
- package/docs/ProtoBuf.Reflect.Enum.html +757 -537
- package/docs/ProtoBuf.Reflect.Extension.html +73 -56
- package/docs/ProtoBuf.Reflect.Message.ExtensionField.html +1013 -740
- package/docs/ProtoBuf.Reflect.Message.Field.html +926 -649
- package/docs/ProtoBuf.Reflect.Message.OneOf.html +327 -245
- package/docs/ProtoBuf.Reflect.Message.html +919 -652
- package/docs/ProtoBuf.Reflect.Namespace.html +648 -447
- package/docs/ProtoBuf.Reflect.Service.Method.html +363 -251
- package/docs/ProtoBuf.Reflect.Service.RPCMethod.html +545 -397
- package/docs/ProtoBuf.Reflect.Service.html +721 -511
- package/docs/ProtoBuf.Reflect.T.html +268 -197
- package/docs/ProtoBuf.Reflect.html +20 -12
- package/docs/ProtoBuf.Util.html +169 -118
- package/docs/ProtoBuf.html +840 -628
- package/docs/ProtoBuf.js.html +271 -180
- package/docs/fonts/OpenSans-Bold-webfont.eot +0 -0
- package/docs/fonts/OpenSans-Bold-webfont.svg +1830 -0
- package/docs/fonts/OpenSans-Bold-webfont.woff +0 -0
- package/docs/fonts/OpenSans-BoldItalic-webfont.eot +0 -0
- package/docs/fonts/OpenSans-BoldItalic-webfont.svg +1830 -0
- package/docs/fonts/OpenSans-BoldItalic-webfont.woff +0 -0
- package/docs/fonts/OpenSans-Italic-webfont.eot +0 -0
- package/docs/fonts/OpenSans-Italic-webfont.svg +1830 -0
- package/docs/fonts/OpenSans-Italic-webfont.woff +0 -0
- package/docs/fonts/OpenSans-Light-webfont.eot +0 -0
- package/docs/fonts/OpenSans-Light-webfont.svg +1831 -0
- package/docs/fonts/OpenSans-Light-webfont.woff +0 -0
- package/docs/fonts/OpenSans-LightItalic-webfont.eot +0 -0
- package/docs/fonts/OpenSans-LightItalic-webfont.svg +1835 -0
- package/docs/fonts/OpenSans-LightItalic-webfont.woff +0 -0
- package/docs/fonts/OpenSans-Regular-webfont.eot +0 -0
- package/docs/fonts/OpenSans-Regular-webfont.svg +1831 -0
- package/docs/fonts/OpenSans-Regular-webfont.woff +0 -0
- package/docs/index.html +7 -5
- package/docs/styles/jsdoc-default.css +95 -75
- package/docs/styles/prettify-tomorrow.css +1 -1
- package/donate.png +0 -0
- package/examples/protoify/json.js +123 -123
- package/examples/protoify/json.json +123 -123
- package/examples/websocket/server.js +4 -4
- package/externs/{ProtoBuf.js → protobuf.js} +933 -922
- package/index.js +1 -18
- package/jsdoc.json +1 -1
- package/package.json +11 -11
- package/protobuf.png +0 -0
- package/scripts/build.js +53 -58
- package/src/ProtoBuf/Builder/Message.js +18 -9
- package/src/ProtoBuf/Builder/Service.js +3 -0
- package/src/ProtoBuf/Builder.js +34 -10
- package/src/ProtoBuf/DotProto/Parser.js +58 -23
- package/src/ProtoBuf/Reflect/Element.js +17 -4
- package/src/ProtoBuf/Reflect/Message/Field.js +6 -5
- package/src/ProtoBuf/Reflect/Message.js +9 -4
- package/src/ProtoBuf/Util.js +116 -116
- package/src/bower.json +2 -2
- package/src/google/protobuf/descriptor.json +55 -15
- package/src/{ProtoBuf.js → protobuf.js} +0 -0
- package/src/wrap.js +4 -4
- package/tests/bench.txt +373 -373
- package/tests/complex.json +8 -1
- package/tests/custom-options.json +169 -169
- package/tests/extend.json +71 -71
- package/tests/imports-weak.proto +7 -0
- package/tests/imports.json +83 -83
- package/tests/nodeunit-browser/nodeunit.css +70 -70
- package/tests/nodeunit-browser/nodeunit.js +2108 -2108
- package/tests/options.json +32 -32
- package/tests/proto2js/Bar.json +46 -46
- package/tests/suite.js +107 -82
- package/ProtoBuf.png +0 -0
- package/dist/ProtoBuf-light.min.js +0 -87
- package/dist/ProtoBuf-light.min.js.gz +0 -0
- package/dist/ProtoBuf-light.min.map +0 -8
- package/dist/ProtoBuf.min.js +0 -108
- package/dist/ProtoBuf.min.js.gz +0 -0
- package/dist/ProtoBuf.min.map +0 -8
- package/externs/ByteBuffer.js +0 -767
- package/externs/Long.js +0 -328
- package/sandbox/gapi/googleapis/google/api/annotations.proto +0 -29
- package/sandbox/gapi/googleapis/google/api/http.proto +0 -245
- package/sandbox/gapi/googleapis/google/datastore/v1beta3/datastore.proto +0 -281
- package/sandbox/gapi/googleapis/google/datastore/v1beta3/entity.proto +0 -189
- package/sandbox/gapi/googleapis/google/datastore/v1beta3/query.proto +0 -281
- package/sandbox/gapi/googleapis/google/longrunning/operations.proto +0 -144
- package/sandbox/gapi/googleapis/google/protobuf/any.proto +0 -98
- package/sandbox/gapi/googleapis/google/protobuf/any_test.proto +0 -41
- package/sandbox/gapi/googleapis/google/protobuf/api.proto +0 -201
- package/sandbox/gapi/googleapis/google/protobuf/descriptor.proto +0 -773
- package/sandbox/gapi/googleapis/google/protobuf/duration.proto +0 -95
- package/sandbox/gapi/googleapis/google/protobuf/empty.proto +0 -50
- package/sandbox/gapi/googleapis/google/protobuf/field_mask.proto +0 -167
- package/sandbox/gapi/googleapis/google/protobuf/map_lite_unittest.proto +0 -130
- package/sandbox/gapi/googleapis/google/protobuf/map_proto2_unittest.proto +0 -60
- package/sandbox/gapi/googleapis/google/protobuf/map_unittest.proto +0 -129
- package/sandbox/gapi/googleapis/google/protobuf/map_unittest_proto3.proto +0 -120
- package/sandbox/gapi/googleapis/google/protobuf/source_context.proto +0 -47
- package/sandbox/gapi/googleapis/google/protobuf/struct.proto +0 -94
- package/sandbox/gapi/googleapis/google/protobuf/timestamp.proto +0 -107
- package/sandbox/gapi/googleapis/google/protobuf/type.proto +0 -176
- package/sandbox/gapi/googleapis/google/protobuf/unittest.proto +0 -878
- package/sandbox/gapi/googleapis/google/protobuf/unittest_arena.proto +0 -46
- package/sandbox/gapi/googleapis/google/protobuf/unittest_custom_options.proto +0 -394
- package/sandbox/gapi/googleapis/google/protobuf/unittest_drop_unknown_fields.proto +0 -58
- package/sandbox/gapi/googleapis/google/protobuf/unittest_embed_optimize_for.proto +0 -51
- package/sandbox/gapi/googleapis/google/protobuf/unittest_empty.proto +0 -38
- package/sandbox/gapi/googleapis/google/protobuf/unittest_enormous_descriptor.proto +0 -1048
- package/sandbox/gapi/googleapis/google/protobuf/unittest_import.proto +0 -66
- package/sandbox/gapi/googleapis/google/protobuf/unittest_import_lite.proto +0 -52
- package/sandbox/gapi/googleapis/google/protobuf/unittest_import_proto3.proto +0 -68
- package/sandbox/gapi/googleapis/google/protobuf/unittest_import_public.proto +0 -41
- package/sandbox/gapi/googleapis/google/protobuf/unittest_import_public_lite.proto +0 -43
- package/sandbox/gapi/googleapis/google/protobuf/unittest_import_public_proto3.proto +0 -42
- package/sandbox/gapi/googleapis/google/protobuf/unittest_lite.proto +0 -385
- package/sandbox/gapi/googleapis/google/protobuf/unittest_lite_imports_nonlite.proto +0 -44
- package/sandbox/gapi/googleapis/google/protobuf/unittest_mset.proto +0 -82
- package/sandbox/gapi/googleapis/google/protobuf/unittest_mset_wire_format.proto +0 -52
- package/sandbox/gapi/googleapis/google/protobuf/unittest_no_arena.proto +0 -202
- package/sandbox/gapi/googleapis/google/protobuf/unittest_no_arena_import.proto +0 -37
- package/sandbox/gapi/googleapis/google/protobuf/unittest_no_arena_lite.proto +0 -42
- package/sandbox/gapi/googleapis/google/protobuf/unittest_no_field_presence.proto +0 -138
- package/sandbox/gapi/googleapis/google/protobuf/unittest_no_generic_services.proto +0 -54
- package/sandbox/gapi/googleapis/google/protobuf/unittest_optimize_for.proto +0 -67
- package/sandbox/gapi/googleapis/google/protobuf/unittest_preserve_unknown_enum.proto +0 -71
- package/sandbox/gapi/googleapis/google/protobuf/unittest_preserve_unknown_enum2.proto +0 -50
- package/sandbox/gapi/googleapis/google/protobuf/unittest_proto3.proto +0 -388
- package/sandbox/gapi/googleapis/google/protobuf/unittest_proto3_arena.proto +0 -206
- package/sandbox/gapi/googleapis/google/protobuf/unittest_well_known_types.proto +0 -112
- package/sandbox/gapi/googleapis/google/protobuf/unknown_enum_test.proto +0 -62
- package/sandbox/gapi/googleapis/google/protobuf/wrappers.proto +0 -117
- package/sandbox/gapi/googleapis/google/rpc/code.proto +0 -190
- package/sandbox/gapi/googleapis/google/rpc/error_details.proto +0 -157
- package/sandbox/gapi/googleapis/google/rpc/status.proto +0 -90
- package/sandbox/gapi/googleapis/google/type/color.proto +0 -163
- package/sandbox/gapi/googleapis/google/type/date.proto +0 -43
- package/sandbox/gapi/googleapis/google/type/dayofweek.proto +0 -50
- package/sandbox/gapi/googleapis/google/type/latlng.proto +0 -36
- package/sandbox/gapi/googleapis/google/type/money.proto +0 -40
- package/sandbox/gapi/googleapis/google/type/timeofday.proto +0 -42
- package/sandbox/gapi/test.js +0 -17
- package/sandbox/gapi/test.proto +0 -12
- package/sandbox/issue146/MyOptions.proto +0 -28
- package/sandbox/issue146/Sample.proto +0 -21
- package/sandbox/issue146/main.js +0 -3
- package/sandbox/issue147/enum.proto +0 -8
- package/sandbox/issue147/main.js +0 -3
- package/sandbox/issue182/commands.proto +0 -10
- package/sandbox/issue182/execute.js +0 -22
- package/sandbox/issue182/session_commands.proto +0 -14
- package/sandbox/issue289/A.proto +0 -8
- package/sandbox/issue289/B.proto +0 -8
- package/sandbox/issue289/common.proto +0 -5
- package/sandbox/issue289/main.js +0 -7
- package/sandbox/issue300/IAuth.proto +0 -14
- package/sandbox/issue300/Request.proto +0 -14
- package/sandbox/issue300/main.js +0 -26
- package/sandbox/issue42/innerextend.proto +0 -18
- package/sandbox/issue42/main.js +0 -8
- package/sandbox/issue42/outerextend.proto +0 -17
- package/tests/gtfs-realtime.proto +0 -552
- package/webpack.config.js +0 -9
package/.travis.yml
CHANGED
package/README.md
CHANGED
|
@@ -1,19 +1,16 @@
|
|
|
1
|
-
|
|
1
|
+
protobuf.js 5 [](https://travis-ci.org/dcodeIO/protobuf.js) [](https://www.paypal.com/cgi-bin/webscr?cmd=_donations&business=dcode%40dcode.io&item_name=%3C3%20protobuf.js)
|
|
2
2
|
=====================================
|
|
3
3
|
**Protocol Buffers** are a language-neutral, platform-neutral, extensible way of serializing structured data for use
|
|
4
4
|
in communications protocols, data storage, and more, originally designed at Google ([see](https://developers.google.com/protocol-buffers/docs/overview)).
|
|
5
5
|
|
|
6
|
-
**
|
|
6
|
+
**protobuf.js** is a pure JavaScript implementation on top of [bytebuffer.js](https://github.com/dcodeIO/bytebuffer.js)
|
|
7
7
|
including a .proto parser, message class building and simple encoding and decoding. There is no compilation step
|
|
8
8
|
required, it's super easy to use and it works out of the box on .proto files!
|
|
9
9
|
|
|
10
|
-
[](https://travis-ci.org/dcodeIO/ProtoBuf.js)
|
|
11
|
-
[](https://www.paypal.com/cgi-bin/webscr?cmd=_donations&business=info%40code-emitter.com&item_name=Open%20Source%3A%20ProtoBuf.js)
|
|
12
|
-
|
|
13
10
|
Getting started
|
|
14
11
|
---------------
|
|
15
12
|
* **Step 1:** Become familar with [Google's Protocol Buffers (protobuf)](https://developers.google.com/protocol-buffers/docs/overview)
|
|
16
|
-
* **Step 2:**
|
|
13
|
+
* **Step 2:** Read on or head straight to [our wiki](https://github.com/dcodeIO/protobuf.js/wiki) for additional information
|
|
17
14
|
* **Step 3:** Build something cool! :-)
|
|
18
15
|
|
|
19
16
|
Features
|
|
@@ -21,42 +18,167 @@ Features
|
|
|
21
18
|
* [RequireJS](http://requirejs.org/)/AMD compatible
|
|
22
19
|
* [node.js](http://nodejs.org)/CommonJS compatible, also available via [npm](https://npmjs.org/package/protobufjs)
|
|
23
20
|
* Browser compatible
|
|
24
|
-
* [Closure Compiler](https://developers.google.com/closure/compiler/) compatible (fully annotated, [externs](https://github.com/dcodeIO/
|
|
21
|
+
* [Closure Compiler](https://developers.google.com/closure/compiler/) compatible (fully annotated, [externs](https://github.com/dcodeIO/protobuf.js/tree/master/externs))
|
|
25
22
|
* Fully documented using [jsdoc3](https://github.com/jsdoc3/jsdoc)
|
|
26
23
|
* Well tested through [test.js](https://github.com/dcodeIO/test.js)
|
|
27
|
-
* [
|
|
24
|
+
* [bytebuffer.js](https://github.com/dcodeIO/bytebuffer.js) is the only production dependency
|
|
28
25
|
* Fully compatible to the official implementation including advanced features
|
|
29
26
|
* proto2js command line utility
|
|
30
27
|
|
|
28
|
+
Installation
|
|
29
|
+
------------
|
|
30
|
+
|
|
31
|
+
### node.js / CommonJS
|
|
32
|
+
|
|
33
|
+
```
|
|
34
|
+
$> npm install protobufjs
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
```js
|
|
38
|
+
var ProtoBuf = require("protobufjs");
|
|
39
|
+
...
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
### RequireJS / AMD
|
|
43
|
+
|
|
44
|
+
Requires [bytebuffer.js](http://github.com/dcodeIO/bytebuffer.js). Optionally depends on [long.js](https://github.com/dcodeIO/long.js) for long (int64) support. If you do not require long support, you can skip the Long.js config. RequireJS example:
|
|
45
|
+
|
|
46
|
+
```js
|
|
47
|
+
require(["protobuf"], function(ProtoBuf) {
|
|
48
|
+
...
|
|
49
|
+
});
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
Or as a module dependency:
|
|
53
|
+
|
|
54
|
+
```js
|
|
55
|
+
define("MyModule", ["protobuf"], function(ProtoBuf) {
|
|
56
|
+
...
|
|
57
|
+
});
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
### Browser
|
|
61
|
+
|
|
62
|
+
Requires [bytebuffer.js](http://github.com/dcodeIO/bytebuffer.js). Optionally depends on [long.js](https://github.com/dcodeIO/long.js) for long (int64) support. If you do not require long support, you can skip the Long.js include.
|
|
63
|
+
|
|
64
|
+
```html
|
|
65
|
+
<!-- Order is important -->
|
|
66
|
+
<script src="long.min.js"></script>
|
|
67
|
+
<script src="bytebuffer.min.js"></script>
|
|
68
|
+
<script src="protobuf.min.js"></script>
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
```js
|
|
72
|
+
var ProtoBuf = dcodeIO.ProtoBuf;
|
|
73
|
+
...
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
Getting started
|
|
77
|
+
---------------
|
|
78
|
+
|
|
79
|
+
*Note:* You'll need the full build to load .proto data. light builds are able to load JSON only.
|
|
80
|
+
|
|
81
|
+
### Loading .proto files
|
|
82
|
+
|
|
83
|
+
To load a .proto file, use:
|
|
84
|
+
|
|
85
|
+
**API:** `ProtoBuf.loadProtoFile(source[, callback[, builder]]):Builder|undefined`
|
|
86
|
+
|
|
87
|
+
```js
|
|
88
|
+
// Synchronously
|
|
89
|
+
var builder = ProtoBuf.loadProtoFile("path/to/file.proto");
|
|
90
|
+
|
|
91
|
+
// Asynchronously
|
|
92
|
+
ProtoBuf.loadProtoFile("path/to/file.proto", function(err, builder) {
|
|
93
|
+
...
|
|
94
|
+
});
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
`ProtoBuf.loadProtoFile` also accepts an object specifying the import root directory and the file to load as its first parameter: `{root: string, file: string}`. Additionally, an already created and then reused builder can be specified as the last argument, which is useful if all the definitions shall reside in a single namespace.
|
|
98
|
+
|
|
99
|
+
### Loading .proto strings
|
|
100
|
+
|
|
101
|
+
**API:** `ProtoBuf.loadProto(source[, builder][, filename]):Builder`
|
|
102
|
+
|
|
103
|
+
```js
|
|
104
|
+
var builder = ProtoBuf.loadProto(...protoString..., "myproto.proto");
|
|
105
|
+
```
|
|
106
|
+
|
|
107
|
+
### Loading JSON files and strings
|
|
108
|
+
|
|
109
|
+
To load the (raw) JSON counterpart generated through pbjs, use `ProtoBuf.loadJsonFile` respectively `ProtoBuf.loadJson`. It's the same API.
|
|
110
|
+
|
|
111
|
+
If you generated classes or modules with it, loading is done just by including respectively requiring the resulting file. Loading is handled transparently in this case.
|
|
112
|
+
|
|
113
|
+
When using JSON only, you can use protobuf-light.js or protobuf-light.min.js instead, which do NOT include the ProtoBuf.DotProto package for parsing and are therefore smaller.
|
|
114
|
+
|
|
115
|
+
Command line
|
|
116
|
+
------------
|
|
117
|
+
Since ProtoBuf.js 4.0.0 the library ships with the `pbjs` command line utility. With it it's possible to convert between .proto and JSON descriptors and even to generate the code required to access runtime structures as pure JS (classes), an AMD module or a CommonJS module.
|
|
118
|
+
|
|
119
|
+
```
|
|
120
|
+
|
|
121
|
+
_ |_ . _
|
|
122
|
+
|_)|_)|_) ProtoBuf.js v4.0.0-b3 https://github.com/dcodeIO/ProtoBuf.js
|
|
123
|
+
| '
|
|
124
|
+
|
|
125
|
+
CLI utility to convert between .proto and JSON syntax / to generate classes.
|
|
126
|
+
|
|
127
|
+
Usage: pbjs <filename> [options] [> outFile]
|
|
128
|
+
|
|
129
|
+
Options:
|
|
130
|
+
--help, -h Show help [boolean]
|
|
131
|
+
--version, -v Show version number [boolean]
|
|
132
|
+
--source, -s Specifies the source format. Valid formats are:
|
|
133
|
+
|
|
134
|
+
json Plain JSON descriptor
|
|
135
|
+
proto Plain .proto descriptor
|
|
136
|
+
|
|
137
|
+
--target, -t Specifies the target format. Valid formats are:
|
|
138
|
+
|
|
139
|
+
amd Runtime structures as AMD module
|
|
140
|
+
commonjs Runtime structures as CommonJS module
|
|
141
|
+
js Runtime structures
|
|
142
|
+
json Plain JSON descriptor
|
|
143
|
+
proto Plain .proto descriptor
|
|
144
|
+
|
|
145
|
+
--using, -u Specifies an option to apply to the volatile builder
|
|
146
|
+
loading the source, e.g. convertFieldsToCamelCase.
|
|
147
|
+
--min, -m Minifies the output. [default: false]
|
|
148
|
+
--path, -p Adds a directory to the include path.
|
|
149
|
+
--legacy, -l Includes legacy descriptors from google/protobuf/ if
|
|
150
|
+
explicitly referenced. [default: false]
|
|
151
|
+
--quiet, -q Suppresses any informatory output to stderr. [default: false]
|
|
152
|
+
--use, -i Specifies an option to apply to the emitted builder
|
|
153
|
+
utilized by your program, e.g. populateAccessors.
|
|
154
|
+
--exports, -e Specifies the namespace to export. Defaults to export
|
|
155
|
+
the root namespace.
|
|
156
|
+
--dependency, -d Library dependency to use when generating classes.
|
|
157
|
+
Defaults to 'protobufjs' for CommonJS, 'ProtoBuf' for
|
|
158
|
+
AMD modules and 'dcodeIO.ProtoBuf' for classes.
|
|
159
|
+
```
|
|
160
|
+
|
|
31
161
|
Documentation
|
|
32
162
|
-------------
|
|
33
163
|
* [Read the official protobuf guide](https://developers.google.com/protocol-buffers/docs/overview)
|
|
34
|
-
* [Read
|
|
35
|
-
* [
|
|
36
|
-
* [Check out the examples](https://github.com/dcodeIO/ProtoBuf.js/tree/master/examples)
|
|
164
|
+
* [Read the API docs](http://htmlpreview.github.io/?https://raw.githubusercontent.com/dcodeIO/protobuf.js/ProtoBuf5/docs/ProtoBuf.html)
|
|
165
|
+
* [Check out the examples](https://github.com/dcodeIO/protobuf.js/tree/ProtoBuf5/examples)
|
|
37
166
|
|
|
38
167
|
Tests
|
|
39
168
|
-----
|
|
40
|
-
* [View source](https://github.com/dcodeIO/
|
|
41
|
-
* [View report](https://travis-ci.org/dcodeIO/ProtoBuf.js)
|
|
169
|
+
* [View source](https://github.com/dcodeIO/protobuf.js/blob/ProtoBuf5/tests/suite.js)
|
|
42
170
|
|
|
43
171
|
Downloads
|
|
44
172
|
---------
|
|
45
|
-
* [Distributions](https://github.com/dcodeIO/
|
|
46
|
-
* [ZIP-Archive](https://github.com/dcodeIO/
|
|
47
|
-
* [Tarball](https://github.com/dcodeIO/
|
|
173
|
+
* [Distributions](https://github.com/dcodeIO/protobuf.js/tree/ProtoBuf5/dist)
|
|
174
|
+
* [ZIP-Archive](https://github.com/dcodeIO/protobuf.js/archive/ProtoBuf5.zip)
|
|
175
|
+
* [Tarball](https://github.com/dcodeIO/protobuf.js/tarball/ProtoBuf5)
|
|
48
176
|
|
|
49
177
|
CDN usage
|
|
50
178
|
---------
|
|
51
179
|
```html
|
|
52
|
-
<script src="//cdn.rawgit.com/dcodeIO/
|
|
180
|
+
<script src="//cdn.rawgit.com/dcodeIO/protobuf.js/5.0.1/dist/protobuf.min.js"></script>
|
|
53
181
|
```
|
|
54
|
-
With
|
|
55
|
-
the latest master build.
|
|
56
|
-
|
|
57
|
-
Contributors
|
|
58
|
-
------------
|
|
59
|
-
[Daniel Wirtz](https://github.com/dcodeIO) (maintainer), [Frank Xu](https://github.com/yyfrankyy),
|
|
60
|
-
[Dretch](https://github.com/Dretch), [shirmin](https://github.com/shirmin), [Nikolai Vavilov](https://github.com/seishun)
|
|
182
|
+
With the version pointing to the exact [release](https://github.com/dcodeIO/protobuf.js/releases) your project depends upon.
|
|
61
183
|
|
|
62
|
-
**License:** [Apache License, Version 2.0](http://www.apache.org/licenses/LICENSE-2.0.html)
|
|
184
|
+
**License:** [Apache License, Version 2.0](http://www.apache.org/licenses/LICENSE-2.0.html)
|
package/bin/pbjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
process.exit(require(__dirname+"/../cli/pbjs.js").main(process.argv));
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
process.exit(require(__dirname+"/../cli/pbjs.js").main(process.argv));
|
package/bower.json
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "protobuf",
|
|
3
3
|
"description": "Protocol Buffers for JavaScript. Finally.",
|
|
4
|
-
"version": "
|
|
5
|
-
"main": "dist/
|
|
4
|
+
"version": "5.0.2",
|
|
5
|
+
"main": "dist/protobuf.js",
|
|
6
6
|
"license": "Apache-2.0",
|
|
7
7
|
"homepage": "http://dcode.io/",
|
|
8
8
|
"dependencies": {
|
|
9
|
-
"bytebuffer": "~
|
|
9
|
+
"bytebuffer": "~5"
|
|
10
10
|
},
|
|
11
11
|
"keywords": ["net", "buffer", "protobuf", "serialization", "bytebuffer", "websocket", "webrtc"],
|
|
12
12
|
"ignore": [
|
package/cli/pbjs/targets/amd.js
CHANGED
|
@@ -30,7 +30,7 @@ var ProtoBuf = require("../../../index.js"),
|
|
|
30
30
|
var amd = module.exports = function(builder, options) {
|
|
31
31
|
options = options || {};
|
|
32
32
|
return [
|
|
33
|
-
"define([", JSON.stringify(options.dependency || "
|
|
33
|
+
"define([", JSON.stringify(options.dependency || "protobuf"), "]", options.min ? "," : ", ",
|
|
34
34
|
"function(ProtoBuf)", options.min ? "{" : " {\n ",
|
|
35
35
|
"return ProtoBuf",
|
|
36
36
|
util.indent(js.build(builder, options), options.min ? "" : " "), options.min ? "" : "\n",
|
package/cli/pbjs/targets/json.js
CHANGED
|
@@ -58,11 +58,14 @@ json.description = description;
|
|
|
58
58
|
function buildNamespace(ns, out) {
|
|
59
59
|
var messages, enums, services;
|
|
60
60
|
util.extend(out, {
|
|
61
|
+
"syntax" : ns.syntax || 'proto2',
|
|
61
62
|
"options" : out.options || {},
|
|
62
63
|
"messages" : messages = [],
|
|
63
64
|
"enums" : enums = [],
|
|
64
65
|
"services" : services = []
|
|
65
66
|
});
|
|
67
|
+
if (!(ns instanceof ProtoBuf.Reflect.Message))
|
|
68
|
+
out['isNamespace'] = true;
|
|
66
69
|
util.extend(out["options"], buildOptions(ns.options));
|
|
67
70
|
ns.getChildren(ProtoBuf.Reflect.Enum).forEach(function(enm) {
|
|
68
71
|
enums.push(buildEnum(enm));
|
|
@@ -131,6 +134,7 @@ function buildOptions(options) {
|
|
|
131
134
|
case 'string':
|
|
132
135
|
case 'number':
|
|
133
136
|
case 'boolean':
|
|
137
|
+
case 'object':
|
|
134
138
|
break;
|
|
135
139
|
default:
|
|
136
140
|
throw Error("Illegal option type: "+typeof(val));
|
|
@@ -148,6 +152,7 @@ function buildMessage(msg) {
|
|
|
148
152
|
var fields, oneofs;
|
|
149
153
|
var out = {
|
|
150
154
|
"name" : msg.name,
|
|
155
|
+
"syntax" : msg.syntax || 'proto2',
|
|
151
156
|
"options" : {},
|
|
152
157
|
"fields" : fields = [],
|
|
153
158
|
"oneofs" : oneofs = {}
|
|
@@ -160,7 +165,7 @@ function buildMessage(msg) {
|
|
|
160
165
|
msg.getChildren(ProtoBuf.Reflect.Message.OneOf).forEach(function(oneof) {
|
|
161
166
|
oneofs[oneof.name] = buildMessageOneof(oneof);
|
|
162
167
|
});
|
|
163
|
-
if (msg.extensions
|
|
168
|
+
if (msg.extensions)
|
|
164
169
|
out["extensions"] = msg.extensions;
|
|
165
170
|
if (Object.keys(oneofs).length === 0)
|
|
166
171
|
delete out["oneofs"];
|
|
@@ -207,6 +212,7 @@ function buildEnum(enm) {
|
|
|
207
212
|
var values;
|
|
208
213
|
var out = {
|
|
209
214
|
"name" : enm.name,
|
|
215
|
+
"syntax" : enm.syntax || 'proto2',
|
|
210
216
|
"values" : values = []
|
|
211
217
|
};
|
|
212
218
|
enm.getChildren(ProtoBuf.Reflect.Enum.Value).forEach(function(val) {
|
|
@@ -244,7 +250,9 @@ function buildService(svc) {
|
|
|
244
250
|
svc.getChildren(ProtoBuf.Reflect.Service.RPCMethod).forEach(function(mtd) {
|
|
245
251
|
rpc[mtd.name] = {
|
|
246
252
|
"request": svc.qn(mtd.resolvedRequestType),
|
|
253
|
+
"request_stream": mtd.requestStream,
|
|
247
254
|
"response": svc.qn(mtd.resolvedResponseType),
|
|
255
|
+
"response_stream": mtd.responseStream,
|
|
248
256
|
"options": buildOptions(mtd.options)
|
|
249
257
|
};
|
|
250
258
|
});
|
|
@@ -61,7 +61,8 @@ var proto = module.exports = function(builder, options) {
|
|
|
61
61
|
buildEnum(enm, indent);
|
|
62
62
|
});
|
|
63
63
|
ns.getChildren(ProtoBuf.Reflect.Message).forEach(function(msg) {
|
|
64
|
-
|
|
64
|
+
if (!msg.isGroup) // legacy groups are build within the respective field
|
|
65
|
+
buildMessage(msg, indent);
|
|
65
66
|
});
|
|
66
67
|
var exts = util.groupExtensions(ns);
|
|
67
68
|
if (exts !== null) {
|
|
@@ -98,9 +99,12 @@ var proto = module.exports = function(builder, options) {
|
|
|
98
99
|
|
|
99
100
|
// Builds a message
|
|
100
101
|
function buildMessage(msg, indent) {
|
|
101
|
-
if (!
|
|
102
|
-
|
|
103
|
-
|
|
102
|
+
if (!msg.isGroup) {
|
|
103
|
+
if (!options.min)
|
|
104
|
+
out.push(indent);
|
|
105
|
+
out.push("message ", msg.name);
|
|
106
|
+
}
|
|
107
|
+
out.push(options.min ? "{" : " {\n");
|
|
104
108
|
buildOptions(msg.options, indent+" ");
|
|
105
109
|
var n = 0, oneofFields = [];
|
|
106
110
|
msg.getChildren(ProtoBuf.Reflect.Message.OneOf).forEach(function(oneof) {
|
|
@@ -125,10 +129,18 @@ var proto = module.exports = function(builder, options) {
|
|
|
125
129
|
});
|
|
126
130
|
if (n > 0 && !options.min)
|
|
127
131
|
out[out.length-1] += "\n";
|
|
128
|
-
if (msg.extensions
|
|
132
|
+
if (msg.extensions) { // array of ranges
|
|
129
133
|
if (!options.min)
|
|
130
134
|
out.push(indent, " ");
|
|
131
|
-
out.push("extensions "
|
|
135
|
+
out.push("extensions ");
|
|
136
|
+
msg.extensions.forEach(function(range, index) {
|
|
137
|
+
if (index > 0)
|
|
138
|
+
out.push(options.min ? "," : ", ");
|
|
139
|
+
out.push(value(range[0]));
|
|
140
|
+
if (range[1] !== range[0])
|
|
141
|
+
out.push(" to ", range[1] === ProtoBuf.ID_MAX ? "max" : value(range[1]));
|
|
142
|
+
});
|
|
143
|
+
out.push(options.min ? ";" : ";\n\n");
|
|
132
144
|
}
|
|
133
145
|
buildNamespace(msg, indent+" ");
|
|
134
146
|
if (!options.min)
|
|
@@ -138,31 +150,43 @@ var proto = module.exports = function(builder, options) {
|
|
|
138
150
|
|
|
139
151
|
// Builds a message field
|
|
140
152
|
function buildMessageField(msg, fld, indent, isOneOf) {
|
|
153
|
+
var isGroup = false;
|
|
141
154
|
if (!options.min)
|
|
142
155
|
out.push(indent);
|
|
143
156
|
if (!isOneOf)
|
|
144
157
|
out.push(fld.required ? "required " : (fld.repeated ? "repeated " : "optional "));
|
|
145
|
-
if (fld.resolvedType !== null)
|
|
158
|
+
if (fld.resolvedType !== null) {
|
|
159
|
+
if (fld.resolvedType instanceof ProtoBuf.Reflect.Message && fld.resolvedType.isGroup) {
|
|
160
|
+
// inline legacy groups
|
|
161
|
+
out.push("group ");
|
|
162
|
+
isGroup = true;
|
|
163
|
+
}
|
|
146
164
|
out.push(msg.qn(fld.resolvedType));
|
|
147
|
-
else
|
|
165
|
+
} else
|
|
148
166
|
out.push(fld.type['name']);
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
out.push(
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
167
|
+
if (!isGroup)
|
|
168
|
+
out.push(" ", fld instanceof ProtoBuf.Reflect.Message.ExtensionField ? fld.name.substring(fld.name.lastIndexOf(".")+1) : fld.name);
|
|
169
|
+
out.push(options.min ? "=" : " = ", fld.id);
|
|
170
|
+
if (isGroup) // inline
|
|
171
|
+
buildMessage(fld.resolvedType, indent);
|
|
172
|
+
else {
|
|
173
|
+
var keys = Object.keys(fld.options);
|
|
174
|
+
if (keys.length > 0) {
|
|
175
|
+
out.push(options.min ? "[" : " [");
|
|
176
|
+
var n = 0;
|
|
177
|
+
keys.forEach(function (key) {
|
|
178
|
+
if (n > 0)
|
|
179
|
+
out.push(options.min ? "," : ", ");
|
|
180
|
+
out.push(key, options.min ? "=" : " = ",
|
|
181
|
+
// BEWARE: Monkey patch for string enum defaults
|
|
182
|
+
key === "default" && fld.type === ProtoBuf.TYPES["enum"] && typeof fld.options[key] === 'string' ? fld.options[key] : value(fld.options[key])
|
|
183
|
+
);
|
|
184
|
+
n++;
|
|
185
|
+
});
|
|
186
|
+
out.push("]");
|
|
187
|
+
}
|
|
188
|
+
out.push(options.min ? ";" : ";\n");
|
|
164
189
|
}
|
|
165
|
-
out.push(options.min ? ";" : ";\n");
|
|
166
190
|
}
|
|
167
191
|
|
|
168
192
|
// Builds an enum
|
package/cli/pbjs/util.js
CHANGED
package/cli/pbjs.js
CHANGED
|
@@ -13,7 +13,7 @@
|
|
|
13
13
|
See the License for the specific language governing permissions and
|
|
14
14
|
limitations under the License.
|
|
15
15
|
*/
|
|
16
|
-
var ProtoBuf = require(__dirname+"/../
|
|
16
|
+
var ProtoBuf = require(__dirname+"/../index.js"),
|
|
17
17
|
fs = require("fs"),
|
|
18
18
|
path = require("path"),
|
|
19
19
|
cli = require("ascli")("pbjs"),
|
|
@@ -160,6 +160,10 @@ pbjs.main = function(argv) {
|
|
|
160
160
|
describe: "Suppresses any informatory output to stderr.",
|
|
161
161
|
default: false
|
|
162
162
|
},
|
|
163
|
+
out: {
|
|
164
|
+
alias: "o",
|
|
165
|
+
describe: "Send output to file instead of stdout.",
|
|
166
|
+
},
|
|
163
167
|
use: {
|
|
164
168
|
alias: "i",
|
|
165
169
|
describe: "Specifies an option to apply to the emitted builder\nutilized by your program, e.g. populateAccessors.",
|
|
@@ -171,7 +175,7 @@ pbjs.main = function(argv) {
|
|
|
171
175
|
},
|
|
172
176
|
dependency: {
|
|
173
177
|
alias: "d",
|
|
174
|
-
describe: "Library dependency to use when generating classes.\nDefaults to 'protobufjs' for CommonJS, '
|
|
178
|
+
describe: "Library dependency to use when generating classes.\nDefaults to 'protobufjs' for CommonJS, 'protobuf' for\nAMD modules and 'dcodeIO.ProtoBuf' for classes."
|
|
175
179
|
}
|
|
176
180
|
})
|
|
177
181
|
.alias("help", "h")
|
|
@@ -265,6 +269,9 @@ pbjs.main = function(argv) {
|
|
|
265
269
|
if (!options.quiet)
|
|
266
270
|
cli.error("\nProcessing: "+sourceFiles.join(", ")+" ...\n");
|
|
267
271
|
var res = pbjs.targets[options.target](builder, options);
|
|
272
|
+
if (options.out){
|
|
273
|
+
fs.writeFileSync(options.out, res);
|
|
274
|
+
}else
|
|
268
275
|
process.stdout.write(res);
|
|
269
276
|
if (!options.quiet)
|
|
270
277
|
cli.error(""),
|
package/dist/README.md
CHANGED
|
@@ -5,31 +5,31 @@ ProtoBuf.js is available either with or without the .proto parser included.
|
|
|
5
5
|
|
|
6
6
|
### Full build including .proto parser (.proto and JSON)
|
|
7
7
|
|
|
8
|
-
* **[
|
|
8
|
+
* **[protobuf.js](https://raw.githubusercontent.com/dcodeIO/ProtoBuf.js/master/dist/protobuf.js)**
|
|
9
9
|
contains the commented source code.
|
|
10
10
|
|
|
11
|
-
* **[
|
|
11
|
+
* **[protobuf.min.js](https://raw.githubusercontent.com/dcodeIO/ProtoBuf.js/master/dist/protobuf.min.js)**
|
|
12
12
|
has been compiled with Closure Compiler.
|
|
13
13
|
|
|
14
|
-
* **[
|
|
14
|
+
* **[protobuf.min.js.gz](https://raw.githubusercontent.com/dcodeIO/ProtoBuf.js/master/dist/protobuf.min.js.gz)**
|
|
15
15
|
has also been gzipped using `-9`.
|
|
16
16
|
|
|
17
|
-
* **[
|
|
17
|
+
* **[protobuf.min.map](https://raw.githubusercontent.com/dcodeIO/ProtoBuf.js/master/dist/protobuf.min.map)**
|
|
18
18
|
is the source map generated by Closure Compiler.
|
|
19
19
|
|
|
20
|
-
### Light build excluding .proto parser (JSON only) for use with [pbjs](https://github.com/dcodeIO/
|
|
20
|
+
### Light build excluding .proto parser (JSON only) for use with [pbjs](https://github.com/dcodeIO/Protobuf.js/wiki/pbjs)
|
|
21
21
|
|
|
22
|
-
* **[
|
|
22
|
+
* **[protobuf-light.js](https://raw.githubusercontent.com/dcodeIO/ProtoBuf.js/master/dist/protobuf-light.js)**
|
|
23
23
|
contains the commented source code.
|
|
24
24
|
|
|
25
|
-
* **[
|
|
25
|
+
* **[protobuf-light.min.js](https://raw.githubusercontent.com/dcodeIO/ProtoBuf.js/master/dist/protobuf-light.min.js)**
|
|
26
26
|
has been compiled with Closure Compiler.
|
|
27
27
|
|
|
28
|
-
* **[
|
|
28
|
+
* **[protobuf-light.min.js.gz](https://raw.githubusercontent.com/dcodeIO/ProtoBuf.js/master/dist/protobuf-light.min.js.gz)**
|
|
29
29
|
has also been gzipped using `-9`.
|
|
30
30
|
|
|
31
|
-
* **[
|
|
31
|
+
* **[protobuf-light.min.map](https://raw.githubusercontent.com/dcodeIO/ProtoBuf.js/master/dist/protobuf-light.min.map)**
|
|
32
32
|
is the source map generated by Closure Compiler.
|
|
33
33
|
|
|
34
34
|
When sending pull requests, please note that these files have been automatically generated from the sources located in
|
|
35
|
-
[src/](https://github.com/dcodeIO/
|
|
35
|
+
[src/](https://github.com/dcodeIO/protobuf.js/tree/master/src).
|