protobufjs 4.1.3 → 5.0.3

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 (80) 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} +92 -37
  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} +150 -60
  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 +106 -37
  20. package/docs/ProtoBuf.Builder.Service.html +9 -9
  21. package/docs/ProtoBuf.Builder.html +22 -22
  22. package/docs/ProtoBuf.DotProto.Parser.html +7 -7
  23. package/docs/ProtoBuf.DotProto.Tokenizer.html +11 -11
  24. package/docs/ProtoBuf.DotProto.html +2 -2
  25. package/docs/ProtoBuf.Map.html +6 -6
  26. package/docs/ProtoBuf.Reflect.Element.html +104 -8
  27. package/docs/ProtoBuf.Reflect.Enum.Value.html +10 -10
  28. package/docs/ProtoBuf.Reflect.Enum.html +21 -21
  29. package/docs/ProtoBuf.Reflect.Extension.html +3 -3
  30. package/docs/ProtoBuf.Reflect.Message.ExtensionField.html +29 -29
  31. package/docs/ProtoBuf.Reflect.Message.Field.html +28 -28
  32. package/docs/ProtoBuf.Reflect.Message.OneOf.html +10 -10
  33. package/docs/ProtoBuf.Reflect.Message.html +31 -28
  34. package/docs/ProtoBuf.Reflect.Namespace.html +19 -19
  35. package/docs/ProtoBuf.Reflect.Service.Method.html +11 -11
  36. package/docs/ProtoBuf.Reflect.Service.RPCMethod.html +17 -17
  37. package/docs/ProtoBuf.Reflect.Service.html +20 -20
  38. package/docs/ProtoBuf.Reflect.T.html +9 -9
  39. package/docs/ProtoBuf.Reflect.html +2 -2
  40. package/docs/ProtoBuf.Util.html +6 -6
  41. package/docs/ProtoBuf.html +28 -28
  42. package/docs/ProtoBuf.js.html +151 -61
  43. package/docs/index.html +1 -1
  44. package/donate.png +0 -0
  45. package/examples/websocket/server.js +4 -4
  46. package/externs/{ProtoBuf.js → protobuf.js} +25 -14
  47. package/index.js +1 -18
  48. package/jsdoc.json +1 -1
  49. package/package.json +11 -11
  50. package/protobuf.png +0 -0
  51. package/scripts/build.js +5 -10
  52. package/src/ProtoBuf/Builder/Message.js +17 -8
  53. package/src/ProtoBuf/Builder/Service.js +3 -0
  54. package/src/ProtoBuf/Builder.js +34 -10
  55. package/src/ProtoBuf/DotProto/Parser.js +58 -23
  56. package/src/ProtoBuf/Lang.js +2 -2
  57. package/src/ProtoBuf/Reflect/Element.js +17 -4
  58. package/src/ProtoBuf/Reflect/Message/Field.js +6 -5
  59. package/src/ProtoBuf/Reflect/Message.js +9 -4
  60. package/src/{bower.json → bower.json.in} +2 -2
  61. package/src/google/protobuf/descriptor.json +55 -15
  62. package/src/{ProtoBuf.js → protobuf.js} +0 -0
  63. package/src/wrap.js +4 -4
  64. package/tests/complex.json +8 -1
  65. package/tests/imports-weak.proto +7 -0
  66. package/tests/suite.js +107 -82
  67. package/.npmignore +0 -3
  68. package/ProtoBuf.png +0 -0
  69. package/dist/ProtoBuf-light.min.js +0 -87
  70. package/dist/ProtoBuf-light.min.js.gz +0 -0
  71. package/dist/ProtoBuf-light.min.map +0 -8
  72. package/dist/ProtoBuf.min.js +0 -108
  73. package/dist/ProtoBuf.min.js.gz +0 -0
  74. package/dist/ProtoBuf.min.map +0 -8
  75. package/examples/protoify/.npmignore +0 -2
  76. package/examples/websocket/.npmignore +0 -3
  77. package/externs/ByteBuffer.js +0 -767
  78. package/externs/Long.js +0 -328
  79. package/tests/gtfs-realtime.proto +0 -552
  80. package/webpack.config.js +0 -9
@@ -2,7 +2,7 @@
2
2
  <html lang="en">
3
3
  <head>
4
4
  <meta charset="utf-8">
5
- <title>JSDoc: Source: ProtoBuf.js</title>
5
+ <title>JSDoc: Source: protobuf.js</title>
6
6
 
