protobufjs 4.1.1 → 5.0.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/.travis.yml +2 -1
- package/README.md +17 -17
- package/bower.json +2 -2
- package/cli/pbjs/targets/json.js +3 -2
- package/cli/pbjs/targets/proto.js +48 -24
- package/cli/pbjs.js +8 -1
- package/dist/README.md +10 -10
- package/dist/{ProtoBuf-light.js → protobuf-light.js} +49 -43
- package/dist/protobuf-light.min.js +87 -0
- package/dist/protobuf-light.min.js.gz +0 -0
- package/dist/protobuf-light.min.map +8 -0
- package/dist/{ProtoBuf.js → protobuf.js} +103 -66
- package/dist/protobuf.min.js +108 -0
- package/dist/protobuf.min.js.gz +0 -0
- package/dist/protobuf.min.map +8 -0
- package/docs/ProtoBuf.Builder.Message.html +106 -37
- package/docs/ProtoBuf.Builder.Service.html +9 -9
- package/docs/ProtoBuf.Builder.html +22 -22
- package/docs/ProtoBuf.DotProto.Parser.html +7 -7
- package/docs/ProtoBuf.DotProto.Tokenizer.html +11 -11
- package/docs/ProtoBuf.DotProto.html +2 -2
- package/docs/ProtoBuf.Map.html +6 -6
- package/docs/ProtoBuf.Reflect.Element.html +7 -7
- package/docs/ProtoBuf.Reflect.Enum.Value.html +10 -10
- package/docs/ProtoBuf.Reflect.Enum.html +21 -21
- package/docs/ProtoBuf.Reflect.Extension.html +3 -3
- package/docs/ProtoBuf.Reflect.Message.ExtensionField.html +29 -29
- package/docs/ProtoBuf.Reflect.Message.Field.html +28 -28
- package/docs/ProtoBuf.Reflect.Message.OneOf.html +10 -10
- package/docs/ProtoBuf.Reflect.Message.html +31 -28
- package/docs/ProtoBuf.Reflect.Namespace.html +19 -19
- package/docs/ProtoBuf.Reflect.Service.Method.html +11 -11
- package/docs/ProtoBuf.Reflect.Service.RPCMethod.html +17 -17
- package/docs/ProtoBuf.Reflect.Service.html +20 -20
- package/docs/ProtoBuf.Reflect.T.html +9 -9
- package/docs/ProtoBuf.Reflect.html +2 -2
- package/docs/ProtoBuf.Util.html +2 -151
- package/docs/ProtoBuf.html +9 -9
- package/docs/ProtoBuf.js.html +104 -67
- package/docs/index.html +1 -1
- package/donate.png +0 -0
- package/externs/{ProtoBuf.js → protobuf.js} +933 -922
- package/index.js +1 -18
- package/package.json +12 -11
- package/protobuf.png +0 -0
- package/sandbox/issue347/index.js +27 -0
- package/sandbox/issue355/main.proto +15 -0
- package/scripts/build.js +4 -9
- package/src/ProtoBuf/Builder/Message.js +9 -4
- package/src/ProtoBuf/Builder/Service.js +3 -0
- package/src/ProtoBuf/Builder.js +17 -10
- package/src/ProtoBuf/DotProto/Parser.js +54 -23
- package/src/ProtoBuf/Reflect/Element.js +4 -3
- package/src/ProtoBuf/Reflect/Message/Field.js +4 -3
- package/src/ProtoBuf/Reflect/Message.js +3 -3
- package/src/ProtoBuf/Util.js +3 -14
- package/src/bower.json +1 -1
- package/src/google/protobuf/descriptor.json +28 -14
- package/src/{ProtoBuf.js → protobuf.js} +0 -0
- package/src/wrap.js +6 -6
- package/tests/imports-weak.proto +7 -0
- package/tests/suite.js +64 -81
- package/ProtoBuf.png +0 -0
- package/dist/ProtoBuf-light.min.js +0 -88
- 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/tests/gtfs-realtime.proto +0 -552
package/.travis.yml
CHANGED
package/README.md
CHANGED
|
@@ -1,19 +1,19 @@
|
|
|
1
|
-

