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.
Files changed (188) hide show
  1. package/.travis.yml +3 -1
  2. package/README.md +147 -25
  3. package/bin/pbjs +2 -2
  4. package/bower.json +3 -3
  5. package/cli/pbjs/targets/amd.js +1 -1
  6. package/cli/pbjs/targets/json.js +9 -1
  7. package/cli/pbjs/targets/proto.js +48 -24
  8. package/cli/pbjs/util.js +1 -1
  9. package/cli/pbjs.js +9 -2
  10. package/dist/README.md +10 -10
  11. package/dist/{ProtoBuf-light.js → protobuf-light.js} +207 -152
  12. package/dist/protobuf-light.min.js +94 -0
  13. package/dist/protobuf-light.min.js.gz +0 -0
  14. package/dist/protobuf-light.min.map +8 -0
  15. package/dist/{ProtoBuf.js → protobuf.js} +265 -175
  16. package/dist/protobuf.min.js +116 -0
  17. package/dist/protobuf.min.js.gz +0 -0
  18. package/dist/protobuf.min.map +8 -0
  19. package/docs/ProtoBuf.Builder.Message.html +1473 -967
  20. package/docs/ProtoBuf.Builder.Service.html +266 -197
  21. package/docs/ProtoBuf.Builder.html +758 -542
  22. package/docs/ProtoBuf.DotProto.Parser.html +223 -161
  23. package/docs/ProtoBuf.DotProto.Tokenizer.html +344 -248
  24. package/docs/ProtoBuf.DotProto.html +20 -12
  25. package/docs/ProtoBuf.Element.html +554 -554
  26. package/docs/ProtoBuf.Map.html +158 -123
  27. package/docs/ProtoBuf.Reflect.Element.html +286 -143
  28. package/docs/ProtoBuf.Reflect.Enum.Value.html +329 -228
  29. package/docs/ProtoBuf.Reflect.Enum.html +757 -537
  30. package/docs/ProtoBuf.Reflect.Extension.html +73 -56
  31. package/docs/ProtoBuf.Reflect.Message.ExtensionField.html +1013 -740
  32. package/docs/ProtoBuf.Reflect.Message.Field.html +926 -649
  33. package/docs/ProtoBuf.Reflect.Message.OneOf.html +327 -245
  34. package/docs/ProtoBuf.Reflect.Message.html +919 -652
  35. package/docs/ProtoBuf.Reflect.Namespace.html +648 -447
  36. package/docs/ProtoBuf.Reflect.Service.Method.html +363 -251
  37. package/docs/ProtoBuf.Reflect.Service.RPCMethod.html +545 -397
  38. package/docs/ProtoBuf.Reflect.Service.html +721 -511
  39. package/docs/ProtoBuf.Reflect.T.html +268 -197
  40. package/docs/ProtoBuf.Reflect.html +20 -12
  41. package/docs/ProtoBuf.Util.html +169 -118
  42. package/docs/ProtoBuf.html +840 -628
  43. package/docs/ProtoBuf.js.html +271 -180
  44. package/docs/fonts/OpenSans-Bold-webfont.eot +0 -0
  45. package/docs/fonts/OpenSans-Bold-webfont.svg +1830 -0
  46. package/docs/fonts/OpenSans-Bold-webfont.woff +0 -0
  47. package/docs/fonts/OpenSans-BoldItalic-webfont.eot +0 -0
  48. package/docs/fonts/OpenSans-BoldItalic-webfont.svg +1830 -0
  49. package/docs/fonts/OpenSans-BoldItalic-webfont.woff +0 -0
  50. package/docs/fonts/OpenSans-Italic-webfont.eot +0 -0
  51. package/docs/fonts/OpenSans-Italic-webfont.svg +1830 -0
  52. package/docs/fonts/OpenSans-Italic-webfont.woff +0 -0
  53. package/docs/fonts/OpenSans-Light-webfont.eot +0 -0
  54. package/docs/fonts/OpenSans-Light-webfont.svg +1831 -0
  55. package/docs/fonts/OpenSans-Light-webfont.woff +0 -0
  56. package/docs/fonts/OpenSans-LightItalic-webfont.eot +0 -0
  57. package/docs/fonts/OpenSans-LightItalic-webfont.svg +1835 -0
  58. package/docs/fonts/OpenSans-LightItalic-webfont.woff +0 -0
  59. package/docs/fonts/OpenSans-Regular-webfont.eot +0 -0
  60. package/docs/fonts/OpenSans-Regular-webfont.svg +1831 -0
  61. package/docs/fonts/OpenSans-Regular-webfont.woff +0 -0
  62. package/docs/index.html +7 -5
  63. package/docs/styles/jsdoc-default.css +95 -75
  64. package/docs/styles/prettify-tomorrow.css +1 -1
  65. package/donate.png +0 -0
  66. package/examples/protoify/json.js +123 -123
  67. package/examples/protoify/json.json +123 -123
  68. package/examples/websocket/server.js +4 -4
  69. package/externs/{ProtoBuf.js → protobuf.js} +933 -922
  70. package/index.js +1 -18
  71. package/jsdoc.json +1 -1
  72. package/package.json +11 -11
  73. package/protobuf.png +0 -0
  74. package/scripts/build.js +53 -58
  75. package/src/ProtoBuf/Builder/Message.js +18 -9
  76. package/src/ProtoBuf/Builder/Service.js +3 -0
  77. package/src/ProtoBuf/Builder.js +34 -10
  78. package/src/ProtoBuf/DotProto/Parser.js +58 -23
  79. package/src/ProtoBuf/Reflect/Element.js +17 -4
  80. package/src/ProtoBuf/Reflect/Message/Field.js +6 -5
  81. package/src/ProtoBuf/Reflect/Message.js +9 -4
  82. package/src/ProtoBuf/Util.js +116 -116
  83. package/src/bower.json +2 -2
  84. package/src/google/protobuf/descriptor.json +55 -15
  85. package/src/{ProtoBuf.js → protobuf.js} +0 -0
  86. package/src/wrap.js +4 -4
  87. package/tests/bench.txt +373 -373
  88. package/tests/complex.json +8 -1
  89. package/tests/custom-options.json +169 -169
  90. package/tests/extend.json +71 -71
  91. package/tests/imports-weak.proto +7 -0
  92. package/tests/imports.json +83 -83
  93. package/tests/nodeunit-browser/nodeunit.css +70 -70
  94. package/tests/nodeunit-browser/nodeunit.js +2108 -2108
  95. package/tests/options.json +32 -32
  96. package/tests/proto2js/Bar.json +46 -46
  97. package/tests/suite.js +107 -82
  98. package/ProtoBuf.png +0 -0
  99. package/dist/ProtoBuf-light.min.js +0 -87
  100. package/dist/ProtoBuf-light.min.js.gz +0 -0
  101. package/dist/ProtoBuf-light.min.map +0 -8
  102. package/dist/ProtoBuf.min.js +0 -108
  103. package/dist/ProtoBuf.min.js.gz +0 -0
  104. package/dist/ProtoBuf.min.map +0 -8
  105. package/externs/ByteBuffer.js +0 -767
  106. package/externs/Long.js +0 -328
  107. package/sandbox/gapi/googleapis/google/api/annotations.proto +0 -29
  108. package/sandbox/gapi/googleapis/google/api/http.proto +0 -245
  109. package/sandbox/gapi/googleapis/google/datastore/v1beta3/datastore.proto +0 -281
  110. package/sandbox/gapi/googleapis/google/datastore/v1beta3/entity.proto +0 -189
  111. package/sandbox/gapi/googleapis/google/datastore/v1beta3/query.proto +0 -281
  112. package/sandbox/gapi/googleapis/google/longrunning/operations.proto +0 -144
  113. package/sandbox/gapi/googleapis/google/protobuf/any.proto +0 -98
  114. package/sandbox/gapi/googleapis/google/protobuf/any_test.proto +0 -41
  115. package/sandbox/gapi/googleapis/google/protobuf/api.proto +0 -201
  116. package/sandbox/gapi/googleapis/google/protobuf/descriptor.proto +0 -773
  117. package/sandbox/gapi/googleapis/google/protobuf/duration.proto +0 -95
  118. package/sandbox/gapi/googleapis/google/protobuf/empty.proto +0 -50
  119. package/sandbox/gapi/googleapis/google/protobuf/field_mask.proto +0 -167
  120. package/sandbox/gapi/googleapis/google/protobuf/map_lite_unittest.proto +0 -130
  121. package/sandbox/gapi/googleapis/google/protobuf/map_proto2_unittest.proto +0 -60
  122. package/sandbox/gapi/googleapis/google/protobuf/map_unittest.proto +0 -129
  123. package/sandbox/gapi/googleapis/google/protobuf/map_unittest_proto3.proto +0 -120
  124. package/sandbox/gapi/googleapis/google/protobuf/source_context.proto +0 -47
  125. package/sandbox/gapi/googleapis/google/protobuf/struct.proto +0 -94
  126. package/sandbox/gapi/googleapis/google/protobuf/timestamp.proto +0 -107
  127. package/sandbox/gapi/googleapis/google/protobuf/type.proto +0 -176
  128. package/sandbox/gapi/googleapis/google/protobuf/unittest.proto +0 -878
  129. package/sandbox/gapi/googleapis/google/protobuf/unittest_arena.proto +0 -46
  130. package/sandbox/gapi/googleapis/google/protobuf/unittest_custom_options.proto +0 -394
  131. package/sandbox/gapi/googleapis/google/protobuf/unittest_drop_unknown_fields.proto +0 -58
  132. package/sandbox/gapi/googleapis/google/protobuf/unittest_embed_optimize_for.proto +0 -51
  133. package/sandbox/gapi/googleapis/google/protobuf/unittest_empty.proto +0 -38
  134. package/sandbox/gapi/googleapis/google/protobuf/unittest_enormous_descriptor.proto +0 -1048
  135. package/sandbox/gapi/googleapis/google/protobuf/unittest_import.proto +0 -66
  136. package/sandbox/gapi/googleapis/google/protobuf/unittest_import_lite.proto +0 -52
  137. package/sandbox/gapi/googleapis/google/protobuf/unittest_import_proto3.proto +0 -68
  138. package/sandbox/gapi/googleapis/google/protobuf/unittest_import_public.proto +0 -41
  139. package/sandbox/gapi/googleapis/google/protobuf/unittest_import_public_lite.proto +0 -43
  140. package/sandbox/gapi/googleapis/google/protobuf/unittest_import_public_proto3.proto +0 -42
  141. package/sandbox/gapi/googleapis/google/protobuf/unittest_lite.proto +0 -385
  142. package/sandbox/gapi/googleapis/google/protobuf/unittest_lite_imports_nonlite.proto +0 -44
  143. package/sandbox/gapi/googleapis/google/protobuf/unittest_mset.proto +0 -82
  144. package/sandbox/gapi/googleapis/google/protobuf/unittest_mset_wire_format.proto +0 -52
  145. package/sandbox/gapi/googleapis/google/protobuf/unittest_no_arena.proto +0 -202
  146. package/sandbox/gapi/googleapis/google/protobuf/unittest_no_arena_import.proto +0 -37
  147. package/sandbox/gapi/googleapis/google/protobuf/unittest_no_arena_lite.proto +0 -42
  148. package/sandbox/gapi/googleapis/google/protobuf/unittest_no_field_presence.proto +0 -138
  149. package/sandbox/gapi/googleapis/google/protobuf/unittest_no_generic_services.proto +0 -54
  150. package/sandbox/gapi/googleapis/google/protobuf/unittest_optimize_for.proto +0 -67
  151. package/sandbox/gapi/googleapis/google/protobuf/unittest_preserve_unknown_enum.proto +0 -71
  152. package/sandbox/gapi/googleapis/google/protobuf/unittest_preserve_unknown_enum2.proto +0 -50
  153. package/sandbox/gapi/googleapis/google/protobuf/unittest_proto3.proto +0 -388
  154. package/sandbox/gapi/googleapis/google/protobuf/unittest_proto3_arena.proto +0 -206
  155. package/sandbox/gapi/googleapis/google/protobuf/unittest_well_known_types.proto +0 -112
  156. package/sandbox/gapi/googleapis/google/protobuf/unknown_enum_test.proto +0 -62
  157. package/sandbox/gapi/googleapis/google/protobuf/wrappers.proto +0 -117
  158. package/sandbox/gapi/googleapis/google/rpc/code.proto +0 -190
  159. package/sandbox/gapi/googleapis/google/rpc/error_details.proto +0 -157
  160. package/sandbox/gapi/googleapis/google/rpc/status.proto +0 -90
  161. package/sandbox/gapi/googleapis/google/type/color.proto +0 -163
  162. package/sandbox/gapi/googleapis/google/type/date.proto +0 -43
  163. package/sandbox/gapi/googleapis/google/type/dayofweek.proto +0 -50
  164. package/sandbox/gapi/googleapis/google/type/latlng.proto +0 -36
  165. package/sandbox/gapi/googleapis/google/type/money.proto +0 -40
  166. package/sandbox/gapi/googleapis/google/type/timeofday.proto +0 -42
  167. package/sandbox/gapi/test.js +0 -17
  168. package/sandbox/gapi/test.proto +0 -12
  169. package/sandbox/issue146/MyOptions.proto +0 -28
  170. package/sandbox/issue146/Sample.proto +0 -21
  171. package/sandbox/issue146/main.js +0 -3
  172. package/sandbox/issue147/enum.proto +0 -8
  173. package/sandbox/issue147/main.js +0 -3
  174. package/sandbox/issue182/commands.proto +0 -10
  175. package/sandbox/issue182/execute.js +0 -22
  176. package/sandbox/issue182/session_commands.proto +0 -14
  177. package/sandbox/issue289/A.proto +0 -8
  178. package/sandbox/issue289/B.proto +0 -8
  179. package/sandbox/issue289/common.proto +0 -5
  180. package/sandbox/issue289/main.js +0 -7
  181. package/sandbox/issue300/IAuth.proto +0 -14
  182. package/sandbox/issue300/Request.proto +0 -14
  183. package/sandbox/issue300/main.js +0 -26
  184. package/sandbox/issue42/innerextend.proto +0 -18
  185. package/sandbox/issue42/main.js +0 -8
  186. package/sandbox/issue42/outerextend.proto +0 -17
  187. package/tests/gtfs-realtime.proto +0 -552
  188. package/webpack.config.js +0 -9
