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.
Files changed (99) hide show
  1. package/bin/proto2js +16 -4
  2. package/bower.json +1 -1
  3. package/dist/ProtoBuf.js +645 -441
  4. package/dist/ProtoBuf.min.js +96 -96
  5. package/dist/ProtoBuf.min.js.gz +0 -0
  6. package/dist/ProtoBuf.min.map +2 -2
  7. package/dist/ProtoBuf.noparse.js +520 -357
  8. package/dist/ProtoBuf.noparse.min.js +68 -66
  9. package/dist/ProtoBuf.noparse.min.js.gz +0 -0
  10. package/dist/ProtoBuf.noparse.min.map +3 -3
  11. package/docs/ProtoBuf.Builder.Message.html +673 -135
  12. package/docs/ProtoBuf.Builder.Service.html +58 -19
  13. package/docs/ProtoBuf.Builder.html +374 -46
  14. package/docs/ProtoBuf.DotProto.Parser.html +58 -19
  15. package/docs/ProtoBuf.DotProto.Tokenizer.html +104 -19
  16. package/docs/ProtoBuf.DotProto.html +16 -10
  17. package/docs/ProtoBuf.Reflect.Enum.Value.html +207 -33
  18. package/docs/ProtoBuf.Reflect.Enum.html +318 -56
  19. package/docs/ProtoBuf.Reflect.Extension.html +53 -13
  20. package/docs/ProtoBuf.Reflect.Message.ExtensionField.html +450 -68
  21. package/docs/ProtoBuf.Reflect.Message.Field.html +454 -51
  22. package/docs/ProtoBuf.Reflect.Message.OneOf.html +1044 -0
  23. package/docs/ProtoBuf.Reflect.Message.html +378 -64
  24. package/docs/ProtoBuf.Reflect.Namespace.html +333 -51
  25. package/docs/ProtoBuf.Reflect.Service.Method.html +228 -35
  26. package/docs/ProtoBuf.Reflect.Service.RPCMethod.html +262 -41
  27. package/docs/ProtoBuf.Reflect.Service.html +318 -56
  28. package/docs/ProtoBuf.Reflect.T.html +210 -25
  29. package/docs/ProtoBuf.Reflect.html +17 -11
  30. package/docs/ProtoBuf.Util.html +59 -13
  31. package/docs/ProtoBuf.html +235 -67
  32. package/docs/ProtoBuf.js.html +648 -443
  33. package/docs/index.html +4 -2
  34. package/docs/styles/jsdoc-default.css +2 -2
  35. package/examples/protoify/.npmignore +2 -0
  36. package/examples/protoify/README.md +28 -0
  37. package/examples/protoify/index.js +147 -0
  38. package/examples/protoify/json.js +123 -0
  39. package/examples/protoify/json.json +123 -0
  40. package/examples/protoify/json.proto +30 -0
  41. package/examples/protoify/package.json +15 -0
  42. package/examples/protoify/test.js +56 -0
  43. package/examples/websocket/README.md +1 -0
  44. package/examples/websocket/package.json +1 -1
  45. package/externs/ProtoBuf.js +922 -922
  46. package/package.json +3 -3
  47. package/scripts/build.js +58 -58
  48. package/src/ProtoBuf/Builder/Message.js +107 -77
  49. package/src/ProtoBuf/Builder/Service.js +8 -5
  50. package/src/ProtoBuf/Builder.js +71 -37
  51. package/src/ProtoBuf/DotProto/Parser.js +108 -72
  52. package/src/ProtoBuf/DotProto/Tokenizer.js +17 -11
  53. package/src/ProtoBuf/Lang.js +1 -1
  54. package/src/ProtoBuf/Reflect/Enum/Value.js +3 -2
  55. package/src/ProtoBuf/Reflect/Enum.js +9 -5
  56. package/src/ProtoBuf/Reflect/Extension.js +4 -3
  57. package/src/ProtoBuf/Reflect/Message/ExtensionField.js +4 -3
  58. package/src/ProtoBuf/Reflect/Message/Field.js +45 -26
  59. package/src/ProtoBuf/Reflect/Message/OneOf.js +19 -0
  60. package/src/ProtoBuf/Reflect/Message.js +36 -19
  61. package/src/ProtoBuf/Reflect/Namespace.js +19 -15
  62. package/src/ProtoBuf/Reflect/Service/Method.js +9 -5
  63. package/src/ProtoBuf/Reflect/Service/RPCMethod.js +3 -2
  64. package/src/ProtoBuf/Reflect/Service.js +9 -5
  65. package/src/ProtoBuf/Reflect/T.js +20 -6
  66. package/src/ProtoBuf/Reflect.js +9 -0
  67. package/src/ProtoBuf/Util.js +132 -132
  68. package/src/ProtoBuf.js +15 -17
  69. package/src/google/protobuf/descriptor.json +33 -13
  70. package/tests/bench.txt +373 -373
  71. package/tests/complex.json +8 -4
  72. package/tests/custom-options.json +169 -169
  73. package/tests/extend.json +71 -71
  74. package/tests/nodeunit-browser/nodeunit.css +70 -70
  75. package/tests/nodeunit-browser/nodeunit.js +2108 -2108
  76. package/tests/oneof.proto +6 -0
  77. package/tests/options.json +32 -32
  78. package/tests/options.proto +2 -0
  79. package/tests/proto2js/Bar.json +46 -46
  80. package/tests/suite.js +83 -12
  81. package/.idea/.name +0 -1
  82. package/.idea/ProtoBuf.iml +0 -9
  83. package/.idea/dictionaries/Daniel.xml +0 -7
  84. package/.idea/encodings.xml +0 -5
  85. package/.idea/misc.xml +0 -5
  86. package/.idea/modules.xml +0 -9
  87. package/.idea/scopes/scope_settings.xml +0 -5
  88. package/.idea/vcs.xml +0 -7
  89. package/.idea/workspace.xml +0 -551
  90. package/NOTICE +0 -2
  91. package/sandbox/issue146/MyOptions.proto +0 -28
  92. package/sandbox/issue146/Sample.proto +0 -21
  93. package/sandbox/issue146/main.js +0 -3
  94. package/sandbox/issue147/enum.proto +0 -8
  95. package/sandbox/issue147/main.js +0 -3
  96. package/sandbox/issue42/innerextend.proto +0 -18
  97. package/sandbox/issue42/main.js +0 -8
  98. package/sandbox/issue42/outerextend.proto +0 -17
  99. package/v8.log +0 -3828
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "protobufjs",
3
- "version": "3.6.0",
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.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 fields on the object itself and set default values
20
- for (var i=0, k=fields.length, field; i<k; ++i) {
21
- this[(field = fields[i]).name] = field.repeated ? [] : null;
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 // set field values from arguments, in declaration order
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
- * The message's reflection type.
45
- * @name ProtoBuf.Builder.Message#$type
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
- Message.prototype.add = function(key, value, noAssert) {
64
- var field = T.getChild(key);
65
- if (!field)
66
- throw Error(this+"#"+key+" is undefined");
67
- if (!(field instanceof ProtoBuf.Reflect.Message.Field))
68
- throw Error(this+"#"+key+" is not a field: "+field.toString(true)); // May throw if it's an enum or embedded message
69
- if (!field.repeated)
70
- throw Error(this+"#"+key+" is not a repeated field");
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
- Message.prototype.$add = Message.prototype.add;
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
- Message.prototype.set = function(key, value, noAssert) {
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
- if (noAssert) {
107
- this[key] = value;
108
- return this;
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 or not (asserts by default)
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
- Message.prototype.$set = Message.prototype.set;
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 no assert for an actual field, defaults to `false`
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
- Message.prototype.get = function(key, noAssert) {
152
+ MessagePrototype.get = function(key, noAssert) {
142
153
  if (noAssert)
143
154
  return this[key];
144
- var field = T.getChild(key);
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
- Message.prototype.$get = Message.prototype.get;
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 (ProtoBuf.populateAccessors)
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
- * another field.
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
- Message.prototype["set"+Name] = function(value) {
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
- * another field.
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
- Message.prototype["set_"+name] = function(value) {
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
- * another field.
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
- Message.prototype["get"+Name] = function() {
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
- * another field.
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
- Message.prototype["get_"+name] = function() {
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
- Message.prototype.encode = function(buffer, noVerify) {
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
- Message.prototype.calculate = function() {
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
- Message.prototype.encodeDelimited = function(buffer) {
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
- Message.prototype.encodeAB = function() {
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
- Message.prototype.toArrayBuffer = Message.prototype.encodeAB;
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
- Message.prototype.encodeNB = function() {
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
- Message.prototype.toBuffer = Message.prototype.encodeNB;
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
- Message.prototype.encode64 = function() {
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
- Message.prototype.toBase64 = Message.prototype.encode64;
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
- Message.prototype.encodeHex = function() {
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
- Message.prototype.toHex = Message.prototype.encodeHex;
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} includeBuffers Whether to include native buffer data or not
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, includeBuffers) {
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 (includeBuffers)
440
- clone[i] = obj.toBuffer();
469
+ if (includeBinaryAsBase64)
470
+ clone[i] = obj[i].toBase64();
441
471
  } else // is a non-null object
442
- clone[i] = cloneRaw(obj[i], includeBuffers);
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=} includeBuffers Whether to include native buffer data or not, defaults to `false`
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
- Message.prototype.toRaw = function(includeBuffers) {
454
- return cloneRaw(this, !!includeBuffers);
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
- Message.prototype.toString = function() {
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(Message.prototype, "$type", {
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
- // Extends ProtoBuf.Builder.Service
31
- Service.prototype = Object.create(ProtoBuf.Builder.Service.prototype);
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(Service.prototype, "$options", { "value": Service["$options"] });
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
- Service.prototype[method.name] = function(req, callback) {
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(Service.prototype[method.name], "$options", { "value": Service[method.name]["$options"] });
96
+ Object.defineProperty(ServicePrototype[method.name], "$options", { "value": Service[method.name]["$options"] });
94
97
  })(rpc[i]);
95
98
  }