7
7
  <script src="scripts/prettify/prettify.js"> </script>
8
8
  <script src="scripts/prettify/lang-css.js"> </script>
@@ -17,7 +17,7 @@
17
17
 
18
18
  <div id="main">
19
19
 
20
- <h1 class="page-title">Source: ProtoBuf.js</h1>
20
+ <h1 class="page-title">Source: protobuf.js</h1>
21
21
 
22
22
 
23
23
 
@@ -43,14 +43,14 @@
43
43
  */
44
44
 
45
45
  /**
46
- * @license ProtoBuf.js (c) 2013 Daniel Wirtz &lt;dcode@dcode.io>
46
+ * @license protobuf.js (c) 2013 Daniel Wirtz &lt;dcode@dcode.io>
47
47
  * Released under the Apache License, Version 2.0
48
- * see: https://github.com/dcodeIO/ProtoBuf.js for details
48
+ * see: https://github.com/dcodeIO/protobuf.js for details
49
49
  */
50
50
  (function(global, factory) {
51
51
 
52
52
  /* AMD */ if (typeof define === 'function' &amp;&amp; define["amd"])
53
- define(["ByteBuffer"], factory);
53
+ define(["bytebuffer"], factory);
54
54
  /* CommonJS */ else if (typeof require === "function" &amp;&amp; typeof module === "object" &amp;&amp; module &amp;&amp; module["exports"])
55
55
  module["exports"] = factory(require("bytebuffer"), true);
56
56
  /* Global */ else
@@ -85,7 +85,7 @@
85
85
  * @const
86
86
  * @expose
87
87
  */
88
- ProtoBuf.VERSION = "4.1.3";
88
+ ProtoBuf.VERSION = "5.0.2";
89
89
 
90
90
  /**
91
91
  * Wire types.
@@ -753,7 +753,8 @@
753
753
  // "syntax": undefined
754
754
  };
755
755
  var token,
756
- head = true;
756
+ head = true,
757
+ weak;
757
758
  try {
758
759
  while (token = this.tn.next()) {
759
760
  switch (token) {
@@ -770,11 +771,12 @@
770
771
  if (!head)
771
772
  throw Error("unexpected 'import'");
772
773
  token = this.tn.peek();
773
- if (token === "public") // ignored
774
+ if (token === "public" || (weak = token === "weak")) // token ignored
774
775
  this.tn.next();
775
776
  token = this._readString();
776
777
  this.tn.skip(";");
777
- topLevel["imports"].push(token);
778
+ if (!weak) // import ignored
779
+ topLevel["imports"].push(token);
778
780
  break;
779
781
  case 'syntax':
780
782
  if (!head)
@@ -1099,6 +1101,7 @@
1099
1101
  "enums": [],
1100
1102
  "messages": [],
1101
1103
  "options": {},
1104
+ "services": [],
1102
1105
  "oneofs": {}
1103
1106
  // "extensions": undefined
1104
1107
  };
@@ -1125,8 +1128,16 @@
1125
1128
  this._parseMessage(msg);
1126
1129
  else if (token === "option")
1127
1130
  this._parseOption(msg);
1131
+ else if (token === "service")
1132
+ this._parseService(msg);
1128
1133
  else if (token === "extensions")
1129
- this._parseExtensions(msg);
1134
+ if (msg.hasOwnProperty("extensions")) {
1135
+ msg["extensions"] = msg["extensions"].concat(this._parseExtensionRanges())
1136
+ } else {
1137
+ msg["extensions"] = this._parseExtensionRanges();
1138
+ }
1139
+ else if (token === "reserved")
1140
+ this._parseIgnored(); // TODO
1130
1141
  else if (token === "extend")
1131
1142
  this._parseExtend(msg);
1132
1143
  else if (Lang.TYPEREF.test(token)) {
@@ -1141,6 +1152,16 @@
1141
1152
  return msg;
1142
1153
  };
1143
1154
 
1155
+ /**
1156
+ * Parses an ignored statement.
1157
+ * @private
1158
+ */
1159
+ ParserPrototype._parseIgnored = function() {
1160
+ while (this.tn.peek() !== ';')
1161
+ this.tn.next();
1162
+ this.tn.skip(";");
1163
+ };
1164
+
1144
1165
  /**
1145
1166
  * Parses a message field.
1146
1167
  * @param {!Object} msg Message definition
@@ -1303,29 +1324,43 @@
1303
1324
  };
1304
1325
 
1305
1326
  /**
1306
- * Parses an extensions statement.
1307
- * @param {!Object} msg Message object
1327
+ * Parses extension / reserved ranges.
1328
+ * @returns {!Array.&lt;!Array.&lt;number>>}
1308
1329
  * @private
1309
1330
  */
1310
- ParserPrototype._parseExtensions = function(msg) {
1311
- var token = this.tn.next(),
1331
+ ParserPrototype._parseExtensionRanges = function() {
1332
+ var ranges = [];
1333
+ var token,
1334
+ range,
1335
+ value;
1336
+ do {
1312
1337
  range = [];
1313
- if (token === "min")
1314
- range.push(ProtoBuf.ID_MIN);
1315
- else if (token === "max")
1316
- range.push(ProtoBuf.ID_MAX);
1317
- else
1318
- range.push(mkNumber(token));
1319
- this.tn.skip("to");
1320
- token = this.tn.next();
1321
- if (token === "min")
1322
- range.push(ProtoBuf.ID_MIN);
1323
- else if (token === "max")
1324
- range.push(ProtoBuf.ID_MAX);
1325
- else
1326
- range.push(mkNumber(token));
1338
+ while (true) {
1339
+ token = this.tn.next();
1340
+ switch (token) {
1341
+ case "min":
1342
+ value = ProtoBuf.ID_MIN;
1343
+ break;
1344
+ case "max":
1345
+ value = ProtoBuf.ID_MAX;
1346
+ break;
1347
+ default:
1348
+ value = mkNumber(token);
1349
+ break;
1350
+ }
1351
+ range.push(value);
1352
+ if (range.length === 2)
1353
+ break;
1354
+ if (this.tn.peek() !== "to") {
1355
+ range.push(value);
1356
+ break;
1357
+ }
1358
+ this.tn.next();
1359
+ }
1360
+ ranges.push(range);
1361
+ } while (this.tn.omit(","));
1327
1362
  this.tn.skip(";");
1328
- msg["extensions"] = range;
1363
+ return ranges;
1329
1364
  };
1330
1365
 
1331
1366
  /**
@@ -1706,9 +1741,11 @@
1706
1741
  * converted to string form if so.
1707
1742
  * @param {string} syntax Syntax level of defining message type, e.g.,
1708
1743
  * proto2 or proto3.
1744
+ * @param {string} name Name of the field containing this element (for error
1745
+ * messages)
1709
1746
  * @constructor
1710
1747
  */
1711
- var Element = function(type, resolvedType, isMapKey, syntax) {
1748
+ var Element = function(type, resolvedType, isMapKey, syntax, name) {
1712
1749
 
1713
1750
  /**
1714
1751
  * Element type, as a string (e.g., int32).
@@ -1734,6 +1771,12 @@
1734
1771
  */
1735
1772
  this.syntax = syntax;
1736
1773
 
1774
+ /**
1775
+ * Name of the field containing this element (for error messages)
1776
+ * @type {string}
1777
+ */
1778
+ this.name = name;
1779
+
1737
1780
  if (isMapKey &amp;&amp; ProtoBuf.MAP_KEY_TYPES.indexOf(type) &lt; 0)
1738
1781
  throw Error("Invalid map key type: " + type.name);
1739
1782
  };
@@ -1784,6 +1827,10 @@
1784
1827
  throw Error("not convertible to Long");
1785
1828
  }
1786
1829
 
1830
+ ElementPrototype.toString = function() {
1831
+ return (this.name || '') + (this.isMapKey ? 'map' : 'value') + ' element';
1832
+ }
1833
+
1787
1834
  /**
1788
1835
  * Checks if the given value can be set for an element of this type (singular
1789
1836
  * field or one element of a repeated field or map).
@@ -1793,9 +1840,10 @@
1793
1840
  * @expose
1794
1841
  */
1795
1842
  ElementPrototype.verifyValue = function(value) {
1796
- var fail = function(val, msg) {
1797
- throw Error("Illegal value for "+this.toString(true)+" of type "+this.type.name+": "+val+" ("+msg+")");
1798
- }.bind(this);
1843
+ var self = this;
1844
+ function fail(val, msg) {
1845
+ throw Error("Illegal value for "+self.toString(true)+" of type "+self.type.name+": "+val+" ("+msg+")");
1846
+ }
1799
1847
  switch (this.type) {
1800
1848
  // Signed 32bit
1801
1849
  case ProtoBuf.TYPES["int32"]:
@@ -2285,10 +2333,10 @@
2285
2333
 
2286
2334
  /**
2287
2335
  * Extensions range.
2288
- * @type {!Array.&lt;number>}
2336
+ * @type {!Array.&lt;number>|undefined}
2289
2337
  * @expose
2290
2338
  */
2291
- this.extensions = [ProtoBuf.ID_MIN, ProtoBuf.ID_MAX];
2339
+ this.extensions = undefined;
2292
2340
 
2293
2341
  /**
2294
2342
  * Runtime message class.
@@ -2457,9 +2505,11 @@
2457
2505
  MessagePrototype.set = function(keyOrObj, value, noAssert) {
2458
2506
  if (keyOrObj &amp;&amp; typeof keyOrObj === 'object') {
2459
2507
  noAssert = value;
2460
- for (var ikey in keyOrObj)
2461
- if (keyOrObj.hasOwnProperty(ikey) &amp;&amp; typeof (value = keyOrObj[ikey]) !== 'undefined')
2508
+ for (var ikey in keyOrObj) {
2509
+ // Check if virtual oneof field - don't set these
2510
+ if (keyOrObj.hasOwnProperty(ikey) &amp;&amp; typeof (value = keyOrObj[ikey]) !== 'undefined' &amp;&amp; T._oneofsByName[ikey] === undefined)
2462
2511
  this.$set(ikey, value, noAssert);
2512
+ }
2463
2513
  return this;
2464
2514
  }
2465
2515
  var field = T._fieldsByName[keyOrObj];
@@ -2687,18 +2737,19 @@
2687
2737
  * @name ProtoBuf.Builder.Message#encodeDelimited
2688
2738
  * @function
2689
2739
  * @param {(!ByteBuffer|boolean)=} buffer ByteBuffer to encode to. Will create a new one and flip it if omitted.
2740
+ * @param {boolean=} noVerify Whether to not verify field values, defaults to `false`
2690
2741
  * @return {!ByteBuffer} Encoded message as a ByteBuffer
2691
2742
  * @throws {Error} If the message cannot be encoded or if required fields are missing. The later still
2692
2743
  * returns the encoded ByteBuffer in the `encoded` property on the error.
2693
2744
  * @expose
2694
2745
  */
2695
- MessagePrototype.encodeDelimited = function(buffer) {
2746
+ MessagePrototype.encodeDelimited = function(buffer, noVerify) {
2696
2747
  var isNew = false;
2697
2748
  if (!buffer)
2698
2749
  buffer = new ByteBuffer(),
2699
2750
  isNew = true;
2700
2751
  var enc = new ByteBuffer().LE();
2701
- T.encode(this, enc).flip();
2752
+ T.encode(this, enc, noVerify).flip();
2702
2753
  buffer.writeVarint32(enc.remaining());
2703
2754
  buffer.append(enc);
2704
2755
  return isNew ? buffer.flip() : buffer;
@@ -2907,6 +2958,7 @@
2907
2958
  * @name ProtoBuf.Builder.Message.decode
2908
2959
  * @function
2909
2960
  * @param {!ByteBuffer|!ArrayBuffer|!Buffer|string} buffer Buffer to decode from
2961
+ * @param {(number|string)=} length Message length. Defaults to decode all the remainig data.
2910
2962
  * @param {string=} enc Encoding if buffer is a string: hex, utf8 (not recommended), defaults to base64
2911
2963
  * @return {!ProtoBuf.Builder.Message} Decoded message
2912
2964
  * @throws {Error} If the message cannot be decoded or if required fields are missing. The later still
@@ -2915,13 +2967,17 @@
2915
2967
  * @see ProtoBuf.Builder.Message.decode64
2916
2968
  * @see ProtoBuf.Builder.Message.decodeHex
2917
2969
  */
2918
- Message.decode = function(buffer, enc) {
2970
+ Message.decode = function(buffer, length, enc) {
2971
+ if (typeof length === 'string')
2972
+ enc = length,
2973
+ length = -1;
2919
2974
  if (typeof buffer === 'string')
2920
2975
  buffer = ByteBuffer.wrap(buffer, enc ? enc : "base64");
2921
- buffer = ByteBuffer.isByteBuffer(buffer) ? buffer : ByteBuffer.wrap(buffer); // May throw
2976
+ else if (!ByteBuffer.isByteBuffer(buffer))
2977
+ buffer = ByteBuffer.wrap(buffer); // May throw
2922
2978
  var le = buffer.littleEndian;
2923
2979
  try {
2924
- var msg = T.decode(buffer.LE());
2980
+ var msg = T.decode(buffer.LE(), length);
2925
2981
  buffer.LE(le);
2926
2982
  return msg;
2927
2983
  } catch (e) {
@@ -2944,7 +3000,8 @@
2944
3000
  Message.decodeDelimited = function(buffer, enc) {
2945
3001
  if (typeof buffer === 'string')
2946
3002
  buffer = ByteBuffer.wrap(buffer, enc ? enc : "base64");
2947
- buffer = ByteBuffer.isByteBuffer(buffer) ? buffer : ByteBuffer.wrap(buffer); // May throw
3003
+ else if (!ByteBuffer.isByteBuffer(buffer))
3004
+ buffer = ByteBuffer.wrap(buffer); // May throw
2948
3005
  if (buffer.remaining() &lt; 1)
2949
3006
  return null;
2950
3007
  var off = buffer.offset,
@@ -3066,6 +3123,7 @@
3066
3123
  this._fields = [];
3067
3124
  this._fieldsById = {};
3068
3125
  this._fieldsByName = {};
3126
+ this._oneofsByName = {};
3069
3127
  for (var i=0, k=this.children.length, child; i&lt;k; i++) {
3070
3128
  child = this.children[i];
3071
3129
  if (child instanceof Enum || child instanceof Message || child instanceof Service) {
@@ -3077,6 +3135,9 @@
3077
3135
  this._fields.push(child),
3078
3136
  this._fieldsById[child.id] = child,
3079
3137
  this._fieldsByName[child.name] = child;
3138
+ else if (child instanceof Message.OneOf) {
3139
+ this._oneofsByName[child.name] = child;
3140
+ }
3080
3141
  else if (!(child instanceof Message.OneOf) &amp;&amp; !(child instanceof Extension)) // Not built
3081
3142
  throw Error("Illegal reflect child of "+this.toString(true)+": "+this.children[i].toString(true));
3082
3143
  }
@@ -3176,14 +3237,15 @@
3176
3237
  /**
3177
3238
  * Decodes an encoded message and returns the decoded message.
3178
3239
  * @param {ByteBuffer} buffer ByteBuffer to decode from
3179
- * @param {number=} length Message length. Defaults to decode all the available data.
3240
+ * @param {number=} length Message length. Defaults to decode all remaining data.
3180
3241
  * @param {number=} expectedGroupEndId Expected GROUPEND id if this is a legacy group
3181
3242
  * @return {ProtoBuf.Builder.Message} Decoded message
3182
3243
  * @throws {Error} If the message cannot be decoded
3183
3244
  * @expose
3184
3245
  */
3185
3246
  MessagePrototype.decode = function(buffer, length, expectedGroupEndId) {
3186
- length = typeof length === 'number' ? length : -1;
3247
+ if (typeof length !== 'number')
3248
+ length = -1;
3187
3249
  var start = buffer.offset,
3188
3250
  msg = new (this.clazz)(),
3189
3251
  tag, wireType, id, field;
@@ -3402,9 +3464,9 @@
3402
3464
  * @expose
3403
3465
  */
3404
3466
  FieldPrototype.build = function() {
3405
- this.element = new Element(this.type, this.resolvedType, false, this.syntax);
3467
+ this.element = new Element(this.type, this.resolvedType, false, this.syntax, this.name);
3406
3468
  if (this.map)
3407
- this.keyElement = new Element(this.keyType, undefined, true, this.syntax);
3469
+ this.keyElement = new Element(this.keyType, undefined, true, this.syntax, this.name);
3408
3470
 
3409
3471
  // In proto3, fields do not have field presence, and every field is set to
3410
3472
  // its type's default value ("", 0, 0.0, or false).
@@ -3426,9 +3488,10 @@
3426
3488
  */
3427
3489
  FieldPrototype.verifyValue = function(value, skipRepeated) {
3428
3490
  skipRepeated = skipRepeated || false;
3429
- var fail = function(val, msg) {
3430
- throw Error("Illegal value for "+this.toString(true)+" of type "+this.type.name+": "+val+" ("+msg+")");
3431
- }.bind(this);
3491
+ var self = this;
3492
+ function fail(val, msg) {
3493
+ throw Error("Illegal value for "+self.toString(true)+" of type "+self.type.name+": "+val+" ("+msg+")");
3494
+ }
3432
3495
  if (value === null) { // NULL values for optional fields
3433
3496
  if (this.required)
3434
3497
  fail(typeof value, "required");
@@ -4042,6 +4105,9 @@
4042
4105
  callback(err);
4043
4106
  return;
4044
4107
  }
4108
+ // Coalesce to empty string when service response has empty content
4109
+ if (res === null)
4110
+ res = ''
4045
4111
  try { res = method.resolvedResponseType.clazz.decode(res); } catch (notABuffer) {}
4046
4112
  if (!res || !(res instanceof method.resolvedResponseType.clazz)) {
4047
4113
  callback(Error("Illegal response type received in service method "+ T.name+"#"+method.name));
@@ -4485,13 +4551,12 @@
4485
4551
  subObj.push(svc);
4486
4552
  });
4487
4553
 
4488
- // Set extension range
4554
+ // Set extension ranges
4489
4555
  if (def["extensions"]) {
4490
- obj.extensions = def["extensions"];
4491
- if (obj.extensions[0] &lt; ProtoBuf.ID_MIN)
4492
- obj.extensions[0] = ProtoBuf.ID_MIN;
4493
- if (obj.extensions[1] > ProtoBuf.ID_MAX)
4494
- obj.extensions[1] = ProtoBuf.ID_MAX;
4556
+ if (typeof def["extensions"][0] === 'number') // pre 5.0.1
4557
+ obj.extensions = [ def["extensions"] ];
4558
+ else
4559
+ obj.extensions = def["extensions"];
4495
4560
  }
4496
4561
 
4497
4562
  // Create on top of current namespace
@@ -4530,8 +4595,16 @@
4530
4595
  def["fields"].forEach(function(fld) {
4531
4596
  if (obj.getChild(fld['id']|0) !== null)
4532
4597
  throw Error("duplicate extended field id in "+obj.name+": "+fld['id']);
4533
- if (fld['id'] &lt; obj.extensions[0] || fld['id'] > obj.extensions[1])
4534
- throw Error("illegal extended field id in "+obj.name+": "+fld['id']+" ("+obj.extensions.join(' to ')+" expected)");
4598
+ // Check if field id is allowed to be extended
4599
+ if (obj.extensions) {
4600
+ var valid = false;
4601
+ obj.extensions.forEach(function(range) {
4602
+ if (fld["id"] >= range[0] &amp;&amp; fld["id"] &lt;= range[1])
4603
+ valid = true;
4604
+ });
4605
+ if (!valid)
4606
+ throw Error("illegal extended field id in "+obj.name+": "+fld['id']+" (not within valid ranges)");
4607
+ }
4535
4608
  // Convert extension field names to camel case notation if the override is set
4536
4609
  var name = fld["name"];
4537
4610
  if (this.options['convertFieldsToCamelCase'])
@@ -4612,7 +4685,11 @@
4612
4685
  root = require("path")['resolve'](root);
4613
4686
  if (root.indexOf("\\") >= 0 || filename.file.indexOf("\\") >= 0)
4614
4687
  delim = '\\';
4615
- var fname = root + delim + filename.file;
4688
+ var fname;
4689
+ if (ProtoBuf.Util.IS_NODE)
4690
+ fname = require("path")['join'](root, filename.file);
4691
+ else
4692
+ fname = root + delim + filename.file;
4616
4693
  if (this.files[fname] === true)
4617
4694
  return this.reset();
4618
4695
  this.files[fname] = true;
@@ -4658,7 +4735,10 @@
4658
4735
  var importFilename = json['imports'][i];
4659
4736
  if (importFilename === "google/protobuf/descriptor.proto")
4660
4737
  continue; // Not needed and therefore not used
4661
- importFilename = importRoot + delim + importFilename;
4738
+ if (ProtoBuf.Util.IS_NODE)
4739
+ importFilename = require("path")['join'](importRoot, importFilename);
4740
+ else
4741
+ importFilename = importRoot + delim + importFilename;
4662
4742
  if (this.files[importFilename] === true)
4663
4743
  continue; // Already imported
4664
4744
  if (/\.proto$/i.test(importFilename) &amp;&amp; !ProtoBuf.DotProto) // If this is a light build
@@ -4756,6 +4836,16 @@
4756
4836
  this.ptr.keyType = ProtoBuf.TYPES[this.ptr.keyType];
4757
4837
  }
4758
4838
 
4839
+ // If it's a repeated and packable field then proto3 mandates it should be packed by
4840
+ // default
4841
+ if (
4842
+ this.ptr.syntax === 'proto3' &amp;&amp;
4843
+ this.ptr.repeated &amp;&amp; this.ptr.options.packed === undefined &amp;&amp;
4844
+ ProtoBuf.PACKABLE_WIRE_TYPES.indexOf(this.ptr.type.wireType) !== -1
4845
+ ) {
4846
+ this.ptr.options.packed = true;
4847
+ }
4848
+
4759
4849
  } else if (this.ptr instanceof ProtoBuf.Reflect.Service.Method) {
4760
4850
 
4761
4851
  if (this.ptr instanceof ProtoBuf.Reflect.Service.RPCMethod) {
@@ -5217,7 +5307,7 @@
5217
5307
  <br class="clear">
5218
5308
 
5219
5309
  <footer>
5220
- Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.3.3</a> on Tue Nov 17 2015 01:51:27 GMT+0100 (Mitteleuropäische Zeit)
5310
+ Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.3.3</a> on Fri Jan 27 2017 17:03:55 GMT+0100 (Mitteleuropäische Zeit)
5221
5311
  </footer>
5222
5312
 
5223
5313
  <script> prettyPrint(); </script>
package/docs/index.html CHANGED
@@ -56,7 +56,7 @@
56
56
  <br class="clear">
57
57
 
58
58
  <footer>
59
- Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.3.3</a> on Tue Nov 17 2015 01:51:27 GMT+0100 (Mitteleuropäische Zeit)
59
+ Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.3.3</a> on Fri Jan 27 2017 17:03:55 GMT+0100 (Mitteleuropäische Zeit)
60
60
  </footer>
61
61
 
62
62
  <script> prettyPrint(); </script>
package/donate.png ADDED
Binary file
@@ -8,9 +8,9 @@ var http = require("http"),
8
8
 
9
9
  // Copy dependencies to "www/" (example specific, you usually don't have to care
10
10
  var deps = [
11
- ["Long.min.js", "./node_modules/protobufjs/node_modules/bytebuffer/node_modules/long/dist/Long.min.js"],
12
- ["ByteBufferAB.min.js", "./node_modules/protobufjs/node_modules/bytebuffer/dist/ByteBufferAB.min.js"],
13
- ["ProtoBuf.min.js", "./node_modules/protobufjs/dist/ProtoBuf.min.js"]
11
+ ["Long.min.js", "./node_modules/long/dist/Long.min.js"],
12
+ ["ByteBufferAB.min.js", "./node_modules/bytebuffer/dist/ByteBufferAB.min.js"],
13
+ ["ProtoBuf.min.js", "./node_modules/protobufjs/dist/ProtoBuf.min.js"]
14
14
  ];
15
15
  for (var i=0, dep, data; i<deps.length; i++) {
16
16
  dep = deps[i];
@@ -68,7 +68,7 @@ server.on("error", function(err) {
68
68
  console.log("Failed to start server:", err);
69
69
  process.exit(1);
70
70
  });
71
-
71
+
72
72
  // WebSocket adapter
73
73
  var wss = new ws.Server({server: server});
74
74
  wss.on("connection", function(socket) {
@@ -27,7 +27,17 @@
27
27
  */
28
28
 
29
29
  /**
30
- * {@type object.<string.*>}
30
+ * @typedef {Array}
31
+ */
32
+ var Buffer;
33
+
34
+ /**
35
+ * @typedef {Object}
36
+ */
37
+ var dcodeIO;
38
+
39
+ /**
40
+ * {@type Object.<string.*>}
31
41
  */
32
42
  var ProtoBuf = {};
33
43
 
@@ -38,7 +48,7 @@ var ProtoBuf = {};
38
48
  ProtoBuf.VERSION;
39
49
 
40
50
  /**
41
- * @type {!object.<string,number>}
51
+ * @type {!Object.<string,number>}
42
52
  * @const
43
53
  */
44
54
  ProtoBuf.WIRE_TYPES = {};
@@ -97,7 +107,7 @@ ProtoBuf.populateAccessors;
97
107
 
98
108
  /**
99
109
  * @dict
100
- * @type {!object.<string,{name: string, wireType: number}>}
110
+ * @type {!Object<string,{name: string, wireType: number}>}
101
111
  * @const
102
112
  */
103
113
  ProtoBuf.TYPES;
@@ -113,22 +123,22 @@ ProtoBuf.ID_MIN;
113
123
  ProtoBuf.ID_MAX;
114
124
 
115
125
  /**
116
- * @type {!function(new: ByteBuffer, ...[*])}
126
+ * @type {!function(new: ByteBuffer, ...*)}
117
127
  */
118
128
  ProtoBuf.ByteBuffer;
119
129
 
120
130
  /**
121
- * @type {?function(new: Long, ...[*])}
131
+ * @type {?function(new: Long, ...*)}
122
132
  */
123
133
  ProtoBuf.Long;
124
134
 
125
135
  /**
126
- * @type {!object.<string,string|RegExp>}
136
+ * @type {!Object<string,string|RegExp>}
127
137
  */
128
138
  ProtoBuf.Lang;
129
139
 
130
140
  /**
131
- * @type {!object.<string,function>}
141
+ * @type {Object<string, function(*)>}
132
142
  */
133
143
  ProtoBuf.DotProto;
134
144
 
@@ -154,7 +164,7 @@ ProtoBuf.DotProto.Tokenizer.prototype.index;
154
164
  ProtoBuf.DotProto.Tokenizer.prototype.line;
155
165
 
156
166
  /**
157
- * @type {array.<string>}
167
+ * @type {Array.<string>}
158
168
  */
159
169
  ProtoBuf.DotProto.Tokenizer.prototype.stack;
160
170
 
@@ -171,7 +181,7 @@ ProtoBuf.DotProto.Tokenizer.prototype.next = function() {};
171
181
 
172
182
  /**
173
183
  * @return {?string}
174
- * @thorws {Error}
184
+ * @throws {Error}
175
185
  */
176
186
  ProtoBuf.DotProto.Tokenizer.prototype.peek = function() {};
177
187
 
@@ -193,7 +203,7 @@ ProtoBuf.DotProto.Parser = function(proto) {};
193
203
  ProtoBuf.DotProto.Parser.prototype.tn;
194
204
 
195
205
  /**
196
- * @return {{package: string|null, messages: Array.<object>, enums: Array.<object>, imports: Array.<string>, options: object<string,*>}}
206
+ * @return {{package: (string|null), messages: Array.<Object>, enums: Array.<Object>, imports: Array.<string>, options: Object<string,*>}}
197
207
  * @throws {Error}
198
208
  */
199
209
  ProtoBuf.DotProto.Parser.prototype.parse = function() {};
@@ -205,7 +215,7 @@ ProtoBuf.DotProto.Parser.prototype.parse = function() {};
205
215
  ProtoBuf.DotProto.Parser.prototype.toString = function() {};
206
216
 
207
217
  /**
208
- * @type {Object.<string,function>}
218
+ * @type {Object<string, function(*)>}
209
219
  */
210
220
  ProtoBuf.Reflect.Reflect = {};
211
221
 
@@ -339,10 +349,11 @@ ProtoBuf.Reflect.Message.prototype.calculate = function(message) {};
339
349
  /**
340
350
  * @param {!ProtoBuf.Builder.Message} message
341
351
  * @param {!ByteBuffer} buffer
352
+ * @param {boolean} noVerify
342
353
  * @return {!ByteBuffer}
343
354
  * @throws {Error}
344
355
  */
345
- ProtoBuf.Reflect.Message.prototype.encodeDelimited = function(message, buffer) {};
356
+ ProtoBuf.Reflect.Message.prototype.encodeDelimited = function(message, buffer, noVerify) {};
346
357
 
347
358
  /**
348
359
  * @param {!ByteBuffer} buffer
@@ -366,7 +377,7 @@ ProtoBuf.Reflect.Message.prototype.decodeDelimited = function(buffer, length) {}
366
377
  * @param {string} type
367
378
  * @param {string} name
368
379
  * @param {number} id
369
- * @param {Object.<string.*>=} options
380
+ * @param {Object<string>=} options
370
381
  * @constructor
371
382
  * @extends ProtoBuf.Reflect.T
372
383
  */
@@ -873,7 +884,7 @@ ProtoBuf.loadProtoFile = function(filename, callback, builder) {};
873
884
  ProtoBuf.protoFromFile = function(filename, callback, builder) {};
874
885
 
875
886
  /**
876
- * @param {!*|string} proto
887
+ * @param {!*|string} json
877
888
  * @param {(ProtoBuf.Builder|string|{root: string, file: string})=} builder
878
889
  * @param {(string|{root: string, file: string})=} filename
879
890
  * @return {!ProtoBuf.Builder}
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"