package/index.js CHANGED
@@ -1,18 +1 @@
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
- var ProtoBuf = require("./dist/ProtoBuf.js");
17
-
18
- module.exports = ProtoBuf;
1
+ module.exports = require("./dist/protobuf.js");
package/jsdoc.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "allowUnknownTags": true
4
4
  },
5
5
  "source": {
6
- "include": ["dist/ProtoBuf.js"]
6
+ "include": ["dist/protobuf.js"]
7
7
  },
8
8
  "opts": {
9
9
  "destination": "docs"
package/package.json CHANGED
@@ -1,23 +1,23 @@
1
1
  {
2
2
  "name": "protobufjs",
3
- "version": "4.1.2",
3
+ "version": "5.0.2",
4
4
  "description": "Protocol Buffers for JavaScript. Finally.",
5
5
  "author": "Daniel Wirtz <dcode@dcode.io>",
6
6
  "contributors": [
7
7
  "Frank Xu <yyfrankyy@gmail.com>"
8
8
  ],
9
- "main": "dist/ProtoBuf.js",
9
+ "main": "./dist/protobuf.js",
10
10
  "bin": {
11
11
  "pbjs": "./bin/pbjs"
12
12
  },
13
13
  "repository": {
14
14
  "type": "git",
15
- "url": "https://github.com/dcodeIO/ProtoBuf.js.git"
15
+ "url": "https://github.com/dcodeIO/protobuf.js.git"
16
16
  },
17
17
  "bugs": {
18
- "url": "https://github.com/dcodeIO/ProtoBuf.js/issues"
18
+ "url": "https://github.com/dcodeIO/protobuf.js/issues"
19
19
  },
20
- "homepage": "https://github.com/dcodeIO/ProtoBuf.js",
20
+ "homepage": "https://github.com/dcodeIO/protobuf.js",
21
21
  "keywords": [
22
22
  "net",
23
23
  "buffer",
@@ -29,8 +29,8 @@
29
29
  ],
30
30
  "dependencies": {
31
31
  "ascli": "~1",
32
- "bytebuffer": "~4 >=4.1",
33
- "glob": "^5.0.10",
32
+ "bytebuffer": "~5",
33
+ "glob": "^7.0.5",
34
34
  "yargs": "^3.10.0"
35
35
  },
36
36
  "devDependencies": {
@@ -55,11 +55,11 @@
55
55
  "build": "node scripts/build.js",
56
56
  "descriptor2json": "node bin/pbjs src/google/protobuf/descriptor.proto --target=json > src/google/protobuf/descriptor.json",
57
57
  "compile": "npm run-script compile-full && npm run-script compile-light",
58
- "compile-full": "ccjs dist/ProtoBuf.js --create_source_map=dist/ProtoBuf.min.map --compilation_level=SIMPLE_OPTIMIZATIONS > dist/ProtoBuf.min.js",
59
- "compile-light": "ccjs dist/ProtoBuf-light.js --create_source_map=dist/ProtoBuf-light.min.map --compilation_level=SIMPLE_OPTIMIZATIONS > dist/ProtoBuf-light.min.js",
58
+ "compile-full": "ccjs dist/protobuf.js --create_source_map=dist/protobuf.min.map --compilation_level=SIMPLE_OPTIMIZATIONS > dist/protobuf.min.js",
59
+ "compile-light": "ccjs dist/protobuf-light.js --create_source_map=dist/protobuf-light.min.map --compilation_level=SIMPLE_OPTIMIZATIONS > dist/protobuf-light.min.js",
60
60
  "compress": "npm run-script compress-full && npm run-script compress-light",
61
- "compress-full": "gzip -c -9 dist/ProtoBuf.min.js > dist/ProtoBuf.min.js.gz",
62
- "compress-light": "gzip -c -9 dist/ProtoBuf-light.min.js > dist/ProtoBuf-light.min.js.gz",
61
+ "compress-full": "gzip -c -9 dist/protobuf.min.js > dist/protobuf.min.js.gz",
62
+ "compress-light": "gzip -c -9 dist/protobuf-light.min.js > dist/protobuf-light.min.js.gz",
63
63
  "jsdoc": "node node_modules/jsdoc/jsdoc.js -c jsdoc.json"
64
64
  }
65
65
  }
package/protobuf.png ADDED
Binary file
package/scripts/build.js CHANGED
@@ -1,58 +1,53 @@
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
- DOTPROTO: true // Whether to include the ProtoBuf.DotProto package for .proto syntax support
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, "wrap.js")), filename, scope, srcDir)
42
- );
43
-
44
- // Make light build
45
- scope.DOTPROTO = false;
46
- console.log("Building ProtoBuf-light.js with scope", JSON.stringify(scope, null, 2));
47
- fs.writeFileSync(
48
- path.join(distDir, "ProtoBuf-light.js"),
49
- MetaScript.transform(fs.readFileSync(filename = path.join(srcDir, "wrap.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
+ var MetaScript = require("metascript"),
18
+ path = require("path"),
19
+ fs = require("fs");
20
+
21
+ var rootDir = path.join(__dirname, ".."),
22
+ srcDir = path.join(rootDir, "src"),
23
+ distDir = path.join(rootDir, "dist"),
24
+ pkg = require(path.join(rootDir, "package.json")),
25
+ filename;
26
+
27
+ var scope = {
28
+ VERSION: pkg.version, // Version
29
+ DOTPROTO: true // Whether to include the ProtoBuf.DotProto package for .proto syntax support
30
+ };
31
+
32
+ // Make full build
33
+ console.log("Building protobuf.js with scope", JSON.stringify(scope, null, 2));
34
+ fs.writeFileSync(
35
+ path.join(distDir, "protobuf.js"),
36
+ MetaScript.transform(fs.readFileSync(filename = path.join(srcDir, "wrap.js")), filename, scope, srcDir)
37
+ );
38
+
39
+ // Make light build
40
+ scope.DOTPROTO = false;
41
+ console.log("Building protobuf-light.js with scope", JSON.stringify(scope, null, 2));
42
+ fs.writeFileSync(
43
+ path.join(distDir, "protobuf-light.js"),
44
+ MetaScript.transform(fs.readFileSync(filename = path.join(srcDir, "wrap.js")), filename, scope, srcDir)
45
+ );
46
+
47
+ // Update bower.json
48
+ scope = { VERSION: pkg.version };
49
+ console.log("Updating bower.json with scope", JSON.stringify(scope, null, 2));
50
+ fs.writeFileSync(
51
+ path.join(rootDir, "bower.json"),
52
+ MetaScript.transform(fs.readFileSync(filename = path.join(srcDir, "bower.json")), filename, scope, srcDir)
53
+ );
@@ -110,9 +110,11 @@ MessagePrototype.$add = MessagePrototype.add;
110
110
  MessagePrototype.set = function(keyOrObj, value, noAssert) {
111
111
  if (keyOrObj && typeof keyOrObj === 'object') {
112
112
  noAssert = value;
113
- for (var ikey in keyOrObj)
114
- if (keyOrObj.hasOwnProperty(ikey) && typeof (value = keyOrObj[ikey]) !== 'undefined')
113
+ for (var ikey in keyOrObj) {
114
+ // Check if virtual oneof field - don't set these
115
+ if (keyOrObj.hasOwnProperty(ikey) && typeof (value = keyOrObj[ikey]) !== 'undefined' && T._oneofsByName[ikey] === undefined)
115
116
  this.$set(ikey, value, noAssert);
117
+ }
116
118
  return this;
117
119
  }
118
120
  var field = T._fieldsByName[keyOrObj];
@@ -340,18 +342,19 @@ MessagePrototype.calculate = function() {
340
342
  * @name ProtoBuf.Builder.Message#encodeDelimited
341
343
  * @function
342
344
  * @param {(!ByteBuffer|boolean)=} buffer ByteBuffer to encode to. Will create a new one and flip it if omitted.
345
+ * @param {boolean=} noVerify Whether to not verify field values, defaults to `false`
343
346
  * @return {!ByteBuffer} Encoded message as a ByteBuffer
344
347
  * @throws {Error} If the message cannot be encoded or if required fields are missing. The later still
345
348
  * returns the encoded ByteBuffer in the `encoded` property on the error.
346
349
  * @expose
347
350
  */
348
- MessagePrototype.encodeDelimited = function(buffer) {
351
+ MessagePrototype.encodeDelimited = function(buffer, noVerify) {
349
352
  var isNew = false;
350
353
  if (!buffer)
351
354
  buffer = new ByteBuffer(),
352
355
  isNew = true;
353
356
  var enc = new ByteBuffer().LE();
354
- T.encode(this, enc).flip();
357
+ T.encode(this, enc, noVerify).flip();
355
358
  buffer.writeVarint32(enc.remaining());
356
359
  buffer.append(enc);
357
360
  return isNew ? buffer.flip() : buffer;
@@ -498,7 +501,7 @@ function cloneRaw(obj, binaryAsBase64, longsAsStrings, resolvedType) {
498
501
  return binaryAsBase64 ? obj.toBase64() : obj.toBuffer();
499
502
  // Convert Longs to proper objects or strings
500
503
  if (ProtoBuf.Long.isLong(obj))
501
- return longsAsStrings ? obj.toString() : new ProtoBuf.Long(obj);
504
+ return longsAsStrings ? obj.toString() : ProtoBuf.Long.fromValue(obj);
502
505
  var clone;
503
506
  // Clone arrays
504
507
  if (Array.isArray(obj)) {
@@ -560,6 +563,7 @@ MessagePrototype.encodeJSON = function() {
560
563
  * @name ProtoBuf.Builder.Message.decode
561
564
  * @function
562
565
  * @param {!ByteBuffer|!ArrayBuffer|!Buffer|string} buffer Buffer to decode from
566
+ * @param {(number|string)=} length Message length. Defaults to decode all the remainig data.
563
567
  * @param {string=} enc Encoding if buffer is a string: hex, utf8 (not recommended), defaults to base64
564
568
  * @return {!ProtoBuf.Builder.Message} Decoded message
565
569
  * @throws {Error} If the message cannot be decoded or if required fields are missing. The later still
@@ -568,13 +572,17 @@ MessagePrototype.encodeJSON = function() {
568
572
  * @see ProtoBuf.Builder.Message.decode64
569
573
  * @see ProtoBuf.Builder.Message.decodeHex
570
574
  */
571
- Message.decode = function(buffer, enc) {
575
+ Message.decode = function(buffer, length, enc) {
576
+ if (typeof length === 'string')
577
+ enc = length,
578
+ length = -1;
572
579
  if (typeof buffer === 'string')
573
580
  buffer = ByteBuffer.wrap(buffer, enc ? enc : "base64");
574
- buffer = ByteBuffer.isByteBuffer(buffer) ? buffer : ByteBuffer.wrap(buffer); // May throw
581
+ else if (!ByteBuffer.isByteBuffer(buffer))
582
+ buffer = ByteBuffer.wrap(buffer); // May throw
575
583
  var le = buffer.littleEndian;
576
584
  try {
577
- var msg = T.decode(buffer.LE());
585
+ var msg = T.decode(buffer.LE(), length);
578
586
  buffer.LE(le);
579
587
  return msg;
580
588
  } catch (e) {
@@ -597,7 +605,8 @@ Message.decode = function(buffer, enc) {
597
605
  Message.decodeDelimited = function(buffer, enc) {
598
606
  if (typeof buffer === 'string')
599
607
  buffer = ByteBuffer.wrap(buffer, enc ? enc : "base64");
600
- buffer = ByteBuffer.isByteBuffer(buffer) ? buffer : ByteBuffer.wrap(buffer); // May throw
608
+ else if (!ByteBuffer.isByteBuffer(buffer))
609
+ buffer = ByteBuffer.wrap(buffer); // May throw
601
610
  if (buffer.remaining() < 1)
602
611
  return null;
603
612
  var off = buffer.offset,
@@ -77,6 +77,9 @@ for (var i=0; i<rpc.length; i++) {
77
77
  callback(err);
78
78
  return;
79
79
  }
80
+ // Coalesce to empty string when service response has empty content
81
+ if (res === null)
82
+ res = ''
80
83
  try { res = method.resolvedResponseType.clazz.decode(res); } catch (notABuffer) {}
81
84
  if (!res || !(res instanceof method.resolvedResponseType.clazz)) {
82
85
  callback(Error("Illegal response type received in service method "+ T.name+"#"+method.name));
@@ -243,13 +243,12 @@ ProtoBuf.Builder = (function(ProtoBuf, Lang, Reflect) {
243
243
  subObj.push(svc);
244
244
  });
245
245
 
246
- // Set extension range
246
+ // Set extension ranges
247
247
  if (def["extensions"]) {
248
- obj.extensions = def["extensions"];
249
- if (obj.extensions[0] < ProtoBuf.ID_MIN)
250
- obj.extensions[0] = ProtoBuf.ID_MIN;
251
- if (obj.extensions[1] > ProtoBuf.ID_MAX)
252
- obj.extensions[1] = ProtoBuf.ID_MAX;
248
+ if (typeof def["extensions"][0] === 'number') // pre 5.0.1
249
+ obj.extensions = [ def["extensions"] ];
250
+ else
251
+ obj.extensions = def["extensions"];
253
252
  }
254
253
 
255
254
  // Create on top of current namespace
@@ -288,8 +287,16 @@ ProtoBuf.Builder = (function(ProtoBuf, Lang, Reflect) {
288
287
  def["fields"].forEach(function(fld) {
289
288
  if (obj.getChild(fld['id']|0) !== null)
290
289
  throw Error("duplicate extended field id in "+obj.name+": "+fld['id']);
291
- if (fld['id'] < obj.extensions[0] || fld['id'] > obj.extensions[1])
292
- throw Error("illegal extended field id in "+obj.name+": "+fld['id']+" ("+obj.extensions.join(' to ')+" expected)");
290
+ // Check if field id is allowed to be extended
291
+ if (obj.extensions) {
292
+ var valid = false;
293
+ obj.extensions.forEach(function(range) {
294
+ if (fld["id"] >= range[0] && fld["id"] <= range[1])
295
+ valid = true;
296
+ });
297
+ if (!valid)
298
+ throw Error("illegal extended field id in "+obj.name+": "+fld['id']+" (not within valid ranges)");
299
+ }
293
300
  // Convert extension field names to camel case notation if the override is set
294
301
  var name = fld["name"];
295
302
  if (this.options['convertFieldsToCamelCase'])
@@ -370,7 +377,11 @@ ProtoBuf.Builder = (function(ProtoBuf, Lang, Reflect) {
370
377
  root = require("path")['resolve'](root);
371
378
  if (root.indexOf("\\") >= 0 || filename.file.indexOf("\\") >= 0)
372
379
  delim = '\\';
373
- var fname = root + delim + filename.file;
380
+ var fname;
381
+ if (ProtoBuf.Util.IS_NODE)
382
+ fname = require("path")['join'](root, filename.file);
383
+ else
384
+ fname = root + delim + filename.file;
374
385
  if (this.files[fname] === true)
375
386
  return this.reset();
376
387
  this.files[fname] = true;
@@ -416,7 +427,10 @@ ProtoBuf.Builder = (function(ProtoBuf, Lang, Reflect) {
416
427
  var importFilename = json['imports'][i];
417
428
  if (importFilename === "google/protobuf/descriptor.proto")
418
429
  continue; // Not needed and therefore not used
419
- importFilename = importRoot + delim + importFilename;
430
+ if (ProtoBuf.Util.IS_NODE)
431
+ importFilename = require("path")['join'](importRoot, importFilename);
432
+ else
433
+ importFilename = importRoot + delim + importFilename;
420
434
  if (this.files[importFilename] === true)
421
435
  continue; // Already imported
422
436
  if (/\.proto$/i.test(importFilename) && !ProtoBuf.DotProto) // If this is a light build
@@ -514,6 +528,16 @@ ProtoBuf.Builder = (function(ProtoBuf, Lang, Reflect) {
514
528
  this.ptr.keyType = ProtoBuf.TYPES[this.ptr.keyType];
515
529
  }
516
530
 
531
+ // If it's a repeated and packable field then proto3 mandates it should be packed by
532
+ // default
533
+ if (
534
+ this.ptr.syntax === 'proto3' &&
535
+ this.ptr.repeated && this.ptr.options.packed === undefined &&
536
+ ProtoBuf.PACKABLE_WIRE_TYPES.indexOf(this.ptr.type.wireType) !== -1
537
+ ) {
538
+ this.ptr.options.packed = true;
539
+ }
540
+
517
541
  } else if (this.ptr instanceof ProtoBuf.Reflect.Service.Method) {
518
542
 
519
543
  if (this.ptr instanceof ProtoBuf.Reflect.Service.RPCMethod) {
@@ -50,7 +50,8 @@ ParserPrototype.parse = function() {
50
50
  // "syntax": undefined
51
51
  };
52
52
  var token,
53
- head = true;
53
+ head = true,
54
+ weak;
54
55
  try {
55
56
  while (token = this.tn.next()) {
56
57
  switch (token) {
@@ -67,11 +68,12 @@ ParserPrototype.parse = function() {
67
68
  if (!head)
68
69
  throw Error("unexpected 'import'");
69
70
  token = this.tn.peek();
70
- if (token === "public") // ignored
71
+ if (token === "public" || (weak = token === "weak")) // token ignored
71
72
  this.tn.next();
72
73
  token = this._readString();
73
74
  this.tn.skip(";");
74
- topLevel["imports"].push(token);
75
+ if (!weak) // import ignored
76
+ topLevel["imports"].push(token);
75
77
  break;
76
78
  case 'syntax':
77
79
  if (!head)
@@ -396,6 +398,7 @@ ParserPrototype._parseMessage = function(parent, fld) {
396
398
  "enums": [],
397
399
  "messages": [],
398
400
  "options": {},
401
+ "services": [],
399
402
  "oneofs": {}
400
403
  // "extensions": undefined
401
404
  };
@@ -422,8 +425,16 @@ ParserPrototype._parseMessage = function(parent, fld) {
422
425
  this._parseMessage(msg);
423
426
  else if (token === "option")
424
427
  this._parseOption(msg);
428
+ else if (token === "service")
429
+ this._parseService(msg);
425
430
  else if (token === "extensions")
426
- this._parseExtensions(msg);
431
+ if (msg.hasOwnProperty("extensions")) {
432
+ msg["extensions"] = msg["extensions"].concat(this._parseExtensionRanges())
433
+ } else {
434
+ msg["extensions"] = this._parseExtensionRanges();
435
+ }
436
+ else if (token === "reserved")
437
+ this._parseIgnored(); // TODO
427
438
  else if (token === "extend")
428
439
  this._parseExtend(msg);
429
440
  else if (Lang.TYPEREF.test(token)) {
@@ -438,6 +449,16 @@ ParserPrototype._parseMessage = function(parent, fld) {
438
449
  return msg;
439
450
  };
440
451
 
452
+ /**
453
+ * Parses an ignored statement.
454
+ * @private
455
+ */
456
+ ParserPrototype._parseIgnored = function() {
457
+ while (this.tn.peek() !== ';')
458
+ this.tn.next();
459
+ this.tn.skip(";");
460
+ };
461
+
441
462
  /**
442
463
  * Parses a message field.
443
464
  * @param {!Object} msg Message definition
@@ -600,29 +621,43 @@ ParserPrototype._parseEnum = function(msg) {
600
621
  };
601
622
 
602
623
  /**
603
- * Parses an extensions statement.
604
- * @param {!Object} msg Message object
624
+ * Parses extension / reserved ranges.
625
+ * @returns {!Array.<!Array.<number>>}
605
626
  * @private
606
627
  */
607
- ParserPrototype._parseExtensions = function(msg) {
608
- var token = this.tn.next(),
628
+ ParserPrototype._parseExtensionRanges = function() {
629
+ var ranges = [];
630
+ var token,
631
+ range,
632
+ value;
633
+ do {
609
634
  range = [];
610
- if (token === "min")
611
- range.push(ProtoBuf.ID_MIN);
612
- else if (token === "max")
613
- range.push(ProtoBuf.ID_MAX);
614
- else
615
- range.push(mkNumber(token));
616
- this.tn.skip("to");
617
- token = this.tn.next();
618
- if (token === "min")
619
- range.push(ProtoBuf.ID_MIN);
620
- else if (token === "max")
621
- range.push(ProtoBuf.ID_MAX);
622
- else
623
- range.push(mkNumber(token));
635
+ while (true) {
636
+ token = this.tn.next();
637
+ switch (token) {
638
+ case "min":
639
+ value = ProtoBuf.ID_MIN;
640
+ break;
641
+ case "max":
642
+ value = ProtoBuf.ID_MAX;
643
+ break;
644
+ default:
645
+ value = mkNumber(token);
646
+ break;
647
+ }
648
+ range.push(value);
649
+ if (range.length === 2)
650
+ break;
651
+ if (this.tn.peek() !== "to") {
652
+ range.push(value);
653
+ break;
654
+ }
655
+ this.tn.next();
656
+ }
657
+ ranges.push(range);
658
+ } while (this.tn.omit(","));
624
659
  this.tn.skip(";");
625
- msg["extensions"] = range;
660
+ return ranges;
626
661
  };
627
662
 
628
663
  /**
@@ -15,9 +15,11 @@
15
15
  * converted to string form if so.
16
16
  * @param {string} syntax Syntax level of defining message type, e.g.,
17
17
  * proto2 or proto3.
18
+ * @param {string} name Name of the field containing this element (for error
19
+ * messages)
18
20
  * @constructor
19
21
  */
20
- var Element = function(type, resolvedType, isMapKey, syntax) {
22
+ var Element = function(type, resolvedType, isMapKey, syntax, name) {
21
23
 
22
24
  /**
23
25
  * Element type, as a string (e.g., int32).
@@ -43,6 +45,12 @@ var Element = function(type, resolvedType, isMapKey, syntax) {
43
45
  */
44
46
  this.syntax = syntax;
45
47
 
48
+ /**
49
+ * Name of the field containing this element (for error messages)
50
+ * @type {string}
51
+ */
52
+ this.name = name;
53
+
46
54
  if (isMapKey && ProtoBuf.MAP_KEY_TYPES.indexOf(type) < 0)
47
55
  throw Error("Invalid map key type: " + type.name);
48
56
  };
@@ -93,6 +101,10 @@ function mkLong(value, unsigned) {
93
101
  throw Error("not convertible to Long");
94
102
  }
95
103
 
104
+ ElementPrototype.toString = function() {
105
+ return (this.name || '') + (this.isMapKey ? 'map' : 'value') + ' element';
106
+ }
107
+
96
108
  /**
97
109
  * Checks if the given value can be set for an element of this type (singular
98
110
  * field or one element of a repeated field or map).
@@ -102,9 +114,10 @@ function mkLong(value, unsigned) {
102
114
  * @expose
103
115
  */
104
116
  ElementPrototype.verifyValue = function(value) {
105
- var fail = function(val, msg) {
106
- throw Error("Illegal value for "+this.toString(true)+" of type "+this.type.name+": "+val+" ("+msg+")");
107
- }.bind(this);
117
+ var self = this;
118
+ function fail(val, msg) {
119
+ throw Error("Illegal value for "+self.toString(true)+" of type "+self.type.name+": "+val+" ("+msg+")");
120
+ }
108
121
  switch (this.type) {
109
122
  // Signed 32bit
110
123
  case ProtoBuf.TYPES["int32"]:
@@ -141,9 +141,9 @@ var FieldPrototype = Field.prototype = Object.create(T.prototype);
141
141
  * @expose
142
142
  */
143
143
  FieldPrototype.build = function() {
144
- this.element = new Element(this.type, this.resolvedType, false, this.syntax);
144
+ this.element = new Element(this.type, this.resolvedType, false, this.syntax, this.name);
145
145
  if (this.map)
146
- this.keyElement = new Element(this.keyType, undefined, true, this.syntax);
146
+ this.keyElement = new Element(this.keyType, undefined, true, this.syntax, this.name);
147
147
 
148
148
  // In proto3, fields do not have field presence, and every field is set to
149
149
  // its type's default value ("", 0, 0.0, or false).
@@ -165,9 +165,10 @@ FieldPrototype.build = function() {
165
165
  */
166
166
  FieldPrototype.verifyValue = function(value, skipRepeated) {
167
167
  skipRepeated = skipRepeated || false;
168
- var fail = function(val, msg) {
169
- throw Error("Illegal value for "+this.toString(true)+" of type "+this.type.name+": "+val+" ("+msg+")");
170
- }.bind(this);
168
+ var self = this;
169
+ function fail(val, msg) {
170
+ throw Error("Illegal value for "+self.toString(true)+" of type "+self.type.name+": "+val+" ("+msg+")");
171
+ }
171
172
  if (value === null) { // NULL values for optional fields
172
173
  if (this.required)
173
174
  fail(typeof value, "required");
@@ -20,10 +20,10 @@ var Message = function(builder, parent, name, options, isGroup, syntax) {
20
20
 
21
21
  /**
22
22
  * Extensions range.
23
- * @type {!Array.<number>}
23
+ * @type {!Array.<number>|undefined}
24
24
  * @expose
25
25
  */
26
- this.extensions = [ProtoBuf.ID_MIN, ProtoBuf.ID_MAX];
26
+ this.extensions = undefined;
27
27
 
28
28
  /**
29
29
  * Runtime message class.
@@ -94,6 +94,7 @@ MessagePrototype.build = function(rebuild) {
94
94
  this._fields = [];
95
95
  this._fieldsById = {};
96
96
  this._fieldsByName = {};
97
+ this._oneofsByName = {};
97
98
  for (var i=0, k=this.children.length, child; i<k; i++) {
98
99
  child = this.children[i];
99
100
  if (child instanceof Enum || child instanceof Message || child instanceof Service) {
@@ -105,6 +106,9 @@ MessagePrototype.build = function(rebuild) {
105
106
  this._fields.push(child),
106
107
  this._fieldsById[child.id] = child,
107
108
  this._fieldsByName[child.name] = child;
109
+ else if (child instanceof Message.OneOf) {
110
+ this._oneofsByName[child.name] = child;
111
+ }
108
112
  else if (!(child instanceof Message.OneOf) && !(child instanceof Extension)) // Not built
109
113
  throw Error("Illegal reflect child of "+this.toString(true)+": "+this.children[i].toString(true));
110
114
  }
@@ -204,14 +208,15 @@ function skipTillGroupEnd(expectedId, buf) {
204
208
  /**
205
209
  * Decodes an encoded message and returns the decoded message.
206
210
  * @param {ByteBuffer} buffer ByteBuffer to decode from
207
- * @param {number=} length Message length. Defaults to decode all the available data.
211
+ * @param {number=} length Message length. Defaults to decode all remaining data.
208
212
  * @param {number=} expectedGroupEndId Expected GROUPEND id if this is a legacy group
209
213
  * @return {ProtoBuf.Builder.Message} Decoded message
210
214
  * @throws {Error} If the message cannot be decoded
211
215
  * @expose
212
216
  */
213
217
  MessagePrototype.decode = function(buffer, length, expectedGroupEndId) {
214
- length = typeof length === 'number' ? length : -1;
218
+ if (typeof length !== 'number')
219
+ length = -1;
215
220
  var start = buffer.offset,
216
221
  msg = new (this.clazz)(),
217
222
  tag, wireType, id, field;