|
|
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=dcode%40dcode.io&item_name=%3C3%20protobuf.js)
|
|
12
12
|
|
|
13
13
|
Getting started
|
|
14
14
|
---------------
|
|
15
15
|
* **Step 1:** Become familar with [Google's Protocol Buffers (protobuf)](https://developers.google.com/protocol-buffers/docs/overview)
|
|
16
|
-
* **Step 2:** Head straight to [our wiki for up to date usage information, changes and examples](https://github.com/dcodeIO/
|
|
16
|
+
* **Step 2:** Head straight to [our wiki for up to date usage information, changes and examples](https://github.com/dcodeIO/protobuf.js/wiki)
|
|
17
17
|
* **Step 3:** Build something cool! :-)
|
|
18
18
|
|
|
19
19
|
Features
|
|
@@ -21,37 +21,37 @@ Features
|
|
|
21
21
|
* [RequireJS](http://requirejs.org/)/AMD compatible
|
|
22
22
|
* [node.js](http://nodejs.org)/CommonJS compatible, also available via [npm](https://npmjs.org/package/protobufjs)
|
|
23
23
|
* Browser compatible
|
|
24
|
-
* [Closure Compiler](https://developers.google.com/closure/compiler/) compatible (fully annotated, [externs](https://github.com/dcodeIO/
|
|
24
|
+
* [Closure Compiler](https://developers.google.com/closure/compiler/) compatible (fully annotated, [externs](https://github.com/dcodeIO/protobuf.js/tree/master/externs))
|
|
25
25
|
* Fully documented using [jsdoc3](https://github.com/jsdoc3/jsdoc)
|
|
26
26
|
* Well tested through [test.js](https://github.com/dcodeIO/test.js)
|
|
27
|
-
* [
|
|
27
|
+
* [bytebuffer.js](https://github.com/dcodeIO/bytebuffer.js) is the only production dependency
|
|
28
28
|
* Fully compatible to the official implementation including advanced features
|
|
29
29
|
* proto2js command line utility
|
|
30
30
|
|
|
31
31
|
Documentation
|
|
32
32
|
-------------
|
|
33
33
|
* [Read the official protobuf guide](https://developers.google.com/protocol-buffers/docs/overview)
|
|
34
|
-
* [Read our wiki](https://github.com/dcodeIO/
|
|
35
|
-
* [Read the API docs](http://htmlpreview.github.io/?https://raw.githubusercontent.com/dcodeIO/
|
|
36
|
-
* [Check out the examples](https://github.com/dcodeIO/
|
|
34
|
+
* [Read our wiki](https://github.com/dcodeIO/protobuf.js/wiki)
|
|
35
|
+
* [Read the API docs](http://htmlpreview.github.io/?https://raw.githubusercontent.com/dcodeIO/protobuf.js/master/docs/ProtoBuf.html)
|
|
36
|
+
* [Check out the examples](https://github.com/dcodeIO/protobuf.js/tree/master/examples)
|
|
37
37
|
|
|
38
38
|
Tests
|
|
39
39
|
-----
|
|
40
|
-
* [View source](https://github.com/dcodeIO/
|
|
41
|
-
* [View report](https://travis-ci.org/dcodeIO/
|
|
40
|
+
* [View source](https://github.com/dcodeIO/protobuf.js/blob/master/tests/suite.js)
|
|
41
|
+
* [View report](https://travis-ci.org/dcodeIO/protobuf.js)
|
|
42
42
|
|
|
43
43
|
Downloads
|
|
44
44
|
---------
|
|
45
|
-
* [Distributions](https://github.com/dcodeIO/
|
|
46
|
-
* [ZIP-Archive](https://github.com/dcodeIO/
|
|
47
|
-
* [Tarball](https://github.com/dcodeIO/
|
|
45
|
+
* [Distributions](https://github.com/dcodeIO/protobuf.js/tree/master/dist)
|
|
46
|
+
* [ZIP-Archive](https://github.com/dcodeIO/protobuf.js/archive/master.zip)
|
|
47
|
+
* [Tarball](https://github.com/dcodeIO/protobuf.js/tarball/master)
|
|
48
48
|
|
|
49
49
|
CDN usage
|
|
50
50
|
---------
|
|
51
51
|
```html
|
|
52
|
-
<script src="//cdn.rawgit.com/dcodeIO/
|
|
52
|
+
<script src="//cdn.rawgit.com/dcodeIO/protobuf.js/VERSION/dist/protobuf.js"></script>
|
|
53
53
|
```
|
|
54
|
-
With `VERSION` replaced by [a valid tag](https://github.com/dcodeIO/
|
|
54
|
+
With `VERSION` replaced by [a valid tag](https://github.com/dcodeIO/protobuf.js/releases) or just `master` for testing
|
|
55
55
|
the latest master build.
|
|
56
56
|
|
|
57
57
|
Contributors
|
package/bower.json
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "protobuf",
|
|
3
3
|
"description": "Protocol Buffers for JavaScript. Finally.",
|
|
4
|
-
"version": "
|
|
5
|
-
"main": "dist/
|
|
4
|
+
"version": "5.0.1",
|
|
5
|
+
"main": "dist/protobuf.js",
|
|
6
6
|
"license": "Apache-2.0",
|
|
7
7
|
"homepage": "http://dcode.io/",
|
|
8
8
|
"dependencies": {
|
package/cli/pbjs/targets/json.js
CHANGED
|
@@ -160,7 +160,7 @@ function buildMessage(msg) {
|
|
|
160
160
|
msg.getChildren(ProtoBuf.Reflect.Message.OneOf).forEach(function(oneof) {
|
|
161
161
|
oneofs[oneof.name] = buildMessageOneof(oneof);
|
|
162
162
|
});
|
|
163
|
-
if (msg.extensions
|
|
163
|
+
if (msg.extensions)
|
|
164
164
|
out["extensions"] = msg.extensions;
|
|
165
165
|
if (Object.keys(oneofs).length === 0)
|
|
166
166
|
delete out["oneofs"];
|
|
@@ -180,7 +180,8 @@ function buildMessageField(fld) {
|
|
|
180
180
|
"keytype" : (typeof(fld.keyType) === 'string') ? fld.keyType : (fld.keyType !== null ? fld.keyType.name : undefined),
|
|
181
181
|
"name" : fld instanceof ProtoBuf.Reflect.Message.ExtensionField ? fld.name.substring(fld.name.lastIndexOf(".")+1): fld.name,
|
|
182
182
|
"id" : fld.id,
|
|
183
|
-
"options" : Object.keys(fld.options).length > 0 ? buildOptions(fld.options) : undefined
|
|
183
|
+
"options" : Object.keys(fld.options).length > 0 ? buildOptions(fld.options) : undefined,
|
|
184
|
+
"oneof" : fld.oneof ? fld.oneof.name : undefined
|
|
184
185
|
};
|
|
185
186
|
}
|
|
186
187
|
|
|
@@ -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.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.",
|
|
@@ -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).
|
|
@@ -15,20 +15,20 @@
|
|
|
15
15
|
*/
|
|
16
16
|
|
|
17
17
|
/**
|
|
18
|
-
* @license
|
|
18
|
+
* @license protobuf.js (c) 2013 Daniel Wirtz <dcode@dcode.io>
|
|
19
19
|
* Released under the Apache License, Version 2.0
|
|
20
|
-
* see: https://github.com/dcodeIO/
|
|
20
|
+
* see: https://github.com/dcodeIO/protobuf.js for details
|
|
21
21
|
*/
|
|
22
22
|
(function(global, factory) {
|
|
23
23
|
|
|
24
24
|
/* AMD */ if (typeof define === 'function' && define["amd"])
|
|
25
|
-
define(["
|
|
25
|
+
define(["bytebuffer"], factory);
|
|
26
26
|
/* CommonJS */ else if (typeof require === "function" && typeof module === "object" && module && module["exports"])
|
|
27
|
-
module["exports"] = factory(require("bytebuffer"),
|
|
27
|
+
module["exports"] = factory(require("bytebuffer"), true);
|
|
28
28
|
/* Global */ else
|
|
29
29
|
(global["dcodeIO"] = global["dcodeIO"] || {})["ProtoBuf"] = factory(global["dcodeIO"]["ByteBuffer"]);
|
|
30
30
|
|
|
31
|
-
})(this, function(ByteBuffer,
|
|
31
|
+
})(this, function(ByteBuffer, isCommonJS) {
|
|
32
32
|
"use strict";
|
|
33
33
|
|
|
34
34
|
/**
|
|
@@ -57,7 +57,7 @@
|
|
|
57
57
|
* @const
|
|
58
58
|
* @expose
|
|
59
59
|
*/
|
|
60
|
-
ProtoBuf.VERSION = "
|
|
60
|
+
ProtoBuf.VERSION = "5.0.1";
|
|
61
61
|
|
|
62
62
|
/**
|
|
63
63
|
* Wire types.
|
|
@@ -351,8 +351,9 @@
|
|
|
351
351
|
if (callback && typeof callback != 'function')
|
|
352
352
|
callback = null;
|
|
353
353
|
if (Util.IS_NODE) {
|
|
354
|
+
var fs = require("fs");
|
|
354
355
|
if (callback) {
|
|
355
|
-
|
|
356
|
+
fs.readFile(path, function(err, data) {
|
|
356
357
|
if (err)
|
|
357
358
|
callback(null);
|
|
358
359
|
else
|
|
@@ -360,7 +361,7 @@
|
|
|
360
361
|
});
|
|
361
362
|
} else
|
|
362
363
|
try {
|
|
363
|
-
return
|
|
364
|
+
return fs.readFileSync(path);
|
|
364
365
|
} catch (e) {
|
|
365
366
|
return null;
|
|
366
367
|
}
|
|
@@ -390,18 +391,6 @@
|
|
|
390
391
|
}
|
|
391
392
|
};
|
|
392
393
|
|
|
393
|
-
/**
|
|
394
|
-
* Requires a node module.
|
|
395
|
-
* @function
|
|
396
|
-
* @param {string} path
|
|
397
|
-
* @returns {*}
|
|
398
|
-
* @throws Error If node require is not supported
|
|
399
|
-
* @expose
|
|
400
|
-
*/
|
|
401
|
-
Util.require = Util.IS_NODE
|
|
402
|
-
? function(path) { return nodeRequire(path); }
|
|
403
|
-
: function(path) { throw Error("node require is not supported by this platform")};
|
|
404
|
-
|
|
405
394
|
/**
|
|
406
395
|
* Converts a string to camel case.
|
|
407
396
|
* @param {string} str
|
|
@@ -899,9 +888,10 @@
|
|
|
899
888
|
* @expose
|
|
900
889
|
*/
|
|
901
890
|
ElementPrototype.verifyValue = function(value) {
|
|
902
|
-
var
|
|
903
|
-
|
|
904
|
-
|
|
891
|
+
var self = this;
|
|
892
|
+
function fail(val, msg) {
|
|
893
|
+
throw Error("Illegal value for "+self.toString(true)+" of type "+self.type.name+": "+val+" ("+msg+")");
|
|
894
|
+
}
|
|
905
895
|
switch (this.type) {
|
|
906
896
|
// Signed 32bit
|
|
907
897
|
case ProtoBuf.TYPES["int32"]:
|
|
@@ -1391,10 +1381,10 @@
|
|
|
1391
1381
|
|
|
1392
1382
|
/**
|
|
1393
1383
|
* Extensions range.
|
|
1394
|
-
* @type {!Array.<number
|
|
1384
|
+
* @type {!Array.<number>|undefined}
|
|
1395
1385
|
* @expose
|
|
1396
1386
|
*/
|
|
1397
|
-
this.extensions =
|
|
1387
|
+
this.extensions = undefined;
|
|
1398
1388
|
|
|
1399
1389
|
/**
|
|
1400
1390
|
* Runtime message class.
|
|
@@ -1793,18 +1783,19 @@
|
|
|
1793
1783
|
* @name ProtoBuf.Builder.Message#encodeDelimited
|
|
1794
1784
|
* @function
|
|
1795
1785
|
* @param {(!ByteBuffer|boolean)=} buffer ByteBuffer to encode to. Will create a new one and flip it if omitted.
|
|
1786
|
+
* @param {boolean=} noVerify Whether to not verify field values, defaults to `false`
|
|
1796
1787
|
* @return {!ByteBuffer} Encoded message as a ByteBuffer
|
|
1797
1788
|
* @throws {Error} If the message cannot be encoded or if required fields are missing. The later still
|
|
1798
1789
|
* returns the encoded ByteBuffer in the `encoded` property on the error.
|
|
1799
1790
|
* @expose
|
|
1800
1791
|
*/
|
|
1801
|
-
MessagePrototype.encodeDelimited = function(buffer) {
|
|
1792
|
+
MessagePrototype.encodeDelimited = function(buffer, noVerify) {
|
|
1802
1793
|
var isNew = false;
|
|
1803
1794
|
if (!buffer)
|
|
1804
1795
|
buffer = new ByteBuffer(),
|
|
1805
1796
|
isNew = true;
|
|
1806
1797
|
var enc = new ByteBuffer().LE();
|
|
1807
|
-
T.encode(this, enc).flip();
|
|
1798
|
+
T.encode(this, enc, noVerify).flip();
|
|
1808
1799
|
buffer.writeVarint32(enc.remaining());
|
|
1809
1800
|
buffer.append(enc);
|
|
1810
1801
|
return isNew ? buffer.flip() : buffer;
|
|
@@ -1951,7 +1942,7 @@
|
|
|
1951
1942
|
return binaryAsBase64 ? obj.toBase64() : obj.toBuffer();
|
|
1952
1943
|
// Convert Longs to proper objects or strings
|
|
1953
1944
|
if (ProtoBuf.Long.isLong(obj))
|
|
1954
|
-
return longsAsStrings ? obj.toString() :
|
|
1945
|
+
return longsAsStrings ? obj.toString() : ProtoBuf.Long.fromValue(obj);
|
|
1955
1946
|
var clone;
|
|
1956
1947
|
// Clone arrays
|
|
1957
1948
|
if (Array.isArray(obj)) {
|
|
@@ -2013,6 +2004,7 @@
|
|
|
2013
2004
|
* @name ProtoBuf.Builder.Message.decode
|
|
2014
2005
|
* @function
|
|
2015
2006
|
* @param {!ByteBuffer|!ArrayBuffer|!Buffer|string} buffer Buffer to decode from
|
|
2007
|
+
* @param {(number|string)=} length Message length. Defaults to decode all the remainig data.
|
|
2016
2008
|
* @param {string=} enc Encoding if buffer is a string: hex, utf8 (not recommended), defaults to base64
|
|
2017
2009
|
* @return {!ProtoBuf.Builder.Message} Decoded message
|
|
2018
2010
|
* @throws {Error} If the message cannot be decoded or if required fields are missing. The later still
|
|
@@ -2021,7 +2013,10 @@
|
|
|
2021
2013
|
* @see ProtoBuf.Builder.Message.decode64
|
|
2022
2014
|
* @see ProtoBuf.Builder.Message.decodeHex
|
|
2023
2015
|
*/
|
|
2024
|
-
Message.decode = function(buffer, enc) {
|
|
2016
|
+
Message.decode = function(buffer, length, enc) {
|
|
2017
|
+
if (typeof length === 'string')
|
|
2018
|
+
enc = length,
|
|
2019
|
+
length = -1;
|
|
2025
2020
|
if (typeof buffer === 'string')
|
|
2026
2021
|
buffer = ByteBuffer.wrap(buffer, enc ? enc : "base64");
|
|
2027
2022
|
buffer = ByteBuffer.isByteBuffer(buffer) ? buffer : ByteBuffer.wrap(buffer); // May throw
|
|
@@ -2282,7 +2277,7 @@
|
|
|
2282
2277
|
/**
|
|
2283
2278
|
* Decodes an encoded message and returns the decoded message.
|
|
2284
2279
|
* @param {ByteBuffer} buffer ByteBuffer to decode from
|
|
2285
|
-
* @param {number=} length Message length. Defaults to decode all
|
|
2280
|
+
* @param {number=} length Message length. Defaults to decode all remaining data.
|
|
2286
2281
|
* @param {number=} expectedGroupEndId Expected GROUPEND id if this is a legacy group
|
|
2287
2282
|
* @return {ProtoBuf.Builder.Message} Decoded message
|
|
2288
2283
|
* @throws {Error} If the message cannot be decoded
|
|
@@ -2532,9 +2527,10 @@
|
|
|
2532
2527
|
*/
|
|
2533
2528
|
FieldPrototype.verifyValue = function(value, skipRepeated) {
|
|
2534
2529
|
skipRepeated = skipRepeated || false;
|
|
2535
|
-
var
|
|
2536
|
-
|
|
2537
|
-
|
|
2530
|
+
var self = this;
|
|
2531
|
+
function fail(val, msg) {
|
|
2532
|
+
throw Error("Illegal value for "+self.toString(true)+" of type "+self.type.name+": "+val+" ("+msg+")");
|
|
2533
|
+
}
|
|
2538
2534
|
if (value === null) { // NULL values for optional fields
|
|
2539
2535
|
if (this.required)
|
|
2540
2536
|
fail(typeof value, "required");
|
|
@@ -3148,6 +3144,9 @@
|
|
|
3148
3144
|
callback(err);
|
|
3149
3145
|
return;
|
|
3150
3146
|
}
|
|
3147
|
+
// Coalesce to empty string when service response has empty content
|
|
3148
|
+
if (res === null)
|
|
3149
|
+
res = ''
|
|
3151
3150
|
try { res = method.resolvedResponseType.clazz.decode(res); } catch (notABuffer) {}
|
|
3152
3151
|
if (!res || !(res instanceof method.resolvedResponseType.clazz)) {
|
|
3153
3152
|
callback(Error("Illegal response type received in service method "+ T.name+"#"+method.name));
|
|
@@ -3591,13 +3590,12 @@
|
|
|
3591
3590
|
subObj.push(svc);
|
|
3592
3591
|
});
|
|
3593
3592
|
|
|
3594
|
-
// Set extension
|
|
3593
|
+
// Set extension ranges
|
|
3595
3594
|
if (def["extensions"]) {
|
|
3596
|
-
|
|
3597
|
-
|
|
3598
|
-
|
|
3599
|
-
|
|
3600
|
-
obj.extensions[1] = ProtoBuf.ID_MAX;
|
|
3595
|
+
if (typeof def["extensions"][0] === 'number') // pre 5.0.1
|
|
3596
|
+
obj.extensions = [ def["extensions"] ];
|
|
3597
|
+
else
|
|
3598
|
+
obj.extensions = def["extensions"];
|
|
3601
3599
|
}
|
|
3602
3600
|
|
|
3603
3601
|
// Create on top of current namespace
|
|
@@ -3636,8 +3634,16 @@
|
|
|
3636
3634
|
def["fields"].forEach(function(fld) {
|
|
3637
3635
|
if (obj.getChild(fld['id']|0) !== null)
|
|
3638
3636
|
throw Error("duplicate extended field id in "+obj.name+": "+fld['id']);
|
|
3639
|
-
if
|
|
3640
|
-
|
|
3637
|
+
// Check if field id is allowed to be extended
|
|
3638
|
+
if (obj.extensions) {
|
|
3639
|
+
var valid = false;
|
|
3640
|
+
obj.extensions.forEach(function(range) {
|
|
3641
|
+
if (fld["id"] >= range[0] && fld["id"] <= range[1])
|
|
3642
|
+
valid = true;
|
|
3643
|
+
});
|
|
3644
|
+
if (!valid)
|
|
3645
|
+
throw Error("illegal extended field id in "+obj.name+": "+fld['id']+" (not within valid ranges)");
|
|
3646
|
+
}
|
|
3641
3647
|
// Convert extension field names to camel case notation if the override is set
|
|
3642
3648
|
var name = fld["name"];
|
|
3643
3649
|
if (this.options['convertFieldsToCamelCase'])
|
|
@@ -3706,7 +3712,7 @@
|
|
|
3706
3712
|
if (typeof filename === 'string') {
|
|
3707
3713
|
|
|
3708
3714
|
if (ProtoBuf.Util.IS_NODE)
|
|
3709
|
-
filename =
|
|
3715
|
+
filename = require("path")['resolve'](filename);
|
|
3710
3716
|
if (this.files[filename] === true)
|
|
3711
3717
|
return this.reset();
|
|
3712
3718
|
this.files[filename] = true;
|
|
@@ -3715,7 +3721,7 @@
|
|
|
3715
3721
|
|
|
3716
3722
|
var root = filename.root;
|
|
3717
3723
|
if (ProtoBuf.Util.IS_NODE)
|
|
3718
|
-
root =
|
|
3724
|
+
root = require("path")['resolve'](root);
|
|
3719
3725
|
if (root.indexOf("\\") >= 0 || filename.file.indexOf("\\") >= 0)
|
|
3720
3726
|
delim = '\\';
|
|
3721
3727
|
var fname = root + delim + filename.file;
|