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
@@ -15,14 +15,14 @@
15
15
  */
16
16
 
17
17
  /**
18
- * @license ProtoBuf.js (c) 2013 Daniel Wirtz <dcode@dcode.io>
18
+ * @license protobuf.js (c) 2013 Daniel Wirtz <dcode@dcode.io>
19
19
  * Released under the Apache License, Version 2.0
20
- * see: https://github.com/dcodeIO/ProtoBuf.js for details
20
+ * see: https://github.com/dcodeIO/protobuf.js for details
21
21
  */
22
22
  (function(global, factory) {
23
23
 
24
24
  /* AMD */ if (typeof define === 'function' && define["amd"])
25
- define(["ByteBuffer"], factory);
25
+ define(["bytebuffer"], factory);
26
26
  /* CommonJS */ else if (typeof require === "function" && typeof module === "object" && module && module["exports"])
27
27
  module["exports"] = factory(require("bytebuffer"), true);
28
28
  /* Global */ else
@@ -57,7 +57,7 @@
57
57
  * @const
58
58
  * @expose
59
59
  */
60
- ProtoBuf.VERSION = "4.1.3";
60
+ ProtoBuf.VERSION = "5.0.3";
61
61
 
62
62
  /**
63
63
  * Wire types.
@@ -429,10 +429,10 @@
429
429
  TYPEDEF: /^[a-zA-Z][a-zA-Z_0-9]*$/,
430
430
 
431
431
  // Type references
432
- TYPEREF: /^(?:\.?[a-zA-Z_][a-zA-Z_0-9]*)+$/,
432
+ TYPEREF: /^(?:\.?[a-zA-Z_][a-zA-Z_0-9]*)(?:\.[a-zA-Z_][a-zA-Z_0-9]*)*$/,
433
433
 
434
434
  // Fully qualified type references
435
- FQTYPEREF: /^(?:\.[a-zA-Z][a-zA-Z_0-9]*)+$/,
435
+ FQTYPEREF: /^(?:\.[a-zA-Z_][a-zA-Z_0-9]*)+$/,
436
436
 
437
437
  // All numbers
438
438
  NUMBER: /^-?(?:[1-9][0-9]*|0|0[xX][0-9a-fA-F]+|0[0-7]+|([0-9]*(\.[0-9]*)?([Ee][+-]?[0-9]+)?)|inf|nan)$/,
@@ -725,7 +725,8 @@
725
725
  // "syntax": undefined
726
726
  };
727
727
  var token,
728
- head = true;
728
+ head = true,
729
+ weak;
729
730
  try {
730
731
  while (token = this.tn.next()) {
731
732
  switch (token) {
@@ -742,11 +743,12 @@
742
743
  if (!head)
743
744
  throw Error("unexpected 'import'");
744
745
  token = this.tn.peek();
745
- if (token === "public") // ignored
746
+ if (token === "public" || (weak = token === "weak")) // token ignored
746
747
  this.tn.next();
747
748
  token = this._readString();
748
749
  this.tn.skip(";");
749
- topLevel["imports"].push(token);
750
+ if (!weak) // import ignored
751
+ topLevel["imports"].push(token);
750
752
  break;
751
753
  case 'syntax':
752
754
  if (!head)
@@ -1071,6 +1073,7 @@
1071
1073
  "enums": [],
1072
1074
  "messages": [],
1073
1075
  "options": {},
1076
+ "services": [],
1074
1077
  "oneofs": {}
1075
1078
  // "extensions": undefined
1076
1079
  };
@@ -1097,8 +1100,16 @@
1097
1100
  this._parseMessage(msg);
1098
1101
  else if (token === "option")
1099
1102
  this._parseOption(msg);
1103
+ else if (token === "service")
1104
+ this._parseService(msg);
1100
1105
  else if (token === "extensions")
1101
- this._parseExtensions(msg);
1106
+ if (msg.hasOwnProperty("extensions")) {
1107
+ msg["extensions"] = msg["extensions"].concat(this._parseExtensionRanges())
1108
+ } else {
1109
+ msg["extensions"] = this._parseExtensionRanges();
1110
+ }
1111
+ else if (token === "reserved")
1112
+ this._parseIgnored(); // TODO
1102
1113
  else if (token === "extend")
1103
1114
  this._parseExtend(msg);
1104
1115
  else if (Lang.TYPEREF.test(token)) {
@@ -1113,6 +1124,16 @@
1113
1124
  return msg;
1114
1125
  };
1115
1126
 
1127
+ /**
1128
+ * Parses an ignored statement.
1129
+ * @private
1130
+ */
1131
+ ParserPrototype._parseIgnored = function() {
1132
+ while (this.tn.peek() !== ';')
1133
+ this.tn.next();
1134
+ this.tn.skip(";");
1135
+ };
1136
+
1116
1137
  /**
1117
1138
  * Parses a message field.
1118
1139
  * @param {!Object} msg Message definition
@@ -1275,29 +1296,43 @@
1275
1296
  };
1276
1297
 
1277
1298
  /**
1278
- * Parses an extensions statement.
1279
- * @param {!Object} msg Message object
1299
+ * Parses extension / reserved ranges.
1300
+ * @returns {!Array.<!Array.<number>>}
1280
1301
  * @private
1281
1302
  */
1282
- ParserPrototype._parseExtensions = function(msg) {
1283
- var token = this.tn.next(),
1303
+ ParserPrototype._parseExtensionRanges = function() {
1304
+ var ranges = [];
1305
+ var token,
1306
+ range,
1307
+ value;
1308
+ do {
1284
1309
  range = [];
1285
- if (token === "min")
1286
- range.push(ProtoBuf.ID_MIN);
1287
- else if (token === "max")
1288
- range.push(ProtoBuf.ID_MAX);
1289
- else
1290
- range.push(mkNumber(token));
1291
- this.tn.skip("to");
1292
- token = this.tn.next();
1293
- if (token === "min")
1294
- range.push(ProtoBuf.ID_MIN);
1295
- else if (token === "max")
1296
- range.push(ProtoBuf.ID_MAX);
1297
- else
1298
- range.push(mkNumber(token));
1310
+ while (true) {
1311
+ token = this.tn.next();
1312
+ switch (token) {
1313
+ case "min":
1314
+ value = ProtoBuf.ID_MIN;
1315
+ break;
1316
+ case "max":
1317
+ value = ProtoBuf.ID_MAX;
1318
+ break;
1319
+ default:
1320
+ value = mkNumber(token);
1321
+ break;
1322
+ }
1323
+ range.push(value);
1324
+ if (range.length === 2)
1325
+ break;
1326
+ if (this.tn.peek() !== "to") {
1327
+ range.push(value);
1328
+ break;
1329
+ }
1330
+ this.tn.next();
1331
+ }
1332
+ ranges.push(range);
1333
+ } while (this.tn.omit(","));
1299
1334
  this.tn.skip(";");
1300
- msg["extensions"] = range;
1335
+ return ranges;
1301
1336
  };
1302
1337
 
1303
1338
  /**
@@ -1678,9 +1713,11 @@
1678
1713
  * converted to string form if so.
1679
1714
  * @param {string} syntax Syntax level of defining message type, e.g.,
1680
1715
  * proto2 or proto3.
1716
+ * @param {string} name Name of the field containing this element (for error
1717
+ * messages)
1681
1718
  * @constructor
1682
1719
  */
1683
- var Element = function(type, resolvedType, isMapKey, syntax) {
1720
+ var Element = function(type, resolvedType, isMapKey, syntax, name) {
1684
1721
 
1685
1722
  /**
1686
1723
  * Element type, as a string (e.g., int32).
@@ -1706,6 +1743,12 @@
1706
1743
  */
1707
1744
  this.syntax = syntax;
1708
1745
 
1746
+ /**
1747
+ * Name of the field containing this element (for error messages)
1748
+ * @type {string}
1749
+ */
1750
+ this.name = name;
1751
+
1709
1752
  if (isMapKey && ProtoBuf.MAP_KEY_TYPES.indexOf(type) < 0)
1710
1753
  throw Error("Invalid map key type: " + type.name);
1711
1754
  };
@@ -1756,6 +1799,10 @@
1756
1799
  throw Error("not convertible to Long");
1757
1800
  }
1758
1801
 
1802
+ ElementPrototype.toString = function() {
1803
+ return (this.name || '') + (this.isMapKey ? 'map' : 'value') + ' element';
1804
+ }
1805
+
1759
1806
  /**
1760
1807
  * Checks if the given value can be set for an element of this type (singular
1761
1808
  * field or one element of a repeated field or map).
@@ -1765,9 +1812,10 @@
1765
1812
  * @expose
1766
1813
  */
1767
1814
  ElementPrototype.verifyValue = function(value) {
1768
- var fail = function(val, msg) {
1769
- throw Error("Illegal value for "+this.toString(true)+" of type "+this.type.name+": "+val+" ("+msg+")");
1770
- }.bind(this);
1815
+ var self = this;
1816
+ function fail(val, msg) {
1817
+ throw Error("Illegal value for "+self.toString(true)+" of type "+self.type.name+": "+val+" ("+msg+")");
1818
+ }
1771
1819
  switch (this.type) {
1772
1820
  // Signed 32bit
1773
1821
  case ProtoBuf.TYPES["int32"]:
@@ -2257,10 +2305,10 @@
2257
2305
 
2258
2306
  /**
2259
2307
  * Extensions range.
2260
- * @type {!Array.<number>}
2308
+ * @type {!Array.<number>|undefined}
2261
2309
  * @expose
2262
2310
  */
2263
- this.extensions = [ProtoBuf.ID_MIN, ProtoBuf.ID_MAX];
2311
+ this.extensions = undefined;
2264
2312
 
2265
2313
  /**
2266
2314
  * Runtime message class.
@@ -2429,9 +2477,11 @@
2429
2477
  MessagePrototype.set = function(keyOrObj, value, noAssert) {
2430
2478
  if (keyOrObj && typeof keyOrObj === 'object') {
2431
2479
  noAssert = value;
2432
- for (var ikey in keyOrObj)
2433
- if (keyOrObj.hasOwnProperty(ikey) && typeof (value = keyOrObj[ikey]) !== 'undefined')
2480
+ for (var ikey in keyOrObj) {
2481
+ // Check if virtual oneof field - don't set these
2482
+ if (keyOrObj.hasOwnProperty(ikey) && typeof (value = keyOrObj[ikey]) !== 'undefined' && T._oneofsByName[ikey] === undefined)
2434
2483
  this.$set(ikey, value, noAssert);
2484
+ }
2435
2485
  return this;
2436
2486
  }
2437
2487
  var field = T._fieldsByName[keyOrObj];
@@ -2659,18 +2709,19 @@
2659
2709
  * @name ProtoBuf.Builder.Message#encodeDelimited
2660
2710
  * @function
2661
2711
  * @param {(!ByteBuffer|boolean)=} buffer ByteBuffer to encode to. Will create a new one and flip it if omitted.
2712
+ * @param {boolean=} noVerify Whether to not verify field values, defaults to `false`
2662
2713
  * @return {!ByteBuffer} Encoded message as a ByteBuffer
2663
2714
  * @throws {Error} If the message cannot be encoded or if required fields are missing. The later still
2664
2715
  * returns the encoded ByteBuffer in the `encoded` property on the error.
2665
2716
  * @expose
2666
2717
  */
2667
- MessagePrototype.encodeDelimited = function(buffer) {
2718
+ MessagePrototype.encodeDelimited = function(buffer, noVerify) {
2668
2719
  var isNew = false;
2669
2720
  if (!buffer)
2670
2721
  buffer = new ByteBuffer(),
2671
2722
  isNew = true;
2672
2723
  var enc = new ByteBuffer().LE();
2673
- T.encode(this, enc).flip();
2724
+ T.encode(this, enc, noVerify).flip();
2674
2725
  buffer.writeVarint32(enc.remaining());
2675
2726
  buffer.append(enc);
2676
2727
  return isNew ? buffer.flip() : buffer;
@@ -2879,6 +2930,7 @@
2879
2930
  * @name ProtoBuf.Builder.Message.decode
2880
2931
  * @function
2881
2932
  * @param {!ByteBuffer|!ArrayBuffer|!Buffer|string} buffer Buffer to decode from
2933
+ * @param {(number|string)=} length Message length. Defaults to decode all the remainig data.
2882
2934
  * @param {string=} enc Encoding if buffer is a string: hex, utf8 (not recommended), defaults to base64
2883
2935
  * @return {!ProtoBuf.Builder.Message} Decoded message
2884
2936
  * @throws {Error} If the message cannot be decoded or if required fields are missing. The later still
@@ -2887,13 +2939,17 @@
2887
2939
  * @see ProtoBuf.Builder.Message.decode64
2888
2940
  * @see ProtoBuf.Builder.Message.decodeHex
2889
2941
  */
2890
- Message.decode = function(buffer, enc) {
2942
+ Message.decode = function(buffer, length, enc) {
2943
+ if (typeof length === 'string')
2944
+ enc = length,
2945
+ length = -1;
2891
2946
  if (typeof buffer === 'string')
2892
2947
  buffer = ByteBuffer.wrap(buffer, enc ? enc : "base64");
2893
- buffer = ByteBuffer.isByteBuffer(buffer) ? buffer : ByteBuffer.wrap(buffer); // May throw
2948
+ else if (!ByteBuffer.isByteBuffer(buffer))
2949
+ buffer = ByteBuffer.wrap(buffer); // May throw
2894
2950
  var le = buffer.littleEndian;
2895
2951
  try {
2896
- var msg = T.decode(buffer.LE());
2952
+ var msg = T.decode(buffer.LE(), length);
2897
2953
  buffer.LE(le);
2898
2954
  return msg;
2899
2955
  } catch (e) {
@@ -2916,7 +2972,8 @@
2916
2972
  Message.decodeDelimited = function(buffer, enc) {
2917
2973
  if (typeof buffer === 'string')
2918
2974
  buffer = ByteBuffer.wrap(buffer, enc ? enc : "base64");
2919
- buffer = ByteBuffer.isByteBuffer(buffer) ? buffer : ByteBuffer.wrap(buffer); // May throw
2975
+ else if (!ByteBuffer.isByteBuffer(buffer))
2976
+ buffer = ByteBuffer.wrap(buffer); // May throw
2920
2977
  if (buffer.remaining() < 1)
2921
2978
  return null;
2922
2979
  var off = buffer.offset,
@@ -3038,6 +3095,7 @@
3038
3095
  this._fields = [];
3039
3096
  this._fieldsById = {};
3040
3097
  this._fieldsByName = {};
3098
+ this._oneofsByName = {};
3041
3099
  for (var i=0, k=this.children.length, child; i<k; i++) {
3042
3100
  child = this.children[i];
3043
3101
  if (child instanceof Enum || child instanceof Message || child instanceof Service) {
@@ -3049,6 +3107,9 @@
3049
3107
  this._fields.push(child),
3050
3108
  this._fieldsById[child.id] = child,
3051
3109
  this._fieldsByName[child.name] = child;
3110
+ else if (child instanceof Message.OneOf) {
3111
+ this._oneofsByName[child.name] = child;
3112
+ }
3052
3113
  else if (!(child instanceof Message.OneOf) && !(child instanceof Extension)) // Not built
3053
3114
  throw Error("Illegal reflect child of "+this.toString(true)+": "+this.children[i].toString(true));
3054
3115
  }
@@ -3148,14 +3209,15 @@
3148
3209
  /**
3149
3210
  * Decodes an encoded message and returns the decoded message.
3150
3211
  * @param {ByteBuffer} buffer ByteBuffer to decode from
3151
- * @param {number=} length Message length. Defaults to decode all the available data.
3212
+ * @param {number=} length Message length. Defaults to decode all remaining data.
3152
3213
  * @param {number=} expectedGroupEndId Expected GROUPEND id if this is a legacy group
3153
3214
  * @return {ProtoBuf.Builder.Message} Decoded message
3154
3215
  * @throws {Error} If the message cannot be decoded
3155
3216
  * @expose
3156
3217
  */
3157
3218
  MessagePrototype.decode = function(buffer, length, expectedGroupEndId) {
3158
- length = typeof length === 'number' ? length : -1;
3219
+ if (typeof length !== 'number')
3220
+ length = -1;
3159
3221
  var start = buffer.offset,
3160
3222
  msg = new (this.clazz)(),
3161
3223
  tag, wireType, id, field;
@@ -3374,9 +3436,9 @@
3374
3436
  * @expose
3375
3437
  */
3376
3438
  FieldPrototype.build = function() {
3377
- this.element = new Element(this.type, this.resolvedType, false, this.syntax);
3439
+ this.element = new Element(this.type, this.resolvedType, false, this.syntax, this.name);
3378
3440
  if (this.map)
3379
- this.keyElement = new Element(this.keyType, undefined, true, this.syntax);
3441
+ this.keyElement = new Element(this.keyType, undefined, true, this.syntax, this.name);
3380
3442
 
3381
3443
  // In proto3, fields do not have field presence, and every field is set to
3382
3444
  // its type's default value ("", 0, 0.0, or false).
@@ -3398,9 +3460,10 @@
3398
3460
  */
3399
3461
  FieldPrototype.verifyValue = function(value, skipRepeated) {
3400
3462
  skipRepeated = skipRepeated || false;
3401
- var fail = function(val, msg) {
3402
- throw Error("Illegal value for "+this.toString(true)+" of type "+this.type.name+": "+val+" ("+msg+")");
3403
- }.bind(this);
3463
+ var self = this;
3464
+ function fail(val, msg) {
3465
+ throw Error("Illegal value for "+self.toString(true)+" of type "+self.type.name+": "+val+" ("+msg+")");
3466
+ }
3404
3467
  if (value === null) { // NULL values for optional fields
3405
3468
  if (this.required)
3406
3469
  fail(typeof value, "required");
@@ -4014,6 +4077,9 @@
4014
4077
  callback(err);
4015
4078
  return;
4016
4079
  }
4080
+ // Coalesce to empty string when service response has empty content
4081
+ if (res === null)
4082
+ res = ''
4017
4083
  try { res = method.resolvedResponseType.clazz.decode(res); } catch (notABuffer) {}
4018
4084
  if (!res || !(res instanceof method.resolvedResponseType.clazz)) {
4019
4085
  callback(Error("Illegal response type received in service method "+ T.name+"#"+method.name));
@@ -4457,13 +4523,12 @@
4457
4523
  subObj.push(svc);
4458
4524
  });
4459
4525
 
4460
- // Set extension range
4526
+ // Set extension ranges
4461
4527
  if (def["extensions"]) {
4462
- obj.extensions = def["extensions"];
4463
- if (obj.extensions[0] < ProtoBuf.ID_MIN)
4464
- obj.extensions[0] = ProtoBuf.ID_MIN;
4465
- if (obj.extensions[1] > ProtoBuf.ID_MAX)
4466
- obj.extensions[1] = ProtoBuf.ID_MAX;
4528
+ if (typeof def["extensions"][0] === 'number') // pre 5.0.1
4529
+ obj.extensions = [ def["extensions"] ];
4530
+ else
4531
+ obj.extensions = def["extensions"];
4467
4532
  }
4468
4533
 
4469
4534
  // Create on top of current namespace
@@ -4502,8 +4567,16 @@
4502
4567
  def["fields"].forEach(function(fld) {
4503
4568
  if (obj.getChild(fld['id']|0) !== null)
4504
4569
  throw Error("duplicate extended field id in "+obj.name+": "+fld['id']);
4505
- if (fld['id'] < obj.extensions[0] || fld['id'] > obj.extensions[1])
4506
- throw Error("illegal extended field id in "+obj.name+": "+fld['id']+" ("+obj.extensions.join(' to ')+" expected)");
4570
+ // Check if field id is allowed to be extended
4571
+ if (obj.extensions) {
4572
+ var valid = false;
4573
+ obj.extensions.forEach(function(range) {
4574
+ if (fld["id"] >= range[0] && fld["id"] <= range[1])
4575
+ valid = true;
4576
+ });
4577
+ if (!valid)
4578
+ throw Error("illegal extended field id in "+obj.name+": "+fld['id']+" (not within valid ranges)");
4579
+ }
4507
4580
  // Convert extension field names to camel case notation if the override is set
4508
4581
  var name = fld["name"];
4509
4582
  if (this.options['convertFieldsToCamelCase'])
@@ -4584,7 +4657,11 @@
4584
4657
  root = require("path")['resolve'](root);
4585
4658
  if (root.indexOf("\\") >= 0 || filename.file.indexOf("\\") >= 0)
4586
4659
  delim = '\\';
4587
- var fname = root + delim + filename.file;
4660
+ var fname;
4661
+ if (ProtoBuf.Util.IS_NODE)
4662
+ fname = require("path")['join'](root, filename.file);
4663
+ else
4664
+ fname = root + delim + filename.file;
4588
4665
  if (this.files[fname] === true)
4589
4666
  return this.reset();
4590
4667
  this.files[fname] = true;
@@ -4630,7 +4707,10 @@
4630
4707
  var importFilename = json['imports'][i];
4631
4708
  if (importFilename === "google/protobuf/descriptor.proto")
4632
4709
  continue; // Not needed and therefore not used
4633
- importFilename = importRoot + delim + importFilename;
4710
+ if (ProtoBuf.Util.IS_NODE)
4711
+ importFilename = require("path")['join'](importRoot, importFilename);
4712
+ else
4713
+ importFilename = importRoot + delim + importFilename;
4634
4714
  if (this.files[importFilename] === true)
4635
4715
  continue; // Already imported
4636
4716
  if (/\.proto$/i.test(importFilename) && !ProtoBuf.DotProto) // If this is a light build
@@ -4728,6 +4808,16 @@
4728
4808
  this.ptr.keyType = ProtoBuf.TYPES[this.ptr.keyType];
4729
4809
  }
4730
4810
 
4811
+ // If it's a repeated and packable field then proto3 mandates it should be packed by
4812
+ // default
4813
+ if (
4814
+ this.ptr.syntax === 'proto3' &&
4815
+ this.ptr.repeated && this.ptr.options.packed === undefined &&
4816
+ ProtoBuf.PACKABLE_WIRE_TYPES.indexOf(this.ptr.type.wireType) !== -1
4817
+ ) {
4818
+ this.ptr.options.packed = true;
4819
+ }
4820
+
4731
4821
  } else if (this.ptr instanceof ProtoBuf.Reflect.Service.Method) {
4732
4822
 
4733
4823
  if (this.ptr instanceof ProtoBuf.Reflect.Service.RPCMethod) {