protobufjs 8.6.6 → 8.7.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/src/parse.js CHANGED
@@ -220,6 +220,9 @@ function parse(source, root, options) {
220
220
  }
221
221
 
222
222
  function parseId(token, acceptNegative, max) {
223
+ if (token === null) {
224
+ throw illegal(token, "end of input");
225
+ }
223
226
  switch (token) {
224
227
  case "max": case "MAX": case "Max":
225
228
  return max || maxFieldId;
@@ -252,7 +255,7 @@ function parse(source, root, options) {
252
255
  pkg = next();
253
256
 
254
257
  /* istanbul ignore if */
255
- if (!typeRefRe.test(pkg))
258
+ if (pkg === null || !typeRefRe.test(pkg))
256
259
  throw illegal(pkg, "name");
257
260
 
258
261
  ptr = ptr.define(pkg);
@@ -389,7 +392,7 @@ function parse(source, root, options) {
389
392
  throw Error("max depth exceeded");
390
393
 
391
394
  /* istanbul ignore if */
392
- if (!nameRe.test(token = next()))
395
+ if ((token = next()) === null || !nameRe.test(token))
393
396
  throw illegal(token, "type name");
394
397
 
395
398
  var type = new Type(token);
@@ -456,6 +459,9 @@ function parse(source, root, options) {
456
459
 
457
460
  function parseField(parent, rule, extend, depth) {
458
461
  var type = next();
462
+ if (type === null) {
463
+ throw illegal(type, "end of input");
464
+ }
459
465
  if (type === "group") {
460
466
  parseGroup(parent, rule, extend, depth);
461
467
  return;
@@ -467,8 +473,12 @@ function parse(source, root, options) {
467
473
  // package .subpackage field tokens: "package" ".subpackage" [TYPE NAME ENDS HERE] "field"
468
474
  // Keep reading tokens until we get a type name with no period at the end,
469
475
  // and the next token does not start with a period.
470
- while (type.endsWith(".") || peek().startsWith(".")) {
471
- type += next();
476
+ while (type.endsWith(".") || (peek() || "").startsWith(".")) {
477
+ var part = next();
478
+ if (part === null) {
479
+ throw illegal(part, "end of input");
480
+ }
481
+ type += part;
472
482
  }
473
483
 
474
484
  /* istanbul ignore if */
@@ -476,6 +486,9 @@ function parse(source, root, options) {
476
486
  throw illegal(type, "type");
477
487
 
478
488
  var name = next();
489
+ if (name === null) {
490
+ throw illegal(name, "end of input");
491
+ }
479
492
 
480
493
  /* istanbul ignore if */
481
494
 
@@ -528,7 +541,7 @@ function parse(source, root, options) {
528
541
  var name = next();
529
542
 
530
543
  /* istanbul ignore if */
531
- if (!nameRe.test(name))
544
+ if (name === null || !nameRe.test(name))
532
545
  throw illegal(name, "name");
533
546
 
534
547
  var fieldName = util.lcFirst(name);
@@ -546,6 +559,10 @@ function parse(source, root, options) {
546
559
  case ";":
547
560
  break;
548
561
 
562
+ case "map":
563
+ parseMapField(type);
564
+ break;
565
+
549
566
  case "option":
550
567
  parseOption(type, token);
551
568
  skip(";");
@@ -626,7 +643,7 @@ function parse(source, root, options) {
626
643
  var name = next();
627
644
 
628
645
  /* istanbul ignore if */
629
- if (!nameRe.test(name))
646
+ if (name === null || !nameRe.test(name))
630
647
  throw illegal(name, "name");
631
648
 
632
649
  skip("=");
@@ -653,7 +670,7 @@ function parse(source, root, options) {
653
670
  function parseOneOf(parent, token, depth) {
654
671
 
655
672
  /* istanbul ignore if */
656
- if (!nameRe.test(token = next()))
673
+ if ((token = next()) === null || !nameRe.test(token))
657
674
  throw illegal(token, "name");
658
675
 
659
676
  var oneof = new OneOf(applyCase(token));
@@ -672,10 +689,11 @@ function parse(source, root, options) {
672
689
  function parseEnum(parent, token) {
673
690
 
674
691
  /* istanbul ignore if */
675
- if (!nameRe.test(token = next()))
692
+ if ((token = next()) === null || !nameRe.test(token))
676
693
  throw illegal(token, "name");
677
694
 
678
- var enm = new Enum(token);
695
+ var enm = new Enum(token),
696
+ values = [];
679
697
  ifBlock(enm, function parseEnum_block(token) {
680
698
  switch(token) {
681
699
  case ";":
@@ -692,16 +710,18 @@ function parse(source, root, options) {
692
710
  break;
693
711
 
694
712
  default:
695
- parseEnumValue(enm, token);
713
+ values.push(parseEnumValue(token));
696
714
  }
697
715
  });
716
+ for (var i = 0; i < values.length; ++i)
717
+ enm.add(values[i].name, values[i].id, values[i].comment, values[i].options);
698
718
  parent.add(enm);
699
719
  if (parent === ptr) {
700
720
  topLevelObjects.push(enm);
701
721
  }
702
722
  }
703
723
 
704
- function parseEnumValue(parent, token) {
724
+ function parseEnumValue(token) {
705
725
 
706
726
  /* istanbul ignore if */
707
727
  if (!nameRe.test(token))
@@ -733,7 +753,12 @@ function parse(source, root, options) {
733
753
  }, function parseEnumValue_line() {
734
754
  parseInlineOptions(dummy); // skip
735
755
  });
736
- parent.add(token, value, dummy.comment, dummy.parsedOptions || dummy.options);
756
+ return {
757
+ name: token,
758
+ id: value,
759
+ comment: dummy.comment,
760
+ options: dummy.parsedOptions || dummy.options
761
+ };
737
762
  }
738
763
 
739
764
  function parseOption(parent, token) {
@@ -784,16 +809,27 @@ function parse(source, root, options) {
784
809
  var objectResult = {};
785
810
 
786
811
  while (!skip("}", true)) {
787
- /* istanbul ignore if */
788
- if (!nameRe.test(token = next())) {
789
- throw illegal(token, "name");
790
- }
791
- if (token === null) {
792
- throw illegal(token, "end of input");
812
+ token = next();
813
+ var propName;
814
+ if (token === null)
815
+ throw illegal(token, "end of input");
816
+ if (token === "[") {
817
+ token = next();
818
+ // Extension name or, for Any, a type URL: "<prefix>/<fully.qualified.Type>".
819
+ var slash = token === null ? -1 : token.lastIndexOf("/");
820
+ if (token === null || !typeRefRe.test(slash < 0 ? token : token.slice(slash + 1)))
821
+ throw illegal(token, "name");
822
+ propName = "[" + token + "]";
823
+ skip("]");
824
+ } else {
825
+ /* istanbul ignore if */
826
+ if (!nameRe.test(token)) {
827
+ throw illegal(token, "name");
828
+ }
829
+ propName = token;
793
830
  }
794
831
 
795
832
  var value;
796
- var propName = token;
797
833
 
798
834
  skip(":", true);
799
835
 
@@ -801,25 +837,30 @@ function parse(source, root, options) {
801
837
  // option (my_option) = {
802
838
  // repeated_value: [ "foo", "bar" ]
803
839
  // };
804
- value = parseOptionValue(parent, name + "." + token, depth + 1);
840
+ value = parseOptionValue(parent, name + "." + propName, depth + 1);
805
841
  } else if (peek() === "[") {
806
842
  value = [];
807
- var lastValue;
843
+ var lastValue,
844
+ lastValueIsAggregate;
808
845
  if (skip("[", true)) {
809
846
  if (!skip("]", true)) {
810
847
  do {
811
- lastValue = readValue(true);
848
+ lastValueIsAggregate = peek() === "{";
849
+ lastValue = lastValueIsAggregate
850
+ ? parseOptionValue(parent, name + "." + propName, depth + 1)
851
+ : readValue(true);
812
852
  value.push(lastValue);
813
853
  } while (skip(",", true));
814
854
  skip("]");
815
855
  if (typeof lastValue !== "undefined") {
816
- setOption(parent, name + "." + token, lastValue);
856
+ if (!lastValueIsAggregate)
857
+ setOption(parent, name + "." + propName, lastValue);
817
858
  }
818
859
  }
819
860
  }
820
861
  } else {
821
862
  value = readValue(true);
822
- setOption(parent, name + "." + token, value);
863
+ setOption(parent, name + "." + propName, value);
823
864
  }
824
865
 
825
866
  var prevValue = Object.prototype.hasOwnProperty.call(objectResult, propName)
@@ -854,15 +895,12 @@ function parse(source, root, options) {
854
895
  // lift json_name onto Field
855
896
  if (name === "json_name" && parent instanceof Field) {
856
897
  parent.jsonName = value;
857
- return;
858
898
  }
859
899
  if (parent.setOption)
860
900
  parent.setOption(name, value);
861
901
  }
862
902
 
863
903
  function setParsedOption(parent, name, value, propName) {
864
- if (name === "json_name" && parent instanceof Field)
865
- return; // lifted onto Field#jsonName above
866
904
  if (parent.setParsedOption)
867
905
  parent.setParsedOption(name, value, propName);
868
906
  }
@@ -884,7 +922,7 @@ function parse(source, root, options) {
884
922
  throw Error("max depth exceeded");
885
923
 
886
924
  /* istanbul ignore if */
887
- if (!nameRe.test(token = next()))
925
+ if ((token = next()) === null || !nameRe.test(token))
888
926
  throw illegal(token, "service name");
889
927
 
890
928
  var service = new Service(token);
@@ -962,7 +1000,7 @@ function parse(source, root, options) {
962
1000
  function parseExtension(parent, token, depth) {
963
1001
 
964
1002
  /* istanbul ignore if */
965
- if (!typeRefRe.test(token = next()))
1003
+ if ((token = next()) === null || !typeRefRe.test(token))
966
1004
  throw illegal(token, "reference");
967
1005
 
968
1006
  var reference = token;
package/src/reader.js CHANGED
@@ -15,7 +15,7 @@ function indexOutOfRange(reader, writeLength) {
15
15
 
16
16
  /**
17
17
  * Constructs a new reader instance using the specified buffer.
18
- * @classdesc Wire format reader using `Uint8Array` if available, otherwise `Array`.
18
+ * @classdesc Wire format reader using `Uint8Array`.
19
19
  * @constructor
20
20
  * @param {Uint8Array} buffer Buffer to read from
21
21
  */
@@ -39,6 +39,12 @@ function Reader(buffer) {
39
39
  */
40
40
  this.len = buffer.length;
41
41
 
42
+ /**
43
+ * Cached DataView for packed reads.
44
+ * @type {DataView|null}
45
+ */
46
+ this.view = null;
47
+
42
48
  /**
43
49
  * Whether to discard unknown fields while decoding.
44
50
  * @type {boolean}
@@ -46,18 +52,14 @@ function Reader(buffer) {
46
52
  this.discardUnknown = Reader.discardUnknown;
47
53
  }
48
54
 
49
- var create_array = typeof Uint8Array !== "undefined"
50
- ? function create_typed_array(buffer) {
51
- if (buffer instanceof Uint8Array || Array.isArray(buffer))
52
- return new Reader(buffer);
53
- throw Error("illegal buffer");
54
- }
55
- /* istanbul ignore next */
56
- : function create_array(buffer) {
57
- if (Array.isArray(buffer))
58
- return new Reader(buffer);
59
- throw Error("illegal buffer");
60
- };
55
+ function create_array(buffer) {
56
+ // TODO: Remove plain array reader support in the next major release.
57
+ if (Array.isArray(buffer))
58
+ buffer = new Uint8Array(buffer);
59
+ if (buffer instanceof Uint8Array)
60
+ return new Reader(buffer);
61
+ throw Error("illegal buffer");
62
+ }
61
63
 
62
64
  var create = function create() {
63
65
  return util.Buffer
@@ -82,8 +84,6 @@ var create = function create() {
82
84
  */
83
85
  Reader.create = create();
84
86
 
85
- Reader.prototype._slice = util.Array.prototype.subarray || /* istanbul ignore next */ util.Array.prototype.slice;
86
-
87
87
  /**
88
88
  * Returns raw bytes from the backing buffer without advancing the reader.
89
89
  * @param {number} start Start offset
@@ -91,12 +91,7 @@ Reader.prototype._slice = util.Array.prototype.subarray || /* istanbul ignore ne
91
91
  * @returns {Uint8Array} Raw bytes
92
92
  */
93
93
  Reader.prototype.raw = function read_raw(start, end) {
94
- if (Array.isArray(this.buf)) // plain array
95
- return this.buf.slice(start, end);
96
-
97
- if (start === end) // fix for IE 10/Win8 and others' subarray returning array of size 1
98
- return new this.buf.constructor(0);
99
- return this._slice.call(this.buf, start, end);
94
+ return this.buf.subarray(start, end);
100
95
  };
101
96
 
102
97
  /**
@@ -393,6 +388,241 @@ Reader.prototype.double = function read_double() {
393
388
  return value;
394
389
  };
395
390
 
391
+ /**
392
+ * Reads a packed repeated field of unsigned 32 bit varints.
393
+ * @param {number[]} [array] Array to read into; a new one is created if omitted
394
+ * @returns {number[]} Array read into
395
+ */
396
+ Reader.prototype.uint32s = function read_uint32s(array) {
397
+ if (array === undefined) array = [];
398
+ var end = this.uint32() + this.pos;
399
+ while (this.pos < end)
400
+ array.push(this.uint32());
401
+ return array;
402
+ };
403
+
404
+ /**
405
+ * Reads a packed repeated field of signed 32 bit varints.
406
+ * @param {number[]} [array] Array to read into; a new one is created if omitted
407
+ * @returns {number[]} Array read into
408
+ */
409
+ Reader.prototype.int32s = function read_int32s(array) {
410
+ if (array === undefined) array = [];
411
+ var end = this.uint32() + this.pos;
412
+ while (this.pos < end)
413
+ array.push(this.int32());
414
+ return array;
415
+ };
416
+
417
+ /**
418
+ * Reads a packed repeated field of zig-zag encoded signed 32 bit varints.
419
+ * @param {number[]} [array] Array to read into; a new one is created if omitted
420
+ * @returns {number[]} Array read into
421
+ */
422
+ Reader.prototype.sint32s = function read_sint32s(array) {
423
+ if (array === undefined) array = [];
424
+ var end = this.uint32() + this.pos;
425
+ while (this.pos < end)
426
+ array.push(this.sint32());
427
+ return array;
428
+ };
429
+
430
+ /**
431
+ * Reads a packed repeated field of booleans.
432
+ * @param {boolean[]} [array] Array to read into; a new one is created if omitted
433
+ * @returns {boolean[]} Array read into
434
+ */
435
+ Reader.prototype.bools = function read_bools(array) {
436
+ if (array === undefined) array = [];
437
+ var end = this.uint32() + this.pos;
438
+ while (this.pos < end)
439
+ array.push(this.bool());
440
+ return array;
441
+ };
442
+
443
+ // The view allocation only pays off when amortized over enough reads
444
+ var VIEW_THRESHOLD_FLOAT = 8,
445
+ VIEW_THRESHOLD_INT = 128;
446
+
447
+ function getLazyView(reader, count, threshold) {
448
+ var view = reader.view;
449
+ if (view || count < threshold)
450
+ return view;
451
+ var buf = reader.buf;
452
+ return reader.view = new DataView(buf.buffer, buf.byteOffset, buf.byteLength);
453
+ }
454
+
455
+ /**
456
+ * Reads a packed repeated field of unsigned 32 bit fixed values.
457
+ * @param {number[]} [array] Array to read into; a new one is created if omitted
458
+ * @returns {number[]} Array read into
459
+ */
460
+ Reader.prototype.fixed32s = function read_fixed32s(array) {
461
+ if (array === undefined) array = [];
462
+ var len = this.uint32(), end = this.pos + len;
463
+ /* istanbul ignore if */
464
+ if (end > this.len) throw indexOutOfRange(this, len);
465
+ var count = len >>> 2, i = array.length, pos = this.pos;
466
+ array.length = i + count;
467
+ var dv = getLazyView(this, count, VIEW_THRESHOLD_INT);
468
+ if (dv)
469
+ for (var k = 0; k < count; ++k, pos += 4) array[i++] = dv.getUint32(pos, true);
470
+ else {
471
+ var buf = this.buf;
472
+ for (var j = 0; j < count; ++j, pos += 4) array[i++] = readFixed32_end(buf, pos + 4);
473
+ }
474
+ this.pos = pos;
475
+ if (pos !== end) throw indexOutOfRange(this, 4);
476
+ return array;
477
+ };
478
+
479
+ /**
480
+ * Reads a packed repeated field of signed 32 bit fixed values.
481
+ * @param {number[]} [array] Array to read into; a new one is created if omitted
482
+ * @returns {number[]} Array read into
483
+ */
484
+ Reader.prototype.sfixed32s = function read_sfixed32s(array) {
485
+ if (array === undefined) array = [];
486
+ var len = this.uint32(), end = this.pos + len;
487
+ /* istanbul ignore if */
488
+ if (end > this.len) throw indexOutOfRange(this, len);
489
+ var count = len >>> 2, i = array.length, pos = this.pos;
490
+ array.length = i + count;
491
+ var dv = getLazyView(this, count, VIEW_THRESHOLD_INT);
492
+ if (dv)
493
+ for (var k = 0; k < count; ++k, pos += 4) array[i++] = dv.getInt32(pos, true);
494
+ else {
495
+ var buf = this.buf;
496
+ for (var j = 0; j < count; ++j, pos += 4) array[i++] = readFixed32_end(buf, pos + 4) | 0;
497
+ }
498
+ this.pos = pos;
499
+ if (pos !== end) throw indexOutOfRange(this, 4);
500
+ return array;
501
+ };
502
+
503
+ /**
504
+ * Reads a packed repeated field of floats (32 bit).
505
+ * @param {number[]} [array] Array to read into; a new one is created if omitted
506
+ * @returns {number[]} Array read into
507
+ */
508
+ Reader.prototype.floats = function read_floats(array) {
509
+ if (array === undefined) array = [];
510
+ var len = this.uint32(), end = this.pos + len;
511
+ /* istanbul ignore if */
512
+ if (end > this.len) throw indexOutOfRange(this, len);
513
+ var count = len >>> 2, i = array.length, pos = this.pos;
514
+ array.length = i + count;
515
+ var dv = getLazyView(this, count, VIEW_THRESHOLD_FLOAT);
516
+ if (dv)
517
+ for (var k = 0; k < count; ++k, pos += 4) array[i++] = dv.getFloat32(pos, true);
518
+ else {
519
+ var buf = this.buf;
520
+ for (var j = 0; j < count; ++j, pos += 4) array[i++] = util.float.readFloatLE(buf, pos);
521
+ }
522
+ this.pos = pos;
523
+ if (pos !== end) throw indexOutOfRange(this, 4);
524
+ return array;
525
+ };
526
+
527
+ /**
528
+ * Reads a packed repeated field of doubles (64 bit float).
529
+ * @param {number[]} [array] Array to read into; a new one is created if omitted
530
+ * @returns {number[]} Array read into
531
+ */
532
+ Reader.prototype.doubles = function read_doubles(array) {
533
+ if (array === undefined) array = [];
534
+ var len = this.uint32(), end = this.pos + len;
535
+ /* istanbul ignore if */
536
+ if (end > this.len) throw indexOutOfRange(this, len);
537
+ var count = len >>> 3, i = array.length, pos = this.pos;
538
+ array.length = i + count;
539
+ var dv = getLazyView(this, count, VIEW_THRESHOLD_FLOAT);
540
+ if (dv)
541
+ for (var k = 0; k < count; ++k, pos += 8) array[i++] = dv.getFloat64(pos, true);
542
+ else {
543
+ var buf = this.buf;
544
+ for (var j = 0; j < count; ++j, pos += 8) array[i++] = util.float.readDoubleLE(buf, pos);
545
+ }
546
+ this.pos = pos;
547
+ if (pos !== end) throw indexOutOfRange(this, 8);
548
+ return array;
549
+ };
550
+
551
+ /**
552
+ * Reads a packed repeated field of unsigned 64 bit varints.
553
+ * @param {Array.<Long|number>} [array] Array to read into; a new one is created if omitted
554
+ * @returns {Array.<Long|number>} Array read into
555
+ */
556
+ Reader.prototype.uint64s = function read_uint64s(array) {
557
+ if (array === undefined) array = [];
558
+ var end = this.uint32() + this.pos;
559
+ while (this.pos < end)
560
+ array.push(this.uint64());
561
+ return array;
562
+ };
563
+
564
+ /**
565
+ * Reads a packed repeated field of signed 64 bit varints.
566
+ * @param {Array.<Long|number>} [array] Array to read into; a new one is created if omitted
567
+ * @returns {Array.<Long|number>} Array read into
568
+ */
569
+ Reader.prototype.int64s = function read_int64s(array) {
570
+ if (array === undefined) array = [];
571
+ var end = this.uint32() + this.pos;
572
+ while (this.pos < end)
573
+ array.push(this.int64());
574
+ return array;
575
+ };
576
+
577
+ /**
578
+ * Reads a packed repeated field of zig-zag encoded signed 64 bit varints.
579
+ * @param {Array.<Long|number>} [array] Array to read into; a new one is created if omitted
580
+ * @returns {Array.<Long|number>} Array read into
581
+ */
582
+ Reader.prototype.sint64s = function read_sint64s(array) {
583
+ if (array === undefined) array = [];
584
+ var end = this.uint32() + this.pos;
585
+ while (this.pos < end)
586
+ array.push(this.sint64());
587
+ return array;
588
+ };
589
+
590
+ /**
591
+ * Reads a packed repeated field of unsigned 64 bit fixed values.
592
+ * @param {Array.<Long|number>} [array] Array to read into; a new one is created if omitted
593
+ * @returns {Array.<Long|number>} Array read into
594
+ */
595
+ Reader.prototype.fixed64s = function read_fixed64s(array) {
596
+ if (array === undefined) array = [];
597
+ var len = this.uint32(), end = this.pos + len, i = array.length;
598
+ /* istanbul ignore if */
599
+ if (end > this.len) throw indexOutOfRange(this, len);
600
+ var count = len >>> 3;
601
+ array.length = i + count; // 8 bytes per value, count is known
602
+ for (var j = 0; j < count; ++j)
603
+ array[i++] = this.fixed64();
604
+ if (this.pos !== end) throw indexOutOfRange(this, 8);
605
+ return array;
606
+ };
607
+
608
+ /**
609
+ * Reads a packed repeated field of signed 64 bit fixed values.
610
+ * @param {Array.<Long|number>} [array] Array to read into; a new one is created if omitted
611
+ * @returns {Array.<Long|number>} Array read into
612
+ */
613
+ Reader.prototype.sfixed64s = function read_sfixed64s(array) {
614
+ if (array === undefined) array = [];
615
+ var len = this.uint32(), end = this.pos + len, i = array.length;
616
+ /* istanbul ignore if */
617
+ if (end > this.len) throw indexOutOfRange(this, len);
618
+ var count = len >>> 3;
619
+ array.length = i + count; // 8 bytes per value, count is known
620
+ for (var j = 0; j < count; ++j)
621
+ array[i++] = this.sfixed64();
622
+ if (this.pos !== end) throw indexOutOfRange(this, 8);
623
+ return array;
624
+ };
625
+
396
626
  /**
397
627
  * Reads a sequence of bytes preceeded by its length as a varint.
398
628
  * @returns {Uint8Array} Value read
@@ -28,7 +28,7 @@ function BufferReader(buffer) {
28
28
  * Read buffer.
29
29
  * @name BufferReader#buf
30
30
  * @type {Buffer}
31
- */
31
+ */
32
32
  }
33
33
 
34
34
  BufferReader._configure = function () {
@@ -46,8 +46,6 @@ BufferReader._configure = function () {
46
46
  * @returns {Buffer} Raw bytes
47
47
  */
48
48
  BufferReader.prototype.raw = function read_raw_buffer(start, end) {
49
- if (start === end)
50
- return util.Buffer.alloc(0);
51
49
  return this._slice.call(this.buf, start, end);
52
50
  };
53
51
 
package/src/type.js CHANGED
@@ -494,6 +494,14 @@ Type.prototype.setup = function setup() {
494
494
  // Sets up everything at once so that the prototype chain does not have to be re-evaluated
495
495
  // multiple times (V8, soft-deopt prototype-check).
496
496
 
497
+ // Resolve feature defaults incl. field presence before generating codecs
498
+ var root = this.root;
499
+ if (root && root._needsRecursiveFeatureResolution) {
500
+ var edition = root._edition || this._edition;
501
+ if (edition)
502
+ root._resolveFeaturesRecursive(edition);
503
+ }
504
+
497
505
  var fullName = this.fullName,
498
506
  types = [];
499
507
  for (var i = 0; i < /* initializes */ this.fieldsArray.length; ++i)
@@ -557,7 +565,7 @@ Type.prototype.encode = function encode_setup(message, writer) { // eslint-disab
557
565
  * @returns {Writer} writer
558
566
  */
559
567
  Type.prototype.encodeDelimited = function encodeDelimited(message, writer) {
560
- return this.encode(message, writer && writer.len ? writer.fork() : writer).ldelim();
568
+ return this.encode(message, (writer || Writer.create()).fork()).ldelim();
561
569
  };
562
570
 
563
571
  /**
@@ -1,7 +1,7 @@
1
1
  "use strict";
2
2
  module.exports = LongBits;
3
3
 
4
- var util = require("../util/minimal");
4
+ var Long;
5
5
 
6
6
  /**
7
7
  * Constructs new long bits.
@@ -80,10 +80,10 @@ LongBits.fromNumber = function fromNumber(value) {
80
80
  LongBits.from = function from(value) {
81
81
  if (typeof value === "number")
82
82
  return LongBits.fromNumber(value);
83
- if (util.isString(value)) {
83
+ if (typeof value === "string" || value instanceof String) {
84
84
  /* istanbul ignore else */
85
- if (util.Long)
86
- value = util.Long.fromString(value);
85
+ if (Long)
86
+ value = Long.fromString(value);
87
87
  else
88
88
  return LongBits.fromNumber(parseInt(value, 10));
89
89
  }
@@ -112,8 +112,8 @@ LongBits.prototype.toNumber = function toNumber(unsigned) {
112
112
  * @returns {Long} Long
113
113
  */
114
114
  LongBits.prototype.toLong = function toLong(unsigned) {
115
- return util.Long
116
- ? new util.Long(this.lo | 0, this.hi | 0, Boolean(unsigned))
115
+ return Long
116
+ ? new Long(this.lo | 0, this.hi | 0, Boolean(unsigned))
117
117
  /* istanbul ignore next */
118
118
  : { low: this.lo | 0, high: this.hi | 0, unsigned: Boolean(unsigned) };
119
119
  };
@@ -198,3 +198,7 @@ LongBits.prototype.length = function length() {
198
198
  : part1 < 2097152 ? 7 : 8
199
199
  : part2 < 128 ? 9 : 10;
200
200
  };
201
+
202
+ LongBits._configure = function(Long_) {
203
+ Long = Long_;
204
+ };