protobufjs 3.6.0 → 3.8.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/bin/proto2js +16 -4
- package/bower.json +1 -1
- package/dist/ProtoBuf.js +645 -441
- package/dist/ProtoBuf.min.js +96 -96
- package/dist/ProtoBuf.min.js.gz +0 -0
- package/dist/ProtoBuf.min.map +2 -2
- package/dist/ProtoBuf.noparse.js +520 -357
- package/dist/ProtoBuf.noparse.min.js +68 -66
- package/dist/ProtoBuf.noparse.min.js.gz +0 -0
- package/dist/ProtoBuf.noparse.min.map +3 -3
- package/docs/ProtoBuf.Builder.Message.html +673 -135
- package/docs/ProtoBuf.Builder.Service.html +58 -19
- package/docs/ProtoBuf.Builder.html +374 -46
- package/docs/ProtoBuf.DotProto.Parser.html +58 -19
- package/docs/ProtoBuf.DotProto.Tokenizer.html +104 -19
- package/docs/ProtoBuf.DotProto.html +16 -10
- package/docs/ProtoBuf.Reflect.Enum.Value.html +207 -33
- package/docs/ProtoBuf.Reflect.Enum.html +318 -56
- package/docs/ProtoBuf.Reflect.Extension.html +53 -13
- package/docs/ProtoBuf.Reflect.Message.ExtensionField.html +450 -68
- package/docs/ProtoBuf.Reflect.Message.Field.html +454 -51
- package/docs/ProtoBuf.Reflect.Message.OneOf.html +1044 -0
- package/docs/ProtoBuf.Reflect.Message.html +378 -64
- package/docs/ProtoBuf.Reflect.Namespace.html +333 -51
- package/docs/ProtoBuf.Reflect.Service.Method.html +228 -35
- package/docs/ProtoBuf.Reflect.Service.RPCMethod.html +262 -41
- package/docs/ProtoBuf.Reflect.Service.html +318 -56
- package/docs/ProtoBuf.Reflect.T.html +210 -25
- package/docs/ProtoBuf.Reflect.html +17 -11
- package/docs/ProtoBuf.Util.html +59 -13
- package/docs/ProtoBuf.html +235 -67
- package/docs/ProtoBuf.js.html +648 -443
- package/docs/index.html +4 -2
- package/docs/styles/jsdoc-default.css +2 -2
- package/examples/protoify/.npmignore +2 -0
- package/examples/protoify/README.md +28 -0
- package/examples/protoify/index.js +147 -0
- package/examples/protoify/json.js +123 -0
- package/examples/protoify/json.json +123 -0
- package/examples/protoify/json.proto +30 -0
- package/examples/protoify/package.json +15 -0
- package/examples/protoify/test.js +56 -0
- package/examples/websocket/README.md +1 -0
- package/examples/websocket/package.json +1 -1
- package/externs/ProtoBuf.js +922 -922
- package/package.json +3 -3
- package/scripts/build.js +58 -58
- package/src/ProtoBuf/Builder/Message.js +107 -77
- package/src/ProtoBuf/Builder/Service.js +8 -5
- package/src/ProtoBuf/Builder.js +71 -37
- package/src/ProtoBuf/DotProto/Parser.js +108 -72
- package/src/ProtoBuf/DotProto/Tokenizer.js +17 -11
- package/src/ProtoBuf/Lang.js +1 -1
- package/src/ProtoBuf/Reflect/Enum/Value.js +3 -2
- package/src/ProtoBuf/Reflect/Enum.js +9 -5
- package/src/ProtoBuf/Reflect/Extension.js +4 -3
- package/src/ProtoBuf/Reflect/Message/ExtensionField.js +4 -3
- package/src/ProtoBuf/Reflect/Message/Field.js +45 -26
- package/src/ProtoBuf/Reflect/Message/OneOf.js +19 -0
- package/src/ProtoBuf/Reflect/Message.js +36 -19
- package/src/ProtoBuf/Reflect/Namespace.js +19 -15
- package/src/ProtoBuf/Reflect/Service/Method.js +9 -5
- package/src/ProtoBuf/Reflect/Service/RPCMethod.js +3 -2
- package/src/ProtoBuf/Reflect/Service.js +9 -5
- package/src/ProtoBuf/Reflect/T.js +20 -6
- package/src/ProtoBuf/Reflect.js +9 -0
- package/src/ProtoBuf/Util.js +132 -132
- package/src/ProtoBuf.js +15 -17
- package/src/google/protobuf/descriptor.json +33 -13
- package/tests/bench.txt +373 -373
- package/tests/complex.json +8 -4
- package/tests/custom-options.json +169 -169
- package/tests/extend.json +71 -71
- package/tests/nodeunit-browser/nodeunit.css +70 -70
- package/tests/nodeunit-browser/nodeunit.js +2108 -2108
- package/tests/oneof.proto +6 -0
- package/tests/options.json +32 -32
- package/tests/options.proto +2 -0
- package/tests/proto2js/Bar.json +46 -46
- package/tests/suite.js +83 -12
- package/.idea/.name +0 -1
- package/.idea/ProtoBuf.iml +0 -9
- package/.idea/dictionaries/Daniel.xml +0 -7
- package/.idea/encodings.xml +0 -5
- package/.idea/misc.xml +0 -5
- package/.idea/modules.xml +0 -9
- package/.idea/scopes/scope_settings.xml +0 -5
- package/.idea/vcs.xml +0 -7
- package/.idea/workspace.xml +0 -551
- package/NOTICE +0 -2
- 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/issue42/innerextend.proto +0 -18
- package/sandbox/issue42/main.js +0 -8
- package/sandbox/issue42/outerextend.proto +0 -17
- package/v8.log +0 -3828
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "protobufjs",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.8.2",
|
|
4
4
|
"description": "Protocol Buffers for JavaScript. Finally.",
|
|
5
5
|
"author": "Daniel Wirtz <dcode@dcode.io>",
|
|
6
6
|
"contributors": [
|
|
@@ -20,14 +20,14 @@
|
|
|
20
20
|
},
|
|
21
21
|
"keywords": ["net", "buffer", "protobuf", "serialization", "bytebuffer", "websocket", "webrtc"],
|
|
22
22
|
"dependencies": {
|
|
23
|
-
"bytebuffer": "~3.
|
|
23
|
+
"bytebuffer": "~3 >=3.5",
|
|
24
24
|
"ascli": "~0.3"
|
|
25
25
|
},
|
|
26
26
|
"devDependencies": {
|
|
27
27
|
"testjs": "~1",
|
|
28
28
|
"metascript": ">=0.18 <1",
|
|
29
29
|
"closurecompiler": "~1",
|
|
30
|
-
"jsdoc": "~3.3"
|
|
30
|
+
"jsdoc": "~3.3.0-alpha10"
|
|
31
31
|
},
|
|
32
32
|
"license": "Apache-2.0",
|
|
33
33
|
"engines": {
|
package/scripts/build.js
CHANGED
|
@@ -1,58 +1,58 @@
|
|
|
1
|
-
/*
|
|
2
|
-
Copyright 2013 Daniel Wirtz <dcode@dcode.io>
|
|
3
|
-
|
|
4
|
-
Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
-
you may not use this file except in compliance with the License.
|
|
6
|
-
You may obtain a copy of the License at
|
|
7
|
-
|
|
8
|
-
http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
-
|
|
10
|
-
Unless required by applicable law or agreed to in writing, software
|
|
11
|
-
distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
-
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
-
See the License for the specific language governing permissions and
|
|
14
|
-
limitations under the License.
|
|
15
|
-
*/
|
|
16
|
-
|
|
17
|
-
/**
|
|
18
|
-
* @overview ProtoBuf.js Build Script (c) 2014 Daniel Wirtz <dcode@dcode.io>
|
|
19
|
-
* Released under the Apache License, Version 2.0
|
|
20
|
-
* see: https://github.com/dcodeIO/ProtoBuf.js for details
|
|
21
|
-
*/
|
|
22
|
-
var MetaScript = require("metascript"),
|
|
23
|
-
path = require("path"),
|
|
24
|
-
fs = require("fs");
|
|
25
|
-
|
|
26
|
-
var rootDir = path.join(__dirname, ".."),
|
|
27
|
-
srcDir = path.join(rootDir, "src"),
|
|
28
|
-
distDir = path.join(rootDir, "dist"),
|
|
29
|
-
pkg = require(path.join(rootDir, "package.json")),
|
|
30
|
-
filename;
|
|
31
|
-
|
|
32
|
-
var scope = {
|
|
33
|
-
VERSION: pkg.version, // Version
|
|
34
|
-
NOPARSE: false // Whether to exclude the ProtoBuf.DotProto package (no parser, JSON only) or not
|
|
35
|
-
};
|
|
36
|
-
|
|
37
|
-
// Make full build
|
|
38
|
-
console.log("Building ProtoBuf.js with scope", JSON.stringify(scope, null, 2));
|
|
39
|
-
fs.writeFileSync(
|
|
40
|
-
path.join(distDir, "ProtoBuf.js"),
|
|
41
|
-
MetaScript.transform(fs.readFileSync(filename = path.join(srcDir, "ProtoBuf.js")), filename, scope, srcDir)
|
|
42
|
-
);
|
|
43
|
-
|
|
44
|
-
// Make NOPARSE build
|
|
45
|
-
scope.NOPARSE = true;
|
|
46
|
-
console.log("Building ProtoBuf.noparse.js with scope", JSON.stringify(scope, null, 2));
|
|
47
|
-
fs.writeFileSync(
|
|
48
|
-
path.join(distDir, "ProtoBuf.noparse.js"),
|
|
49
|
-
MetaScript.transform(fs.readFileSync(filename = path.join(srcDir, "ProtoBuf.js")), filename, scope, srcDir)
|
|
50
|
-
);
|
|
51
|
-
|
|
52
|
-
// Update bower.json
|
|
53
|
-
scope = { VERSION: pkg.version };
|
|
54
|
-
console.log("Updating bower.json with scope", JSON.stringify(scope, null, 2));
|
|
55
|
-
fs.writeFileSync(
|
|
56
|
-
path.join(rootDir, "bower.json"),
|
|
57
|
-
MetaScript.transform(fs.readFileSync(filename = path.join(srcDir, "bower.json")), filename, scope, srcDir)
|
|
58
|
-
);
|
|
1
|
+
/*
|
|
2
|
+
Copyright 2013 Daniel Wirtz <dcode@dcode.io>
|
|
3
|
+
|
|
4
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
you may not use this file except in compliance with the License.
|
|
6
|
+
You may obtain a copy of the License at
|
|
7
|
+
|
|
8
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
|
|
10
|
+
Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
See the License for the specific language governing permissions and
|
|
14
|
+
limitations under the License.
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* @overview ProtoBuf.js Build Script (c) 2014 Daniel Wirtz <dcode@dcode.io>
|
|
19
|
+
* Released under the Apache License, Version 2.0
|
|
20
|
+
* see: https://github.com/dcodeIO/ProtoBuf.js for details
|
|
21
|
+
*/
|
|
22
|
+
var MetaScript = require("metascript"),
|
|
23
|
+
path = require("path"),
|
|
24
|
+
fs = require("fs");
|
|
25
|
+
|
|
26
|
+
var rootDir = path.join(__dirname, ".."),
|
|
27
|
+
srcDir = path.join(rootDir, "src"),
|
|
28
|
+
distDir = path.join(rootDir, "dist"),
|
|
29
|
+
pkg = require(path.join(rootDir, "package.json")),
|
|
30
|
+
filename;
|
|
31
|
+
|
|
32
|
+
var scope = {
|
|
33
|
+
VERSION: pkg.version, // Version
|
|
34
|
+
NOPARSE: false // Whether to exclude the ProtoBuf.DotProto package (no parser, JSON only) or not
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
// Make full build
|
|
38
|
+
console.log("Building ProtoBuf.js with scope", JSON.stringify(scope, null, 2));
|
|
39
|
+
fs.writeFileSync(
|
|
40
|
+
path.join(distDir, "ProtoBuf.js"),
|
|
41
|
+
MetaScript.transform(fs.readFileSync(filename = path.join(srcDir, "ProtoBuf.js")), filename, scope, srcDir)
|
|
42
|
+
);
|
|
43
|
+
|
|
44
|
+
// Make NOPARSE build
|
|
45
|
+
scope.NOPARSE = true;
|
|
46
|
+
console.log("Building ProtoBuf.noparse.js with scope", JSON.stringify(scope, null, 2));
|
|
47
|
+
fs.writeFileSync(
|
|
48
|
+
path.join(distDir, "ProtoBuf.noparse.js"),
|
|
49
|
+
MetaScript.transform(fs.readFileSync(filename = path.join(srcDir, "ProtoBuf.js")), filename, scope, srcDir)
|
|
50
|
+
);
|
|
51
|
+
|
|
52
|
+
// Update bower.json
|
|
53
|
+
scope = { VERSION: pkg.version };
|
|
54
|
+
console.log("Updating bower.json with scope", JSON.stringify(scope, null, 2));
|
|
55
|
+
fs.writeFileSync(
|
|
56
|
+
path.join(rootDir, "bower.json"),
|
|
57
|
+
MetaScript.transform(fs.readFileSync(filename = path.join(srcDir, "bower.json")), filename, scope, srcDir)
|
|
58
|
+
);
|
|
@@ -2,7 +2,8 @@
|
|
|
2
2
|
// --- Scope ------------------
|
|
3
3
|
// T : Reflect.Message instance
|
|
4
4
|
*/
|
|
5
|
-
var fields = T.getChildren(ProtoBuf.Reflect.Message.Field)
|
|
5
|
+
var fields = T.getChildren(ProtoBuf.Reflect.Message.Field),
|
|
6
|
+
oneofs = T.getChildren(ProtoBuf.Reflect.Message.OneOf);
|
|
6
7
|
|
|
7
8
|
/**
|
|
8
9
|
* Constructs a new runtime Message.
|
|
@@ -16,9 +17,13 @@ var fields = T.getChildren(ProtoBuf.Reflect.Message.Field);
|
|
|
16
17
|
var Message = function(values, var_args) {
|
|
17
18
|
ProtoBuf.Builder.Message.call(this);
|
|
18
19
|
|
|
19
|
-
// Create
|
|
20
|
-
for (var i=0, k=
|
|
21
|
-
this[
|
|
20
|
+
// Create virtual oneof properties
|
|
21
|
+
for (var i=0, k=oneofs.length; i<k; ++i)
|
|
22
|
+
this[oneofs[i].name] = null;
|
|
23
|
+
// Create fields and set default values
|
|
24
|
+
for (i=0, k=fields.length; i<k; ++i) {
|
|
25
|
+
var field = fields[i];
|
|
26
|
+
this[field.name] = field.repeated ? [] : null;
|
|
22
27
|
if (field.required && field.defaultValue !== null)
|
|
23
28
|
this[field.name] = field.defaultValue;
|
|
24
29
|
}
|
|
@@ -34,21 +39,17 @@ var Message = function(values, var_args) {
|
|
|
34
39
|
var keys = Object.keys(values);
|
|
35
40
|
for (i=0, k=keys.length; i<k; ++i)
|
|
36
41
|
this.$set(keys[i], values[keys[i]]); // May throw
|
|
37
|
-
} else //
|
|
42
|
+
} else // Set field values from arguments, in declaration order
|
|
38
43
|
for (i=0, k=arguments.length; i<k; ++i)
|
|
39
44
|
this.$set(fields[i].name, arguments[i]); // May throw
|
|
40
45
|
}
|
|
41
46
|
};
|
|
42
47
|
|
|
43
48
|
/**
|
|
44
|
-
*
|
|
45
|
-
* @
|
|
46
|
-
* @type {!ProtoBuf.Reflect.Message}
|
|
47
|
-
* @expose
|
|
49
|
+
* @alias ProtoBuf.Builder.Message.prototype
|
|
50
|
+
* @inner
|
|
48
51
|
*/
|
|
49
|
-
|
|
50
|
-
// Extends ProtoBuf.Builder.Message
|
|
51
|
-
Message.prototype = Object.create(ProtoBuf.Builder.Message.prototype);
|
|
52
|
+
var MessagePrototype = Message.prototype = Object.create(ProtoBuf.Builder.Message.prototype);
|
|
52
53
|
|
|
53
54
|
/**
|
|
54
55
|
* Adds a value to a repeated field.
|
|
@@ -60,14 +61,16 @@ Message.prototype = Object.create(ProtoBuf.Builder.Message.prototype);
|
|
|
60
61
|
* @throws {Error} If the value cannot be added
|
|
61
62
|
* @expose
|
|
62
63
|
*/
|
|
63
|
-
|
|
64
|
-
var field = T.
|
|
65
|
-
if (!
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
64
|
+
MessagePrototype.add = function(key, value, noAssert) {
|
|
65
|
+
var field = T._fieldsByName[key];
|
|
66
|
+
if (!noAssert) {
|
|
67
|
+
if (!field)
|
|
68
|
+
throw Error(this+"#"+key+" is undefined");
|
|
69
|
+
if (!(field instanceof ProtoBuf.Reflect.Message.Field))
|
|
70
|
+
throw Error(this+"#"+key+" is not a field: "+field.toString(true)); // May throw if it's an enum or embedded message
|
|
71
|
+
if (!field.repeated)
|
|
72
|
+
throw Error(this+"#"+key+" is not a repeated field");
|
|
73
|
+
}
|
|
71
74
|
if (this[field.name] === null)
|
|
72
75
|
this[field.name] = [];
|
|
73
76
|
this[field.name].push(noAssert ? value : field.verifyValue(value, true));
|
|
@@ -83,7 +86,7 @@ Message.prototype.add = function(key, value, noAssert) {
|
|
|
83
86
|
* @throws {Error} If the value cannot be added
|
|
84
87
|
* @expose
|
|
85
88
|
*/
|
|
86
|
-
|
|
89
|
+
MessagePrototype.$add = MessagePrototype.add;
|
|
87
90
|
|
|
88
91
|
/**
|
|
89
92
|
* Sets a field's value.
|
|
@@ -96,23 +99,31 @@ Message.prototype.$add = Message.prototype.add;
|
|
|
96
99
|
* @throws {Error} If the value cannot be set
|
|
97
100
|
* @expose
|
|
98
101
|
*/
|
|
99
|
-
|
|
102
|
+
MessagePrototype.set = function(key, value, noAssert) {
|
|
100
103
|
if (key && typeof key === 'object') {
|
|
101
104
|
for (var i in key)
|
|
102
105
|
if (key.hasOwnProperty(i))
|
|
103
106
|
this.$set(i, key[i], noAssert);
|
|
104
107
|
return this;
|
|
105
108
|
}
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
+
var field = T._fieldsByName[key];
|
|
110
|
+
if (!noAssert) {
|
|
111
|
+
if (!field)
|
|
112
|
+
throw Error(this+"#"+key+" is not a field: undefined");
|
|
113
|
+
if (!(field instanceof ProtoBuf.Reflect.Message.Field))
|
|
114
|
+
throw Error(this+"#"+key+" is not a field: "+field.toString(true));
|
|
115
|
+
this[field.name] = (value = field.verifyValue(value)); // May throw
|
|
116
|
+
} else {
|
|
117
|
+
this[field.name] = value;
|
|
118
|
+
}
|
|
119
|
+
if (field.oneof) {
|
|
120
|
+
if (value !== null) {
|
|
121
|
+
if (this[field.oneof.name] !== null)
|
|
122
|
+
this[this[field.oneof.name]] = null; // Unset the previous (field name is the oneof field's value)
|
|
123
|
+
this[field.oneof.name] = field.name;
|
|
124
|
+
} else if (field.oneof.name === key)
|
|
125
|
+
this[field.oneof.name] = null;
|
|
109
126
|
}
|
|
110
|
-
var field = T.getChild(key);
|
|
111
|
-
if (!field)
|
|
112
|
-
throw Error(this+"#"+key+" is not a field: undefined");
|
|
113
|
-
if (!(field instanceof ProtoBuf.Reflect.Message.Field))
|
|
114
|
-
throw Error(this+"#"+key+" is not a field: "+field.toString(true));
|
|
115
|
-
this[field.name] = field.verifyValue(value); // May throw
|
|
116
127
|
return this;
|
|
117
128
|
};
|
|
118
129
|
|
|
@@ -122,26 +133,26 @@ Message.prototype.set = function(key, value, noAssert) {
|
|
|
122
133
|
* @function
|
|
123
134
|
* @param {string} key Key
|
|
124
135
|
* @param {*} value Value to set
|
|
125
|
-
* @param {boolean=} noAssert Whether to assert the value
|
|
136
|
+
* @param {boolean=} noAssert Whether to not assert the value, defaults to `false`
|
|
126
137
|
* @throws {Error} If the value cannot be set
|
|
127
138
|
* @expose
|
|
128
139
|
*/
|
|
129
|
-
|
|
140
|
+
MessagePrototype.$set = MessagePrototype.set;
|
|
130
141
|
|
|
131
142
|
/**
|
|
132
143
|
* Gets a field's value.
|
|
133
144
|
* @name ProtoBuf.Builder.Message#get
|
|
134
145
|
* @function
|
|
135
146
|
* @param {string} key Key
|
|
136
|
-
* @param {boolean=} noAssert Whether to
|
|
147
|
+
* @param {boolean=} noAssert Whether to not assert for an actual field, defaults to `false`
|
|
137
148
|
* @return {*} Value
|
|
138
149
|
* @throws {Error} If there is no such field
|
|
139
150
|
* @expose
|
|
140
151
|
*/
|
|
141
|
-
|
|
152
|
+
MessagePrototype.get = function(key, noAssert) {
|
|
142
153
|
if (noAssert)
|
|
143
154
|
return this[key];
|
|
144
|
-
var field = T.
|
|
155
|
+
var field = T._fieldsByName[key];
|
|
145
156
|
if (!field || !(field instanceof ProtoBuf.Reflect.Message.Field))
|
|
146
157
|
throw Error(this+"#"+key+" is not a field: undefined");
|
|
147
158
|
if (!(field instanceof ProtoBuf.Reflect.Message.Field))
|
|
@@ -158,7 +169,7 @@ Message.prototype.get = function(key, noAssert) {
|
|
|
158
169
|
* @throws {Error} If there is no such field
|
|
159
170
|
* @expose
|
|
160
171
|
*/
|
|
161
|
-
|
|
172
|
+
MessagePrototype.$get = MessagePrototype.get;
|
|
162
173
|
|
|
163
174
|
// Getters and setters
|
|
164
175
|
|
|
@@ -168,72 +179,91 @@ for (var i=0; i<fields.length; i++) {
|
|
|
168
179
|
if (field instanceof ProtoBuf.Reflect.Message.ExtensionField)
|
|
169
180
|
continue;
|
|
170
181
|
|
|
171
|
-
if (
|
|
182
|
+
if (T.builder.options['populateAccessors'])
|
|
172
183
|
(function(field) {
|
|
173
184
|
// set/get[SomeValue]
|
|
174
185
|
var Name = field.originalName.replace(/(_[a-zA-Z])/g, function(match) {
|
|
175
186
|
return match.toUpperCase().replace('_','');
|
|
176
187
|
});
|
|
177
|
-
Name = Name.substring(0,1).toUpperCase()+Name.substring(1);
|
|
188
|
+
Name = Name.substring(0,1).toUpperCase() + Name.substring(1);
|
|
178
189
|
|
|
179
|
-
// set/get_[some_value]
|
|
190
|
+
// set/get_[some_value] FIXME: Do we really need these?
|
|
180
191
|
var name = field.originalName.replace(/([A-Z])/g, function(match) {
|
|
181
192
|
return "_"+match;
|
|
182
193
|
});
|
|
183
194
|
|
|
195
|
+
/**
|
|
196
|
+
* The current field's unbound setter function.
|
|
197
|
+
* @function
|
|
198
|
+
* @param {*} value
|
|
199
|
+
* @param {boolean=} noAssert
|
|
200
|
+
* @returns {!ProtoBuf.Builder.Message}
|
|
201
|
+
* @inner
|
|
202
|
+
*/
|
|
203
|
+
var setter = function(value, noAssert) {
|
|
204
|
+
this[field.name] = noAssert ? value : field.verifyValue(value);
|
|
205
|
+
return this;
|
|
206
|
+
};
|
|
207
|
+
|
|
208
|
+
/**
|
|
209
|
+
* The current field's unbound getter function.
|
|
210
|
+
* @function
|
|
211
|
+
* @returns {*}
|
|
212
|
+
* @inner
|
|
213
|
+
*/
|
|
214
|
+
var getter = function() {
|
|
215
|
+
return this[field.name];
|
|
216
|
+
};
|
|
217
|
+
|
|
184
218
|
/**
|
|
185
219
|
* Sets a value. This method is present for each field, but only if there is no name conflict with
|
|
186
|
-
*
|
|
220
|
+
* another field.
|
|
187
221
|
* @name ProtoBuf.Builder.Message#set[SomeField]
|
|
188
222
|
* @function
|
|
189
223
|
* @param {*} value Value to set
|
|
224
|
+
* @param {boolean=} noAssert Whether to not assert the value, defaults to `false`
|
|
225
|
+
* @returns {!ProtoBuf.Builder.Message} this
|
|
190
226
|
* @abstract
|
|
191
227
|
* @throws {Error} If the value cannot be set
|
|
192
228
|
*/
|
|
193
229
|
if (T.getChild("set"+Name) === null)
|
|
194
|
-
|
|
195
|
-
this.$set(field.name, value);
|
|
196
|
-
};
|
|
230
|
+
MessagePrototype["set"+Name] = setter;
|
|
197
231
|
|
|
198
232
|
/**
|
|
199
233
|
* Sets a value. This method is present for each field, but only if there is no name conflict with
|
|
200
|
-
*
|
|
234
|
+
* another field.
|
|
201
235
|
* @name ProtoBuf.Builder.Message#set_[some_field]
|
|
202
236
|
* @function
|
|
203
237
|
* @param {*} value Value to set
|
|
238
|
+
* @param {boolean=} noAssert Whether to not assert the value, defaults to `false`
|
|
239
|
+
* @returns {!ProtoBuf.Builder.Message} this
|
|
204
240
|
* @abstract
|
|
205
241
|
* @throws {Error} If the value cannot be set
|
|
206
242
|
*/
|
|
207
243
|
if (T.getChild("set_"+name) === null)
|
|
208
|
-
|
|
209
|
-
this.$set(field.name, value);
|
|
210
|
-
};
|
|
244
|
+
MessagePrototype["set_"+name] = setter;
|
|
211
245
|
|
|
212
246
|
/**
|
|
213
247
|
* Gets a value. This method is present for each field, but only if there is no name conflict with
|
|
214
|
-
*
|
|
248
|
+
* another field.
|
|
215
249
|
* @name ProtoBuf.Builder.Message#get[SomeField]
|
|
216
250
|
* @function
|
|
217
251
|
* @abstract
|
|
218
252
|
* @return {*} The value
|
|
219
253
|
*/
|
|
220
254
|
if (T.getChild("get"+Name) === null)
|
|
221
|
-
|
|
222
|
-
return this.$get(field.name); // Does not throw, field exists
|
|
223
|
-
};
|
|
255
|
+
MessagePrototype["get"+Name] = getter;
|
|
224
256
|
|
|
225
257
|
/**
|
|
226
258
|
* Gets a value. This method is present for each field, but only if there is no name conflict with
|
|
227
|
-
*
|
|
259
|
+
* another field.
|
|
228
260
|
* @name ProtoBuf.Builder.Message#get_[some_field]
|
|
229
261
|
* @function
|
|
230
262
|
* @return {*} The value
|
|
231
263
|
* @abstract
|
|
232
264
|
*/
|
|
233
265
|
if (T.getChild("get_"+name) === null)
|
|
234
|
-
|
|
235
|
-
return this.$get(field.name); // Does not throw, field exists
|
|
236
|
-
};
|
|
266
|
+
MessagePrototype["get_"+name] = getter;
|
|
237
267
|
|
|
238
268
|
})(field);
|
|
239
269
|
}
|
|
@@ -254,7 +284,7 @@ for (var i=0; i<fields.length; i++) {
|
|
|
254
284
|
* @see ProtoBuf.Builder.Message#encodeHex
|
|
255
285
|
* @see ProtoBuf.Builder.Message#encodeAB
|
|
256
286
|
*/
|
|
257
|
-
|
|
287
|
+
MessagePrototype.encode = function(buffer, noVerify) {
|
|
258
288
|
if (typeof buffer === 'boolean')
|
|
259
289
|
noVerify = buffer,
|
|
260
290
|
buffer = undefined;
|
|
@@ -280,7 +310,7 @@ Message.prototype.encode = function(buffer, noVerify) {
|
|
|
280
310
|
* @throws {Error} If the message cannot be calculated or if required fields are missing.
|
|
281
311
|
* @expose
|
|
282
312
|
*/
|
|
283
|
-
|
|
313
|
+
MessagePrototype.calculate = function() {
|
|
284
314
|
return T.calculate(this);
|
|
285
315
|
};
|
|
286
316
|
|
|
@@ -294,7 +324,7 @@ Message.prototype.calculate = function() {
|
|
|
294
324
|
* returns the encoded ByteBuffer in the `encoded` property on the error.
|
|
295
325
|
* @expose
|
|
296
326
|
*/
|
|
297
|
-
|
|
327
|
+
MessagePrototype.encodeDelimited = function(buffer) {
|
|
298
328
|
var isNew = false;
|
|
299
329
|
if (!buffer)
|
|
300
330
|
buffer = new ByteBuffer(),
|
|
@@ -315,7 +345,7 @@ Message.prototype.encodeDelimited = function(buffer) {
|
|
|
315
345
|
* returns the encoded ArrayBuffer in the `encoded` property on the error.
|
|
316
346
|
* @expose
|
|
317
347
|
*/
|
|
318
|
-
|
|
348
|
+
MessagePrototype.encodeAB = function() {
|
|
319
349
|
try {
|
|
320
350
|
return this.encode().toArrayBuffer();
|
|
321
351
|
} catch (e) {
|
|
@@ -333,7 +363,7 @@ Message.prototype.encodeAB = function() {
|
|
|
333
363
|
* returns the encoded ArrayBuffer in the `encoded` property on the error.
|
|
334
364
|
* @expose
|
|
335
365
|
*/
|
|
336
|
-
|
|
366
|
+
MessagePrototype.toArrayBuffer = MessagePrototype.encodeAB;
|
|
337
367
|
|
|
338
368
|
/**
|
|
339
369
|
* Directly encodes the message to a node Buffer.
|
|
@@ -344,7 +374,7 @@ Message.prototype.toArrayBuffer = Message.prototype.encodeAB;
|
|
|
344
374
|
* missing. The later still returns the encoded node Buffer in the `encoded` property on the error.
|
|
345
375
|
* @expose
|
|
346
376
|
*/
|
|
347
|
-
|
|
377
|
+
MessagePrototype.encodeNB = function() {
|
|
348
378
|
try {
|
|
349
379
|
return this.encode().toBuffer();
|
|
350
380
|
} catch (e) {
|
|
@@ -362,7 +392,7 @@ Message.prototype.encodeNB = function() {
|
|
|
362
392
|
* returns the encoded node Buffer in the `encoded` property on the error.
|
|
363
393
|
* @expose
|
|
364
394
|
*/
|
|
365
|
-
|
|
395
|
+
MessagePrototype.toBuffer = MessagePrototype.encodeNB;
|
|
366
396
|
|
|
367
397
|
/**
|
|
368
398
|
* Directly encodes the message to a base64 encoded string.
|
|
@@ -373,7 +403,7 @@ Message.prototype.toBuffer = Message.prototype.encodeNB;
|
|
|
373
403
|
* still returns the encoded base64 string in the `encoded` property on the error.
|
|
374
404
|
* @expose
|
|
375
405
|
*/
|
|
376
|
-
|
|
406
|
+
MessagePrototype.encode64 = function() {
|
|
377
407
|
try {
|
|
378
408
|
return this.encode().toBase64();
|
|
379
409
|
} catch (e) {
|
|
@@ -391,7 +421,7 @@ Message.prototype.encode64 = function() {
|
|
|
391
421
|
* returns the encoded base64 string in the `encoded` property on the error.
|
|
392
422
|
* @expose
|
|
393
423
|
*/
|
|
394
|
-
|
|
424
|
+
MessagePrototype.toBase64 = MessagePrototype.encode64;
|
|
395
425
|
|
|
396
426
|
/**
|
|
397
427
|
* Directly encodes the message to a hex encoded string.
|
|
@@ -402,7 +432,7 @@ Message.prototype.toBase64 = Message.prototype.encode64;
|
|
|
402
432
|
* still returns the encoded hex string in the `encoded` property on the error.
|
|
403
433
|
* @expose
|
|
404
434
|
*/
|
|
405
|
-
|
|
435
|
+
MessagePrototype.encodeHex = function() {
|
|
406
436
|
try {
|
|
407
437
|
return this.encode().toHex();
|
|
408
438
|
} catch (e) {
|
|
@@ -420,38 +450,38 @@ Message.prototype.encodeHex = function() {
|
|
|
420
450
|
* returns the encoded hex string in the `encoded` property on the error.
|
|
421
451
|
* @expose
|
|
422
452
|
*/
|
|
423
|
-
|
|
453
|
+
MessagePrototype.toHex = MessagePrototype.encodeHex;
|
|
424
454
|
|
|
425
455
|
/**
|
|
426
456
|
* Clones a message object to a raw object.
|
|
427
457
|
* @param {*} obj Object to clone
|
|
428
|
-
* @param {boolean}
|
|
458
|
+
* @param {boolean} includeBinaryAsBase64 Whether to include binary data as base64 strings or not
|
|
429
459
|
* @returns {*} Cloned object
|
|
430
460
|
* @inner
|
|
431
461
|
*/
|
|
432
|
-
function cloneRaw(obj,
|
|
462
|
+
function cloneRaw(obj, includeBinaryAsBase64) {
|
|
433
463
|
var clone = {};
|
|
434
464
|
for (var i in obj)
|
|
435
465
|
if (obj.hasOwnProperty(i)) {
|
|
436
466
|
if (obj[i] === null || typeof obj[i] !== 'object')
|
|
437
467
|
clone[i] = obj[i];
|
|
438
468
|
else if (obj[i] instanceof ByteBuffer) {
|
|
439
|
-
if (
|
|
440
|
-
clone[i] = obj.
|
|
469
|
+
if (includeBinaryAsBase64)
|
|
470
|
+
clone[i] = obj[i].toBase64();
|
|
441
471
|
} else // is a non-null object
|
|
442
|
-
clone[i] = cloneRaw(obj[i],
|
|
472
|
+
clone[i] = cloneRaw(obj[i], includeBinaryAsBase64);
|
|
443
473
|
}
|
|
444
474
|
return clone;
|
|
445
475
|
}
|
|
446
476
|
|
|
447
477
|
/**
|
|
448
478
|
* Returns the message's raw payload.
|
|
449
|
-
* @param {boolean=}
|
|
479
|
+
* @param {boolean=} includeBinaryAsBase64 Whether to include binary data as base64 strings or not, defaults to `false`
|
|
450
480
|
* @returns {Object.<string,*>} Raw payload
|
|
451
481
|
* @expose
|
|
452
482
|
*/
|
|
453
|
-
|
|
454
|
-
return cloneRaw(this, !!
|
|
483
|
+
MessagePrototype.toRaw = function(includeBinaryAsBase64) {
|
|
484
|
+
return cloneRaw(this, !!includeBinaryAsBase64);
|
|
455
485
|
};
|
|
456
486
|
|
|
457
487
|
/**
|
|
@@ -552,7 +582,7 @@ Message.decodeHex = function(str) {
|
|
|
552
582
|
* @return {string} String representation as of ".Fully.Qualified.MessageName"
|
|
553
583
|
* @expose
|
|
554
584
|
*/
|
|
555
|
-
|
|
585
|
+
MessagePrototype.toString = function() {
|
|
556
586
|
return T.toString();
|
|
557
587
|
};
|
|
558
588
|
|
|
@@ -576,6 +606,6 @@ var $type; // cc
|
|
|
576
606
|
|
|
577
607
|
if (Object.defineProperty)
|
|
578
608
|
Object.defineProperty(Message, '$options', { "value": T.buildOpt() }),
|
|
579
|
-
Object.defineProperty(
|
|
609
|
+
Object.defineProperty(MessagePrototype, "$type", {
|
|
580
610
|
get: function() { return T; }
|
|
581
611
|
});
|
|
@@ -27,12 +27,15 @@ var Service = function(rpcImpl) {
|
|
|
27
27
|
};
|
|
28
28
|
};
|
|
29
29
|
|
|
30
|
-
|
|
31
|
-
|
|
30
|
+
/**
|
|
31
|
+
* @alias ProtoBuf.Builder.Service.prototype
|
|
32
|
+
* @inner
|
|
33
|
+
*/
|
|
34
|
+
var ServicePrototype = Service.prototype = Object.create(ProtoBuf.Builder.Service.prototype);
|
|
32
35
|
|
|
33
36
|
if (Object.defineProperty)
|
|
34
37
|
Object.defineProperty(Service, "$options", { "value": T.buildOpt() }),
|
|
35
|
-
Object.defineProperty(
|
|
38
|
+
Object.defineProperty(ServicePrototype, "$options", { "value": Service["$options"] });
|
|
36
39
|
|
|
37
40
|
/**
|
|
38
41
|
* Asynchronously performs an RPC call using the given RPC implementation.
|
|
@@ -60,7 +63,7 @@ for (var i=0; i<rpc.length; i++) {
|
|
|
60
63
|
(function(method) {
|
|
61
64
|
|
|
62
65
|
// service#Method(message, callback)
|
|
63
|
-
|
|
66
|
+
ServicePrototype[method.name] = function(req, callback) {
|
|
64
67
|
try {
|
|
65
68
|
if (!req || !(req instanceof method.resolvedRequestType.clazz)) {
|
|
66
69
|
setTimeout(callback.bind(this, Error("Illegal request type provided to service method "+T.name+"#"+method.name)), 0);
|
|
@@ -90,6 +93,6 @@ for (var i=0; i<rpc.length; i++) {
|
|
|
90
93
|
|
|
91
94
|
if (Object.defineProperty)
|
|
92
95
|
Object.defineProperty(Service[method.name], "$options", { "value": method.buildOpt() }),
|
|
93
|
-
Object.defineProperty(
|
|
96
|
+
Object.defineProperty(ServicePrototype[method.name], "$options", { "value": Service[method.name]["$options"] });
|
|
94
97
|
})(rpc[i]);
|
|
95
98
|
}
|