protobufjs 8.6.5 → 8.7.0

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/dist/protobuf.js CHANGED
@@ -1,6 +1,6 @@
1
1
  /*!
2
- * protobuf.js v8.6.5 (c) 2016, daniel wirtz
3
- * compiled tue, 23 jun 2026 14:36:35 utc
2
+ * protobuf.js v8.7.0 (c) 2016, daniel wirtz
3
+ * compiled mon, 06 jul 2026 13:50:00 utc
4
4
  * licensed under the bsd-3-clause license
5
5
  * see: https://github.com/dcodeio/protobuf.js for details
6
6
  */
@@ -938,13 +938,9 @@ function decoder(mtype) {
938
938
  if (types.packed[type] !== undefined) {
939
939
  gen
940
940
  ("if(u===2){");
941
- if (!closed) gen
942
- ("if(!(%s&&%s.length))", ref, ref)
943
- ("%s=[]", ref);
944
- gen
945
- ("var c2=r.uint32()+r.pos");
946
941
  if (closed) {
947
942
  gen
943
+ ("var c2=r.uint32()+r.pos")
948
944
  ("while(r.pos<c2){")
949
945
  ("s=r.pos")
950
946
  ("v=r.%s()", type)
@@ -956,8 +952,9 @@ function decoder(mtype) {
956
952
  genPreserveUnknown(gen, "util.rawField(" + field.id + ",0,r.raw(s,r.pos))")
957
953
  ("}");
958
954
  } else gen
959
- ("while(r.pos<c2)")
960
- ("%s.push(r.%s())", ref, type);
955
+ ("if(!(%s&&%s.length))", ref, ref)
956
+ ("%s=[]", ref)
957
+ ("r.%ss(%s)", type, ref);
961
958
  gen
962
959
  ("continue")
963
960
  ("}");
@@ -1153,10 +1150,7 @@ function encoder(mtype) {
1153
1150
  // Packed repeated
1154
1151
  if (field.packed && types.packed[type] !== undefined) { gen
1155
1152
 
1156
- ("w.uint32(%i).fork()", (field.id << 3 | 2) >>> 0)
1157
- ("for(var i=0;i<%s.length;++i)", ref)
1158
- ("w.%s(%s[i])", type, ref)
1159
- ("w.ldelim()");
1153
+ ("w.uint32(%i).%ss(%s)", (field.id << 3 | 2) >>> 0, type, ref);
1160
1154
 
1161
1155
  // Non-packed
1162
1156
  } else { gen
@@ -2089,7 +2083,6 @@ exports.configure = configure;
2089
2083
  * @returns {undefined}
2090
2084
  */
2091
2085
  function configure() {
2092
- exports.util._configure();
2093
2086
  exports.Writer._configure(exports.BufferWriter);
2094
2087
  exports.Reader._configure(exports.BufferReader);
2095
2088
  }
@@ -4009,6 +4002,9 @@ function parse(source, root, options) {
4009
4002
  }
4010
4003
 
4011
4004
  function parseId(token, acceptNegative, max) {
4005
+ if (token === null) {
4006
+ throw illegal(token, "end of input");
4007
+ }
4012
4008
  switch (token) {
4013
4009
  case "max": case "MAX": case "Max":
4014
4010
  return max || maxFieldId;
@@ -4041,7 +4037,7 @@ function parse(source, root, options) {
4041
4037
  pkg = next();
4042
4038
 
4043
4039
  /* istanbul ignore if */
4044
- if (!typeRefRe.test(pkg))
4040
+ if (pkg === null || !typeRefRe.test(pkg))
4045
4041
  throw illegal(pkg, "name");
4046
4042
 
4047
4043
  ptr = ptr.define(pkg);
@@ -4178,7 +4174,7 @@ function parse(source, root, options) {
4178
4174
  throw Error("max depth exceeded");
4179
4175
 
4180
4176
  /* istanbul ignore if */
4181
- if (!nameRe.test(token = next()))
4177
+ if ((token = next()) === null || !nameRe.test(token))
4182
4178
  throw illegal(token, "type name");
4183
4179
 
4184
4180
  var type = new Type(token);
@@ -4245,6 +4241,9 @@ function parse(source, root, options) {
4245
4241
 
4246
4242
  function parseField(parent, rule, extend, depth) {
4247
4243
  var type = next();
4244
+ if (type === null) {
4245
+ throw illegal(type, "end of input");
4246
+ }
4248
4247
  if (type === "group") {
4249
4248
  parseGroup(parent, rule, extend, depth);
4250
4249
  return;
@@ -4256,8 +4255,12 @@ function parse(source, root, options) {
4256
4255
  // package .subpackage field tokens: "package" ".subpackage" [TYPE NAME ENDS HERE] "field"
4257
4256
  // Keep reading tokens until we get a type name with no period at the end,
4258
4257
  // and the next token does not start with a period.
4259
- while (type.endsWith(".") || peek().startsWith(".")) {
4260
- type += next();
4258
+ while (type.endsWith(".") || (peek() || "").startsWith(".")) {
4259
+ var part = next();
4260
+ if (part === null) {
4261
+ throw illegal(part, "end of input");
4262
+ }
4263
+ type += part;
4261
4264
  }
4262
4265
 
4263
4266
  /* istanbul ignore if */
@@ -4265,6 +4268,9 @@ function parse(source, root, options) {
4265
4268
  throw illegal(type, "type");
4266
4269
 
4267
4270
  var name = next();
4271
+ if (name === null) {
4272
+ throw illegal(name, "end of input");
4273
+ }
4268
4274
 
4269
4275
  /* istanbul ignore if */
4270
4276
 
@@ -4317,7 +4323,7 @@ function parse(source, root, options) {
4317
4323
  var name = next();
4318
4324
 
4319
4325
  /* istanbul ignore if */
4320
- if (!nameRe.test(name))
4326
+ if (name === null || !nameRe.test(name))
4321
4327
  throw illegal(name, "name");
4322
4328
 
4323
4329
  var fieldName = util.lcFirst(name);
@@ -4415,7 +4421,7 @@ function parse(source, root, options) {
4415
4421
  var name = next();
4416
4422
 
4417
4423
  /* istanbul ignore if */
4418
- if (!nameRe.test(name))
4424
+ if (name === null || !nameRe.test(name))
4419
4425
  throw illegal(name, "name");
4420
4426
 
4421
4427
  skip("=");
@@ -4442,7 +4448,7 @@ function parse(source, root, options) {
4442
4448
  function parseOneOf(parent, token, depth) {
4443
4449
 
4444
4450
  /* istanbul ignore if */
4445
- if (!nameRe.test(token = next()))
4451
+ if ((token = next()) === null || !nameRe.test(token))
4446
4452
  throw illegal(token, "name");
4447
4453
 
4448
4454
  var oneof = new OneOf(applyCase(token));
@@ -4461,7 +4467,7 @@ function parse(source, root, options) {
4461
4467
  function parseEnum(parent, token) {
4462
4468
 
4463
4469
  /* istanbul ignore if */
4464
- if (!nameRe.test(token = next()))
4470
+ if ((token = next()) === null || !nameRe.test(token))
4465
4471
  throw illegal(token, "name");
4466
4472
 
4467
4473
  var enm = new Enum(token);
@@ -4534,6 +4540,9 @@ function parse(source, root, options) {
4534
4540
  }
4535
4541
 
4536
4542
  while (token !== "=") {
4543
+ if (token === null) {
4544
+ throw illegal(token, "end of input");
4545
+ }
4537
4546
  if (token === "(") {
4538
4547
  var parensValue = next();
4539
4548
  skip(")");
@@ -4640,15 +4649,12 @@ function parse(source, root, options) {
4640
4649
  // lift json_name onto Field
4641
4650
  if (name === "json_name" && parent instanceof Field) {
4642
4651
  parent.jsonName = value;
4643
- return;
4644
4652
  }
4645
4653
  if (parent.setOption)
4646
4654
  parent.setOption(name, value);
4647
4655
  }
4648
4656
 
4649
4657
  function setParsedOption(parent, name, value, propName) {
4650
- if (name === "json_name" && parent instanceof Field)
4651
- return; // lifted onto Field#jsonName above
4652
4658
  if (parent.setParsedOption)
4653
4659
  parent.setParsedOption(name, value, propName);
4654
4660
  }
@@ -4670,7 +4676,7 @@ function parse(source, root, options) {
4670
4676
  throw Error("max depth exceeded");
4671
4677
 
4672
4678
  /* istanbul ignore if */
4673
- if (!nameRe.test(token = next()))
4679
+ if ((token = next()) === null || !nameRe.test(token))
4674
4680
  throw illegal(token, "service name");
4675
4681
 
4676
4682
  var service = new Service(token);
@@ -4748,7 +4754,7 @@ function parse(source, root, options) {
4748
4754
  function parseExtension(parent, token, depth) {
4749
4755
 
4750
4756
  /* istanbul ignore if */
4751
- if (!typeRefRe.test(token = next()))
4757
+ if ((token = next()) === null || !typeRefRe.test(token))
4752
4758
  throw illegal(token, "reference");
4753
4759
 
4754
4760
  var reference = token;
@@ -4876,7 +4882,7 @@ function indexOutOfRange(reader, writeLength) {
4876
4882
 
4877
4883
  /**
4878
4884
  * Constructs a new reader instance using the specified buffer.
4879
- * @classdesc Wire format reader using `Uint8Array` if available, otherwise `Array`.
4885
+ * @classdesc Wire format reader using `Uint8Array`.
4880
4886
  * @constructor
4881
4887
  * @param {Uint8Array} buffer Buffer to read from
4882
4888
  */
@@ -4900,6 +4906,12 @@ function Reader(buffer) {
4900
4906
  */
4901
4907
  this.len = buffer.length;
4902
4908
 
4909
+ /**
4910
+ * Cached DataView for packed reads.
4911
+ * @type {DataView|null}
4912
+ */
4913
+ this.view = null;
4914
+
4903
4915
  /**
4904
4916
  * Whether to discard unknown fields while decoding.
4905
4917
  * @type {boolean}
@@ -4907,18 +4919,14 @@ function Reader(buffer) {
4907
4919
  this.discardUnknown = Reader.discardUnknown;
4908
4920
  }
4909
4921
 
4910
- var create_array = typeof Uint8Array !== "undefined"
4911
- ? function create_typed_array(buffer) {
4912
- if (buffer instanceof Uint8Array || Array.isArray(buffer))
4913
- return new Reader(buffer);
4914
- throw Error("illegal buffer");
4915
- }
4916
- /* istanbul ignore next */
4917
- : function create_array(buffer) {
4918
- if (Array.isArray(buffer))
4919
- return new Reader(buffer);
4920
- throw Error("illegal buffer");
4921
- };
4922
+ function create_array(buffer) {
4923
+ // TODO: Remove plain array reader support in the next major release.
4924
+ if (Array.isArray(buffer))
4925
+ buffer = new Uint8Array(buffer);
4926
+ if (buffer instanceof Uint8Array)
4927
+ return new Reader(buffer);
4928
+ throw Error("illegal buffer");
4929
+ }
4922
4930
 
4923
4931
  var create = function create() {
4924
4932
  return util.Buffer
@@ -4943,8 +4951,6 @@ var create = function create() {
4943
4951
  */
4944
4952
  Reader.create = create();
4945
4953
 
4946
- Reader.prototype._slice = util.Array.prototype.subarray || /* istanbul ignore next */ util.Array.prototype.slice;
4947
-
4948
4954
  /**
4949
4955
  * Returns raw bytes from the backing buffer without advancing the reader.
4950
4956
  * @param {number} start Start offset
@@ -4952,12 +4958,7 @@ Reader.prototype._slice = util.Array.prototype.subarray || /* istanbul ignore ne
4952
4958
  * @returns {Uint8Array} Raw bytes
4953
4959
  */
4954
4960
  Reader.prototype.raw = function read_raw(start, end) {
4955
- if (Array.isArray(this.buf)) // plain array
4956
- return this.buf.slice(start, end);
4957
-
4958
- if (start === end) // fix for IE 10/Win8 and others' subarray returning array of size 1
4959
- return new this.buf.constructor(0);
4960
- return this._slice.call(this.buf, start, end);
4961
+ return this.buf.subarray(start, end);
4961
4962
  };
4962
4963
 
4963
4964
  /**
@@ -5254,6 +5255,241 @@ Reader.prototype.double = function read_double() {
5254
5255
  return value;
5255
5256
  };
5256
5257
 
5258
+ /**
5259
+ * Reads a packed repeated field of unsigned 32 bit varints.
5260
+ * @param {number[]} [array] Array to read into; a new one is created if omitted
5261
+ * @returns {number[]} Array read into
5262
+ */
5263
+ Reader.prototype.uint32s = function read_uint32s(array) {
5264
+ if (array === undefined) array = [];
5265
+ var end = this.uint32() + this.pos;
5266
+ while (this.pos < end)
5267
+ array.push(this.uint32());
5268
+ return array;
5269
+ };
5270
+
5271
+ /**
5272
+ * Reads a packed repeated field of signed 32 bit varints.
5273
+ * @param {number[]} [array] Array to read into; a new one is created if omitted
5274
+ * @returns {number[]} Array read into
5275
+ */
5276
+ Reader.prototype.int32s = function read_int32s(array) {
5277
+ if (array === undefined) array = [];
5278
+ var end = this.uint32() + this.pos;
5279
+ while (this.pos < end)
5280
+ array.push(this.int32());
5281
+ return array;
5282
+ };
5283
+
5284
+ /**
5285
+ * Reads a packed repeated field of zig-zag encoded signed 32 bit varints.
5286
+ * @param {number[]} [array] Array to read into; a new one is created if omitted
5287
+ * @returns {number[]} Array read into
5288
+ */
5289
+ Reader.prototype.sint32s = function read_sint32s(array) {
5290
+ if (array === undefined) array = [];
5291
+ var end = this.uint32() + this.pos;
5292
+ while (this.pos < end)
5293
+ array.push(this.sint32());
5294
+ return array;
5295
+ };
5296
+
5297
+ /**
5298
+ * Reads a packed repeated field of booleans.
5299
+ * @param {boolean[]} [array] Array to read into; a new one is created if omitted
5300
+ * @returns {boolean[]} Array read into
5301
+ */
5302
+ Reader.prototype.bools = function read_bools(array) {
5303
+ if (array === undefined) array = [];
5304
+ var end = this.uint32() + this.pos;
5305
+ while (this.pos < end)
5306
+ array.push(this.bool());
5307
+ return array;
5308
+ };
5309
+
5310
+ // The view allocation only pays off when amortized over enough reads
5311
+ var VIEW_THRESHOLD_FLOAT = 8,
5312
+ VIEW_THRESHOLD_INT = 128;
5313
+
5314
+ function getLazyView(reader, count, threshold) {
5315
+ var view = reader.view;
5316
+ if (view || count < threshold)
5317
+ return view;
5318
+ var buf = reader.buf;
5319
+ return reader.view = new DataView(buf.buffer, buf.byteOffset, buf.byteLength);
5320
+ }
5321
+
5322
+ /**
5323
+ * Reads a packed repeated field of unsigned 32 bit fixed values.
5324
+ * @param {number[]} [array] Array to read into; a new one is created if omitted
5325
+ * @returns {number[]} Array read into
5326
+ */
5327
+ Reader.prototype.fixed32s = function read_fixed32s(array) {
5328
+ if (array === undefined) array = [];
5329
+ var len = this.uint32(), end = this.pos + len;
5330
+ /* istanbul ignore if */
5331
+ if (end > this.len) throw indexOutOfRange(this, len);
5332
+ var count = len >>> 2, i = array.length, pos = this.pos;
5333
+ array.length = i + count;
5334
+ var dv = getLazyView(this, count, VIEW_THRESHOLD_INT);
5335
+ if (dv)
5336
+ for (var k = 0; k < count; ++k, pos += 4) array[i++] = dv.getUint32(pos, true);
5337
+ else {
5338
+ var buf = this.buf;
5339
+ for (var j = 0; j < count; ++j, pos += 4) array[i++] = readFixed32_end(buf, pos + 4);
5340
+ }
5341
+ this.pos = pos;
5342
+ if (pos !== end) throw indexOutOfRange(this, 4);
5343
+ return array;
5344
+ };
5345
+
5346
+ /**
5347
+ * Reads a packed repeated field of signed 32 bit fixed values.
5348
+ * @param {number[]} [array] Array to read into; a new one is created if omitted
5349
+ * @returns {number[]} Array read into
5350
+ */
5351
+ Reader.prototype.sfixed32s = function read_sfixed32s(array) {
5352
+ if (array === undefined) array = [];
5353
+ var len = this.uint32(), end = this.pos + len;
5354
+ /* istanbul ignore if */
5355
+ if (end > this.len) throw indexOutOfRange(this, len);
5356
+ var count = len >>> 2, i = array.length, pos = this.pos;
5357
+ array.length = i + count;
5358
+ var dv = getLazyView(this, count, VIEW_THRESHOLD_INT);
5359
+ if (dv)
5360
+ for (var k = 0; k < count; ++k, pos += 4) array[i++] = dv.getInt32(pos, true);
5361
+ else {
5362
+ var buf = this.buf;
5363
+ for (var j = 0; j < count; ++j, pos += 4) array[i++] = readFixed32_end(buf, pos + 4) | 0;
5364
+ }
5365
+ this.pos = pos;
5366
+ if (pos !== end) throw indexOutOfRange(this, 4);
5367
+ return array;
5368
+ };
5369
+
5370
+ /**
5371
+ * Reads a packed repeated field of floats (32 bit).
5372
+ * @param {number[]} [array] Array to read into; a new one is created if omitted
5373
+ * @returns {number[]} Array read into
5374
+ */
5375
+ Reader.prototype.floats = function read_floats(array) {
5376
+ if (array === undefined) array = [];
5377
+ var len = this.uint32(), end = this.pos + len;
5378
+ /* istanbul ignore if */
5379
+ if (end > this.len) throw indexOutOfRange(this, len);
5380
+ var count = len >>> 2, i = array.length, pos = this.pos;
5381
+ array.length = i + count;
5382
+ var dv = getLazyView(this, count, VIEW_THRESHOLD_FLOAT);
5383
+ if (dv)
5384
+ for (var k = 0; k < count; ++k, pos += 4) array[i++] = dv.getFloat32(pos, true);
5385
+ else {
5386
+ var buf = this.buf;
5387
+ for (var j = 0; j < count; ++j, pos += 4) array[i++] = util.float.readFloatLE(buf, pos);
5388
+ }
5389
+ this.pos = pos;
5390
+ if (pos !== end) throw indexOutOfRange(this, 4);
5391
+ return array;
5392
+ };
5393
+
5394
+ /**
5395
+ * Reads a packed repeated field of doubles (64 bit float).
5396
+ * @param {number[]} [array] Array to read into; a new one is created if omitted
5397
+ * @returns {number[]} Array read into
5398
+ */
5399
+ Reader.prototype.doubles = function read_doubles(array) {
5400
+ if (array === undefined) array = [];
5401
+ var len = this.uint32(), end = this.pos + len;
5402
+ /* istanbul ignore if */
5403
+ if (end > this.len) throw indexOutOfRange(this, len);
5404
+ var count = len >>> 3, i = array.length, pos = this.pos;
5405
+ array.length = i + count;
5406
+ var dv = getLazyView(this, count, VIEW_THRESHOLD_FLOAT);
5407
+ if (dv)
5408
+ for (var k = 0; k < count; ++k, pos += 8) array[i++] = dv.getFloat64(pos, true);
5409
+ else {
5410
+ var buf = this.buf;
5411
+ for (var j = 0; j < count; ++j, pos += 8) array[i++] = util.float.readDoubleLE(buf, pos);
5412
+ }
5413
+ this.pos = pos;
5414
+ if (pos !== end) throw indexOutOfRange(this, 8);
5415
+ return array;
5416
+ };
5417
+
5418
+ /**
5419
+ * Reads a packed repeated field of unsigned 64 bit varints.
5420
+ * @param {Array.<Long|number>} [array] Array to read into; a new one is created if omitted
5421
+ * @returns {Array.<Long|number>} Array read into
5422
+ */
5423
+ Reader.prototype.uint64s = function read_uint64s(array) {
5424
+ if (array === undefined) array = [];
5425
+ var end = this.uint32() + this.pos;
5426
+ while (this.pos < end)
5427
+ array.push(this.uint64());
5428
+ return array;
5429
+ };
5430
+
5431
+ /**
5432
+ * Reads a packed repeated field of signed 64 bit varints.
5433
+ * @param {Array.<Long|number>} [array] Array to read into; a new one is created if omitted
5434
+ * @returns {Array.<Long|number>} Array read into
5435
+ */
5436
+ Reader.prototype.int64s = function read_int64s(array) {
5437
+ if (array === undefined) array = [];
5438
+ var end = this.uint32() + this.pos;
5439
+ while (this.pos < end)
5440
+ array.push(this.int64());
5441
+ return array;
5442
+ };
5443
+
5444
+ /**
5445
+ * Reads a packed repeated field of zig-zag encoded signed 64 bit varints.
5446
+ * @param {Array.<Long|number>} [array] Array to read into; a new one is created if omitted
5447
+ * @returns {Array.<Long|number>} Array read into
5448
+ */
5449
+ Reader.prototype.sint64s = function read_sint64s(array) {
5450
+ if (array === undefined) array = [];
5451
+ var end = this.uint32() + this.pos;
5452
+ while (this.pos < end)
5453
+ array.push(this.sint64());
5454
+ return array;
5455
+ };
5456
+
5457
+ /**
5458
+ * Reads a packed repeated field of unsigned 64 bit fixed values.
5459
+ * @param {Array.<Long|number>} [array] Array to read into; a new one is created if omitted
5460
+ * @returns {Array.<Long|number>} Array read into
5461
+ */
5462
+ Reader.prototype.fixed64s = function read_fixed64s(array) {
5463
+ if (array === undefined) array = [];
5464
+ var len = this.uint32(), end = this.pos + len, i = array.length;
5465
+ /* istanbul ignore if */
5466
+ if (end > this.len) throw indexOutOfRange(this, len);
5467
+ var count = len >>> 3;
5468
+ array.length = i + count; // 8 bytes per value, count is known
5469
+ for (var j = 0; j < count; ++j)
5470
+ array[i++] = this.fixed64();
5471
+ if (this.pos !== end) throw indexOutOfRange(this, 8);
5472
+ return array;
5473
+ };
5474
+
5475
+ /**
5476
+ * Reads a packed repeated field of signed 64 bit fixed values.
5477
+ * @param {Array.<Long|number>} [array] Array to read into; a new one is created if omitted
5478
+ * @returns {Array.<Long|number>} Array read into
5479
+ */
5480
+ Reader.prototype.sfixed64s = function read_sfixed64s(array) {
5481
+ if (array === undefined) array = [];
5482
+ var len = this.uint32(), end = this.pos + len, i = array.length;
5483
+ /* istanbul ignore if */
5484
+ if (end > this.len) throw indexOutOfRange(this, len);
5485
+ var count = len >>> 3;
5486
+ array.length = i + count; // 8 bytes per value, count is known
5487
+ for (var j = 0; j < count; ++j)
5488
+ array[i++] = this.sfixed64();
5489
+ if (this.pos !== end) throw indexOutOfRange(this, 8);
5490
+ return array;
5491
+ };
5492
+
5257
5493
  /**
5258
5494
  * Reads a sequence of bytes preceeded by its length as a varint.
5259
5495
  * @returns {Uint8Array} Value read
@@ -5449,7 +5685,7 @@ function BufferReader(buffer) {
5449
5685
  * Read buffer.
5450
5686
  * @name BufferReader#buf
5451
5687
  * @type {Buffer}
5452
- */
5688
+ */
5453
5689
  }
5454
5690
 
5455
5691
  BufferReader._configure = function () {
@@ -5467,8 +5703,6 @@ BufferReader._configure = function () {
5467
5703
  * @returns {Buffer} Raw bytes
5468
5704
  */
5469
5705
  BufferReader.prototype.raw = function read_raw_buffer(start, end) {
5470
- if (start === end)
5471
- return util.Buffer.alloc(0);
5472
5706
  return this._slice.call(this.buf, start, end);
5473
5707
  };
5474
5708
 
@@ -7268,6 +7502,14 @@ Type.prototype.setup = function setup() {
7268
7502
  // Sets up everything at once so that the prototype chain does not have to be re-evaluated
7269
7503
  // multiple times (V8, soft-deopt prototype-check).
7270
7504
 
7505
+ // Resolve feature defaults incl. field presence before generating codecs
7506
+ var root = this.root;
7507
+ if (root && root._needsRecursiveFeatureResolution) {
7508
+ var edition = root._edition || this._edition;
7509
+ if (edition)
7510
+ root._resolveFeaturesRecursive(edition);
7511
+ }
7512
+
7271
7513
  var fullName = this.fullName,
7272
7514
  types = [];
7273
7515
  for (var i = 0; i < /* initializes */ this.fieldsArray.length; ++i)
@@ -7331,7 +7573,7 @@ Type.prototype.encode = function encode_setup(message, writer) { // eslint-disab
7331
7573
  * @returns {Writer} writer
7332
7574
  */
7333
7575
  Type.prototype.encodeDelimited = function encodeDelimited(message, writer) {
7334
- return this.encode(message, writer && writer.len ? writer.fork() : writer).ldelim();
7576
+ return this.encode(message, (writer || Writer.create()).fork()).ldelim();
7335
7577
  };
7336
7578
 
7337
7579
  /**
@@ -9121,36 +9363,29 @@ util.isSet = function isSet(obj, prop) {
9121
9363
  util.Buffer = (function() {
9122
9364
  try {
9123
9365
  var Buffer = util.global.Buffer;
9124
- // refuse to use non-node buffers if not explicitly assigned (perf reasons):
9125
- return Buffer.prototype.utf8Write ? Buffer : /* istanbul ignore next */ null;
9366
+ // refuse to use non-node buffers if not explicitly assigned (perf reasons)
9367
+ return Buffer.prototype.utf8Write || util.isNode ? Buffer : /* istanbul ignore next */ null;
9126
9368
  } catch (e) {
9127
9369
  /* istanbul ignore next */
9128
9370
  return null;
9129
9371
  }
9130
9372
  })();
9131
9373
 
9132
- // Internal alias of or polyfull for Buffer.from.
9133
- util._Buffer_from = null;
9134
-
9135
- // Internal alias of or polyfill for Buffer.allocUnsafe.
9136
- util._Buffer_allocUnsafe = null;
9137
-
9138
9374
  /**
9139
9375
  * Creates a new buffer of whatever type supported by the environment.
9140
9376
  * @param {number|number[]} [sizeOrArray=0] Buffer size or number array
9141
9377
  * @returns {Uint8Array|Buffer} Buffer
9142
9378
  */
9143
9379
  util.newBuffer = function newBuffer(sizeOrArray) {
9380
+ var Buffer = util.Buffer;
9144
9381
  /* istanbul ignore next */
9145
9382
  return typeof sizeOrArray === "number"
9146
- ? util.Buffer
9147
- ? util._Buffer_allocUnsafe(sizeOrArray)
9148
- : new util.Array(sizeOrArray)
9149
- : util.Buffer
9150
- ? util._Buffer_from(sizeOrArray)
9151
- : typeof Uint8Array === "undefined"
9152
- ? sizeOrArray
9153
- : new Uint8Array(sizeOrArray);
9383
+ ? Buffer
9384
+ ? Buffer.allocUnsafe(sizeOrArray)
9385
+ : new Uint8Array(sizeOrArray)
9386
+ : Buffer
9387
+ ? Buffer.from(sizeOrArray)
9388
+ : new Uint8Array(sizeOrArray);
9154
9389
  };
9155
9390
 
9156
9391
  /**
@@ -9176,10 +9411,11 @@ util.rawField = function rawField(id, wireType, data) {
9176
9411
  };
9177
9412
 
9178
9413
  /**
9179
- * Array implementation used in the browser. `Uint8Array` if supported, otherwise `Array`.
9414
+ * Array implementation used in the browser.
9180
9415
  * @type {Constructor<Uint8Array>}
9416
+ * @deprecated Use `Uint8Array` instead.
9181
9417
  */
9182
- util.Array = typeof Uint8Array !== "undefined" ? Uint8Array /* istanbul ignore next */ : Array;
9418
+ util.Array = Uint8Array;
9183
9419
 
9184
9420
  /**
9185
9421
  * Any compatible Long instance.
@@ -9500,28 +9736,6 @@ util.toJSONOptions = {
9500
9736
  json: true
9501
9737
  };
9502
9738
 
9503
- // Sets up buffer utility according to the environment (called in index-minimal)
9504
- util._configure = function() {
9505
- var Buffer = util.Buffer;
9506
- /* istanbul ignore if */
9507
- if (!Buffer) {
9508
- util._Buffer_from = util._Buffer_allocUnsafe = null;
9509
- return;
9510
- }
9511
- // because node 4.x buffers are incompatible & immutable
9512
- // see: https://github.com/dcodeIO/protobuf.js/pull/665
9513
- util._Buffer_from = Buffer.from !== Uint8Array.from && Buffer.from ||
9514
- /* istanbul ignore next */
9515
- function Buffer_from(value, encoding) {
9516
- return new Buffer(value, encoding);
9517
- };
9518
- util._Buffer_allocUnsafe = Buffer.allocUnsafe ||
9519
- /* istanbul ignore next */
9520
- function Buffer_allocUnsafe(size) {
9521
- return new Buffer(size);
9522
- };
9523
- };
9524
-
9525
9739
  },{"29":29,"30":30,"32":32,"34":34,"36":36,"40":40,"41":41,"long":"long"}],38:[function(require,module,exports){
9526
9740
  "use strict";
9527
9741
 
@@ -9687,19 +9901,21 @@ function pool(alloc, slice, size) {
9687
9901
  "use strict";
9688
9902
 
9689
9903
  /**
9690
- * A minimal UTF8 implementation for number arrays.
9904
+ * A minimal UTF8 implementation.
9691
9905
  * @memberof util
9692
9906
  * @namespace
9693
9907
  */
9694
9908
  var utf8 = exports,
9695
9909
  replacementChar = "\ufffd",
9910
+ looseDecoder = new TextDecoder("utf-8", { ignoreBOM: true }),
9696
9911
  strictDecoder;
9912
+ var TEXT_DECODER_MIN_LENGTH = 64;
9697
9913
 
9698
9914
  try {
9699
9915
  strictDecoder = new TextDecoder("utf-8", { fatal: true, ignoreBOM: true });
9700
9916
  } catch (err) {
9701
9917
  // "fatal" option is not supported on Node.js compiled without ICU
9702
- strictDecoder = new TextDecoder("utf-8", { ignoreBOM: true });
9918
+ strictDecoder = looseDecoder;
9703
9919
  }
9704
9920
 
9705
9921
  /**
@@ -9750,6 +9966,13 @@ function utf8_read_js(buffer, start, end, str) {
9750
9966
  return str;
9751
9967
  }
9752
9968
 
9969
+ function utf8_read_decoder(decoder, buffer, start, end) {
9970
+ var source = start === 0 && end === buffer.length
9971
+ ? buffer
9972
+ : buffer.subarray(start, end);
9973
+ return decoder.decode(source);
9974
+ }
9975
+
9753
9976
  /**
9754
9977
  * Reads UTF8 bytes as a string.
9755
9978
  * @param {Uint8Array} buffer Source buffer
@@ -9757,9 +9980,11 @@ function utf8_read_js(buffer, start, end, str) {
9757
9980
  * @param {number} end Source end
9758
9981
  * @returns {string} String read
9759
9982
  */
9760
- utf8.read = function utf8_read_ascii(buffer, start, end) {
9983
+ utf8.read = function utf8_read_loose(buffer, start, end) {
9761
9984
  if (end - start < 1)
9762
9985
  return "";
9986
+ if (end - start >= TEXT_DECODER_MIN_LENGTH)
9987
+ return utf8_read_decoder(looseDecoder, buffer, start, end);
9763
9988
 
9764
9989
  var str = "",
9765
9990
  i = start,
@@ -9789,17 +10014,6 @@ utf8.read = function utf8_read_ascii(buffer, start, end) {
9789
10014
  return str;
9790
10015
  };
9791
10016
 
9792
- function utf8_read_strict(buffer, start, end) {
9793
- var source = start === 0 && end === buffer.length
9794
- ? buffer
9795
- : buffer.subarray
9796
- ? buffer.subarray(start, end)
9797
- : buffer.slice(start, end);
9798
- if (Array.isArray(source))
9799
- source = Uint8Array.from(source);
9800
- return strictDecoder.decode(source);
9801
- }
9802
-
9803
10017
  /**
9804
10018
  * Reads UTF8 bytes as a string, rejecting invalid UTF8.
9805
10019
  * @param {Uint8Array} buffer Source buffer
@@ -9807,9 +10021,11 @@ function utf8_read_strict(buffer, start, end) {
9807
10021
  * @param {number} end Source end
9808
10022
  * @returns {string} String read
9809
10023
  */
9810
- utf8.readStrict = function utf8_read_strict_ascii(buffer, start, end) {
10024
+ utf8.readStrict = function utf8_read_strict(buffer, start, end) {
9811
10025
  if (end - start < 1)
9812
10026
  return "";
10027
+ if (end - start >= TEXT_DECODER_MIN_LENGTH)
10028
+ return utf8_read_decoder(strictDecoder, buffer, start, end);
9813
10029
 
9814
10030
  var str = "",
9815
10031
  i = start,
@@ -9825,14 +10041,14 @@ utf8.readStrict = function utf8_read_strict_ascii(buffer, start, end) {
9825
10041
  c7 = buffer[i + 6];
9826
10042
  c8 = buffer[i + 7];
9827
10043
  if ((c1 | c2 | c3 | c4 | c5 | c6 | c7 | c8) & 0x80)
9828
- return str + utf8_read_strict(buffer, i, end);
10044
+ return str + utf8_read_decoder(strictDecoder, buffer, i, end);
9829
10045
  str += String.fromCharCode(c1, c2, c3, c4, c5, c6, c7, c8);
9830
10046
  }
9831
10047
 
9832
10048
  for (; i < end; ++i) {
9833
10049
  c1 = buffer[i];
9834
10050
  if (c1 & 0x80)
9835
- return str + utf8_read_strict(buffer, i, end);
10051
+ return str + utf8_read_decoder(strictDecoder, buffer, i, end);
9836
10052
  str += String.fromCharCode(c1);
9837
10053
  }
9838
10054
 
@@ -10108,7 +10324,7 @@ wrappers[".google.protobuf.Any"] = {
10108
10324
  if (object && object["@type"]) {
10109
10325
  // Only use fully qualified type name after the last '/'
10110
10326
  var name = object["@type"].substring(object["@type"].lastIndexOf("/") + 1);
10111
- var type = this.lookup(name);
10327
+ var type = this.lookup(name, [ this.constructor ]);
10112
10328
  /* istanbul ignore else */
10113
10329
  if (type) {
10114
10330
  // type_url does not accept leading "."
@@ -10144,7 +10360,7 @@ wrappers[".google.protobuf.Any"] = {
10144
10360
  name = message.type_url.substring(message.type_url.lastIndexOf("/") + 1);
10145
10361
  // Separate the prefix used
10146
10362
  prefix = message.type_url.substring(0, message.type_url.lastIndexOf("/") + 1);
10147
- var type = this.lookup(name);
10363
+ var type = this.lookup(name, [ this.constructor ]);
10148
10364
  /* istanbul ignore else */
10149
10365
  if (type)
10150
10366
  message = type.decode(message.value, undefined, undefined, depth + 1);
@@ -10180,118 +10396,52 @@ var LongBits = util.LongBits,
10180
10396
  base64 = util.base64,
10181
10397
  utf8 = util.utf8;
10182
10398
 
10183
- /**
10184
- * Constructs a new writer operation instance.
10185
- * @classdesc Scheduled writer operation.
10186
- * @constructor
10187
- * @param {function(*, Uint8Array, number)} fn Function to call
10188
- * @param {number} len Value byte length
10189
- * @param {*} val Value to write
10190
- * @ignore
10191
- */
10192
- function Op(fn, len, val) {
10193
-
10194
- /**
10195
- * Function to call.
10196
- * @type {function(Uint8Array, number, *)}
10197
- */
10198
- this.fn = fn;
10199
-
10200
- /**
10201
- * Value byte length.
10202
- * @type {number}
10203
- */
10204
- this.len = len;
10205
-
10206
- /**
10207
- * Next operation.
10208
- * @type {Writer.Op|undefined}
10209
- */
10210
- this.next = undefined;
10211
-
10212
- /**
10213
- * Value to write.
10214
- * @type {*}
10215
- */
10216
- this.val = val; // type varies
10217
- }
10218
-
10219
- /* istanbul ignore next */
10220
- function noop() {} // eslint-disable-line no-empty-function
10221
-
10222
- /**
10223
- * Constructs a new writer state instance.
10224
- * @classdesc Copied writer state.
10225
- * @memberof Writer
10226
- * @constructor
10227
- * @param {Writer} writer Writer to copy state from
10228
- * @ignore
10229
- */
10230
- function State(writer) {
10231
-
10232
- /**
10233
- * Current head.
10234
- * @type {Writer.Op}
10235
- */
10236
- this.head = writer.head;
10237
-
10238
- /**
10239
- * Current tail.
10240
- * @type {Writer.Op}
10241
- */
10242
- this.tail = writer.tail;
10243
-
10244
- /**
10245
- * Current buffer length.
10246
- * @type {number}
10247
- */
10248
- this.len = writer.len;
10249
-
10250
- /**
10251
- * Next state.
10252
- * @type {State|null}
10253
- */
10254
- this.next = writer.states;
10255
- }
10256
-
10257
10399
  /**
10258
10400
  * Constructs a new writer instance.
10259
- * @classdesc Wire format writer using `Uint8Array` if available, otherwise `Array`.
10401
+ * @classdesc Wire format writer using `Uint8Array`.
10260
10402
  * @constructor
10261
10403
  */
10262
10404
  function Writer() {
10263
10405
 
10264
10406
  /**
10265
- * Current length.
10407
+ * Write cursor into {@link Writer#buf}.
10266
10408
  * @type {number}
10267
10409
  */
10268
- this.len = 0;
10410
+ this.pos = 0;
10269
10411
 
10270
10412
  /**
10271
- * Operations head.
10272
- * @type {Object}
10413
+ * Backing buffer.
10414
+ * @type {Uint8Array}
10273
10415
  */
10274
- this.head = new Op(noop, 0, 0);
10416
+ this.buf = this.constructor.alloc(64);
10275
10417
 
10276
10418
  /**
10277
- * Operations tail
10278
- * @type {Object}
10419
+ * Cached DataView over {@link Writer#buf}.
10420
+ * @type {DataView|null}
10279
10421
  */
10280
- this.tail = this.head;
10422
+ this.view = null;
10281
10423
 
10282
10424
  /**
10283
- * Linked forked states.
10284
- * @type {Object|null}
10425
+ * Stack of forked length-prefix positions.
10426
+ * @type {Array<number>|null}
10285
10427
  */
10286
10428
  this.states = null;
10287
-
10288
- // When a value is written, the writer calculates its byte length and puts it into a linked
10289
- // list of operations to perform when finish() is called. This both allows us to allocate
10290
- // buffers of the exact required size and reduces the amount of work we have to do compared
10291
- // to first calculating over objects and then encoding over objects. In our case, the encoding
10292
- // part is just a linked list walk calling operations with already prepared values.
10293
10429
  }
10294
10430
 
10431
+ /**
10432
+ * Current write position.
10433
+ * @name Writer#len
10434
+ * @type {number}
10435
+ * @deprecated Use {@link Writer#pos} instead.
10436
+ */
10437
+ Object.defineProperty(Writer.prototype, "len", {
10438
+ configurable: true,
10439
+ enumerable: true,
10440
+ get: function get_len() {
10441
+ return this.pos;
10442
+ }
10443
+ });
10444
+
10295
10445
  var create = function create() {
10296
10446
  return util.Buffer
10297
10447
  ? function create_buffer_setup() {
@@ -10318,32 +10468,45 @@ Writer.create = create();
10318
10468
  * @returns {Uint8Array} Buffer
10319
10469
  */
10320
10470
  Writer.alloc = function alloc(size) {
10321
- return new util.Array(size);
10471
+ return new Uint8Array(size);
10322
10472
  };
10323
10473
 
10324
10474
  // Use Uint8Array buffer pool in the browser, just like node does with buffers
10325
- /* istanbul ignore else */
10326
- if (util.Array !== Array)
10327
- Writer.alloc = util.pool(Writer.alloc, util.Array.prototype.subarray);
10475
+ Writer.alloc = util.pool(Writer.alloc, Uint8Array.prototype.subarray);
10328
10476
 
10329
10477
  /**
10330
- * Pushes a new operation to the queue.
10331
- * @param {function(Uint8Array, number, *)} fn Function to call
10332
- * @param {number} len Value byte length
10333
- * @param {number} val Value to write
10334
- * @returns {Writer} `this`
10478
+ * Calculates the number of bytes a value occupies as a varint.
10479
+ * @param {number} value Value to size (unsigned)
10480
+ * @returns {number} Byte length (1..5)
10481
+ * @ignore
10482
+ */
10483
+ function sizeVarint32(value) {
10484
+ return value < 128 ? 1
10485
+ : value < 16384 ? 2
10486
+ : value < 2097152 ? 3
10487
+ : value < 268435456 ? 4
10488
+ : 5;
10489
+ }
10490
+
10491
+ /**
10492
+ * Ensures that at least `n` more bytes fit into the backing buffer, doubling it if not.
10493
+ * @param {number} n Number of additional bytes required
10494
+ * @returns {undefined}
10335
10495
  * @private
10336
10496
  */
10337
- Writer.prototype._push = function push(fn, len, val) {
10338
- this.tail = this.tail.next = new Op(fn, len, val);
10339
- this.len += len;
10340
- return this;
10497
+ Writer.prototype._reserve = function _reserve(n) {
10498
+ var need = this.pos + n;
10499
+ if (need > this.buf.length) {
10500
+ var size = this.buf.length << 1;
10501
+ if (size < need)
10502
+ size = need;
10503
+ var buf = this.constructor.alloc(size);
10504
+ buf.set(this.buf.subarray(0, this.pos), 0);
10505
+ this.buf = buf;
10506
+ this.view = null; // invalidate
10507
+ }
10341
10508
  };
10342
10509
 
10343
- function writeByte(val, buf, pos) {
10344
- buf[pos] = val & 255;
10345
- }
10346
-
10347
10510
  function writeStringAscii(val, buf, pos) {
10348
10511
  for (var i = 0; i < val.length;)
10349
10512
  buf[pos++] = val.charCodeAt(i++);
@@ -10355,42 +10518,19 @@ function writeVarint32(val, buf, pos) {
10355
10518
  val >>>= 7;
10356
10519
  }
10357
10520
  buf[pos] = val;
10521
+ return pos + 1;
10358
10522
  }
10359
10523
 
10360
- /**
10361
- * Constructs a new varint writer operation instance.
10362
- * @classdesc Scheduled varint writer operation.
10363
- * @extends Op
10364
- * @constructor
10365
- * @param {number} len Value byte length
10366
- * @param {number} val Value to write
10367
- * @ignore
10368
- */
10369
- function VarintOp(len, val) {
10370
- this.len = len;
10371
- this.next = undefined;
10372
- this.val = val;
10373
- }
10374
-
10375
- VarintOp.prototype = Object.create(Op.prototype);
10376
- VarintOp.prototype.fn = writeVarint32;
10377
-
10378
10524
  /**
10379
10525
  * Writes an unsigned 32 bit value as a varint.
10380
10526
  * @param {number} value Value to write
10381
10527
  * @returns {Writer} `this`
10382
10528
  */
10383
10529
  Writer.prototype.uint32 = function write_uint32(value) {
10384
- // here, the call to this.push has been inlined and a varint specific Op subclass is used.
10385
- // uint32 is by far the most frequently used operation and benefits significantly from this.
10386
- this.len += (this.tail = this.tail.next = new VarintOp(
10387
- (value = value >>> 0)
10388
- < 128 ? 1
10389
- : value < 16384 ? 2
10390
- : value < 2097152 ? 3
10391
- : value < 268435456 ? 4
10392
- : 5,
10393
- value)).len;
10530
+ value = value >>> 0;
10531
+ this._reserve(5);
10532
+ var pos = this.pos;
10533
+ this.pos = writeVarint32(value, this.buf, pos);
10394
10534
  return this;
10395
10535
  };
10396
10536
 
@@ -10401,9 +10541,13 @@ Writer.prototype.uint32 = function write_uint32(value) {
10401
10541
  * @returns {Writer} `this`
10402
10542
  */
10403
10543
  Writer.prototype.int32 = function write_int32(value) {
10404
- return (value |= 0) < 0
10405
- ? this._push(writeVarint64, 10, LongBits.fromNumber(value)) // 10 bytes per spec
10406
- : this.uint32(value);
10544
+ if ((value |= 0) < 0) { // 10 bytes per spec
10545
+ this._reserve(10);
10546
+ writeVarint64(LongBits.fromNumber(value), this.buf, this.pos);
10547
+ this.pos += 10;
10548
+ return this;
10549
+ }
10550
+ return this.uint32(value);
10407
10551
  };
10408
10552
 
10409
10553
  /**
@@ -10427,7 +10571,8 @@ function writeVarint64(val, buf, pos) {
10427
10571
  buf[pos++] = lo & 127 | 128;
10428
10572
  lo = lo >>> 7;
10429
10573
  }
10430
- buf[pos++] = lo;
10574
+ buf[pos] = lo;
10575
+ return pos + 1;
10431
10576
  }
10432
10577
 
10433
10578
  /**
@@ -10438,7 +10583,10 @@ function writeVarint64(val, buf, pos) {
10438
10583
  */
10439
10584
  Writer.prototype.uint64 = function write_uint64(value) {
10440
10585
  var bits = LongBits.from(value);
10441
- return this._push(writeVarint64, bits.length(), bits);
10586
+ this._reserve(10);
10587
+ var pos = this.pos;
10588
+ this.pos = writeVarint64(bits, this.buf, pos);
10589
+ return this;
10442
10590
  };
10443
10591
 
10444
10592
  /**
@@ -10458,7 +10606,10 @@ Writer.prototype.int64 = Writer.prototype.uint64;
10458
10606
  */
10459
10607
  Writer.prototype.sint64 = function write_sint64(value) {
10460
10608
  var bits = LongBits.from(value).zzEncode();
10461
- return this._push(writeVarint64, bits.length(), bits);
10609
+ this._reserve(10);
10610
+ var pos = this.pos;
10611
+ this.pos = writeVarint64(bits, this.buf, pos);
10612
+ return this;
10462
10613
  };
10463
10614
 
10464
10615
  /**
@@ -10467,7 +10618,9 @@ Writer.prototype.sint64 = function write_sint64(value) {
10467
10618
  * @returns {Writer} `this`
10468
10619
  */
10469
10620
  Writer.prototype.bool = function write_bool(value) {
10470
- return this._push(writeByte, 1, value ? 1 : 0);
10621
+ this._reserve(1);
10622
+ this.buf[this.pos++] = value ? 1 : 0;
10623
+ return this;
10471
10624
  };
10472
10625
 
10473
10626
  function writeFixed32(val, buf, pos) {
@@ -10483,7 +10636,10 @@ function writeFixed32(val, buf, pos) {
10483
10636
  * @returns {Writer} `this`
10484
10637
  */
10485
10638
  Writer.prototype.fixed32 = function write_fixed32(value) {
10486
- return this._push(writeFixed32, 4, value >>> 0);
10639
+ this._reserve(4);
10640
+ writeFixed32(value >>> 0, this.buf, this.pos);
10641
+ this.pos += 4;
10642
+ return this;
10487
10643
  };
10488
10644
 
10489
10645
  /**
@@ -10502,7 +10658,11 @@ Writer.prototype.sfixed32 = Writer.prototype.fixed32;
10502
10658
  */
10503
10659
  Writer.prototype.fixed64 = function write_fixed64(value) {
10504
10660
  var bits = LongBits.from(value);
10505
- return this._push(writeFixed32, 4, bits.lo)._push(writeFixed32, 4, bits.hi);
10661
+ this._reserve(8);
10662
+ writeFixed32(bits.lo, this.buf, this.pos);
10663
+ writeFixed32(bits.hi, this.buf, this.pos + 4);
10664
+ this.pos += 8;
10665
+ return this;
10506
10666
  };
10507
10667
 
10508
10668
  /**
@@ -10521,7 +10681,10 @@ Writer.prototype.sfixed64 = Writer.prototype.fixed64;
10521
10681
  * @returns {Writer} `this`
10522
10682
  */
10523
10683
  Writer.prototype.float = function write_float(value) {
10524
- return this._push(util.float.writeFloatLE, 4, value);
10684
+ this._reserve(4);
10685
+ util.float.writeFloatLE(value, this.buf, this.pos);
10686
+ this.pos += 4;
10687
+ return this;
10525
10688
  };
10526
10689
 
10527
10690
  /**
@@ -10531,19 +10694,12 @@ Writer.prototype.float = function write_float(value) {
10531
10694
  * @returns {Writer} `this`
10532
10695
  */
10533
10696
  Writer.prototype.double = function write_double(value) {
10534
- return this._push(util.float.writeDoubleLE, 8, value);
10697
+ this._reserve(8);
10698
+ util.float.writeDoubleLE(value, this.buf, this.pos);
10699
+ this.pos += 8;
10700
+ return this;
10535
10701
  };
10536
10702
 
10537
- var writeBytes = util.Array.prototype.set
10538
- ? function writeBytes_set(val, buf, pos) {
10539
- buf.set(val, pos); // also works for plain array values
10540
- }
10541
- /* istanbul ignore next */
10542
- : function writeBytes_for(val, buf, pos) {
10543
- for (var i = 0; i < val.length; ++i)
10544
- buf[pos + i] = val[i];
10545
- };
10546
-
10547
10703
  /**
10548
10704
  * Writes a sequence of bytes.
10549
10705
  * @param {Uint8Array|string} value Buffer or base64 encoded string to write
@@ -10551,14 +10707,21 @@ var writeBytes = util.Array.prototype.set
10551
10707
  */
10552
10708
  Writer.prototype.bytes = function write_bytes(value) {
10553
10709
  var len = value.length >>> 0;
10554
- if (!len)
10555
- return this._push(writeByte, 1, 0);
10710
+ if (!len) {
10711
+ this._reserve(1);
10712
+ this.buf[this.pos++] = 0;
10713
+ return this;
10714
+ }
10556
10715
  if (util.isString(value)) {
10557
10716
  var buf = Writer.alloc(len = base64.length(value));
10558
10717
  base64.decode(value, buf, 0);
10559
10718
  value = buf;
10560
10719
  }
10561
- return this.uint32(len)._push(writeBytes, len, value);
10720
+ this.uint32(len);
10721
+ this._reserve(len);
10722
+ this.buf.set(value, this.pos);
10723
+ this.pos += len;
10724
+ return this;
10562
10725
  };
10563
10726
 
10564
10727
  /**
@@ -10568,7 +10731,28 @@ Writer.prototype.bytes = function write_bytes(value) {
10568
10731
  */
10569
10732
  Writer.prototype.raw = function write_raw(value) {
10570
10733
  var len = value.length >>> 0;
10571
- return len ? this._push(writeBytes, len, value) : this;
10734
+ if (!len)
10735
+ return this;
10736
+ this._reserve(len);
10737
+ this.buf.set(value, this.pos);
10738
+ this.pos += len;
10739
+ return this;
10740
+ };
10741
+
10742
+ /**
10743
+ * Backfills the length varint.
10744
+ * @param {number} pos Position of reserved length byte
10745
+ * @param {number} len Length of content after length varint
10746
+ * @returns {Writer} `this`
10747
+ * @private
10748
+ */
10749
+ Writer.prototype._delim = function _delim(pos, len) {
10750
+ var n = sizeVarint32(len);
10751
+ if (n > 1)
10752
+ this.buf.copyWithin(pos + n, pos + 1, pos + 1 + len);
10753
+ writeVarint32(len, this.buf, pos);
10754
+ this.pos = pos + n + len;
10755
+ return this;
10572
10756
  };
10573
10757
 
10574
10758
  /**
@@ -10577,21 +10761,245 @@ Writer.prototype.raw = function write_raw(value) {
10577
10761
  * @returns {Writer} `this`
10578
10762
  */
10579
10763
  Writer.prototype.string = function write_string(value) {
10764
+ var n = value.length;
10765
+ if (!n) {
10766
+ this._reserve(1);
10767
+ this.buf[this.pos++] = 0;
10768
+ return this;
10769
+ }
10770
+ if (n < 0x80) {
10771
+ this._reserve(n * 3 + 5); // worst case
10772
+ var lenPos = this.pos;
10773
+ return this._delim(lenPos, utf8.write(value, this.buf, lenPos + 1));
10774
+ }
10580
10775
  var len = utf8.length(value);
10581
- return len
10582
- ? this.uint32(len)._push(len === value.length ? writeStringAscii : utf8.write, len, value)
10583
- : this._push(writeByte, 1, 0);
10776
+ this.uint32(len);
10777
+ this._reserve(len);
10778
+ if (len === value.length)
10779
+ writeStringAscii(value, this.buf, this.pos);
10780
+ else
10781
+ utf8.write(value, this.buf, this.pos);
10782
+ this.pos += len;
10783
+ return this;
10784
+ };
10785
+
10786
+ /**
10787
+ * Writes an array of unsigned 32 bit values as a packed repeated field.
10788
+ * @param {number[]} value Values to write
10789
+ * @returns {Writer} `this`
10790
+ */
10791
+ Writer.prototype.uint32s = function write_uint32s(value) {
10792
+ var n = value.length;
10793
+ this._reserve(n * 5 + 5); // worst case: 5 bytes per value + length varint
10794
+ var buf = this.buf, lenPos = this.pos, p = lenPos + 1;
10795
+ for (var i = 0; i < n; ++i)
10796
+ p = writeVarint32(value[i] >>> 0, buf, p);
10797
+ return this._delim(lenPos, p - lenPos - 1);
10798
+ };
10799
+
10800
+ /**
10801
+ * Writes an array of signed 32 bit values as a packed repeated field.
10802
+ * @param {number[]} value Values to write
10803
+ * @returns {Writer} `this`
10804
+ */
10805
+ Writer.prototype.int32s = function write_int32s(value) {
10806
+ var n = value.length;
10807
+ this._reserve(n * 10 + 5); // worst case: 10 bytes per negative value + length varint
10808
+ var buf = this.buf, lenPos = this.pos, pos = lenPos + 1, val;
10809
+ for (var i = 0; i < n; ++i) {
10810
+ if ((val = value[i] | 0) < 0) { // negatives are 10 bytes per spec
10811
+ pos = writeVarint64(LongBits.fromNumber(val), buf, pos);
10812
+ } else {
10813
+ pos = writeVarint32(val, buf, pos);
10814
+ }
10815
+ }
10816
+ return this._delim(lenPos, pos - lenPos - 1);
10817
+ };
10818
+
10819
+ /**
10820
+ * Writes an array of 32 bit values as packed, zig-zag encoded varints.
10821
+ * @param {number[]} value Values to write
10822
+ * @returns {Writer} `this`
10823
+ */
10824
+ Writer.prototype.sint32s = function write_sint32s(value) {
10825
+ var n = value.length;
10826
+ this._reserve(n * 5 + 5);
10827
+ var buf = this.buf, lenPos = this.pos, pos = lenPos + 1;
10828
+ for (var i = 0; i < n; ++i)
10829
+ pos = writeVarint32((value[i] << 1 ^ value[i] >> 31) >>> 0, buf, pos);
10830
+ return this._delim(lenPos, pos - lenPos - 1);
10831
+ };
10832
+
10833
+ /**
10834
+ * Writes an array of unsigned 64 bit values as a packed repeated field.
10835
+ * @param {Array.<Long|number|string>} value Values to write
10836
+ * @returns {Writer} `this`
10837
+ */
10838
+ Writer.prototype.uint64s = function write_uint64s(value) {
10839
+ var n = value.length;
10840
+ this._reserve(n * 10 + 5);
10841
+ var buf = this.buf, lenPos = this.pos, pos = lenPos + 1;
10842
+ for (var i = 0; i < n; ++i) {
10843
+ pos = writeVarint64(LongBits.from(value[i]), buf, pos);
10844
+ }
10845
+ return this._delim(lenPos, pos - lenPos - 1);
10846
+ };
10847
+
10848
+ /**
10849
+ * Writes an array of signed 64 bit values as a packed repeated field.
10850
+ * @function
10851
+ * @param {Array.<Long|number|string>} value Values to write
10852
+ * @returns {Writer} `this`
10853
+ */
10854
+ Writer.prototype.int64s = Writer.prototype.uint64s;
10855
+
10856
+ /**
10857
+ * Writes an array of 64 bit values as packed, zig-zag encoded varints.
10858
+ * @param {Array.<Long|number|string>} value Values to write
10859
+ * @returns {Writer} `this`
10860
+ */
10861
+ Writer.prototype.sint64s = function write_sint64s(value) {
10862
+ var n = value.length;
10863
+ this._reserve(n * 10 + 5);
10864
+ var buf = this.buf, lenPos = this.pos, pos = lenPos + 1;
10865
+ for (var i = 0; i < n; ++i) {
10866
+ pos = writeVarint64(LongBits.from(value[i]).zzEncode(), buf, pos);
10867
+ }
10868
+ return this._delim(lenPos, pos - lenPos - 1);
10869
+ };
10870
+
10871
+ /**
10872
+ * Writes an array of boolish values as a packed repeated field.
10873
+ * @param {boolean[]} value Values to write
10874
+ * @returns {Writer} `this`
10875
+ */
10876
+ Writer.prototype.bools = function write_bools(value) {
10877
+ var n = value.length;
10878
+ this.uint32(n); // one byte per value
10879
+ this._reserve(n);
10880
+ var buf = this.buf, p = this.pos;
10881
+ for (var i = 0; i < n; ++i)
10882
+ buf[p++] = value[i] ? 1 : 0;
10883
+ this.pos += n;
10884
+ return this;
10885
+ };
10886
+
10887
+ // The view allocation only pays off when amortized over enough writes
10888
+ var VIEW_THRESHOLD_FLOAT = 16,
10889
+ VIEW_THRESHOLD_INT = 128;
10890
+
10891
+ function getLazyView(writer, count, threshold) {
10892
+ var view = writer.view;
10893
+ if (view || count < threshold)
10894
+ return view;
10895
+ var buf = writer.buf;
10896
+ return writer.view = new DataView(buf.buffer, buf.byteOffset, buf.byteLength);
10897
+ }
10898
+
10899
+ /**
10900
+ * Writes an array of unsigned 32 bit values as packed, fixed 32 bits.
10901
+ * @param {number[]} value Values to write
10902
+ * @returns {Writer} `this`
10903
+ */
10904
+ Writer.prototype.fixed32s = function write_fixed32s(value) {
10905
+ var n = value.length, bytes = n * 4;
10906
+ this.uint32(bytes); // length is known exactly
10907
+ this._reserve(bytes);
10908
+ var p = this.pos, i, dv = getLazyView(this, n, VIEW_THRESHOLD_INT);
10909
+ if (dv)
10910
+ for (i = 0; i < n; ++i) { dv.setUint32(p, value[i] >>> 0, true); p += 4; }
10911
+ else {
10912
+ var buf = this.buf;
10913
+ for (i = 0; i < n; ++i) { writeFixed32(value[i] >>> 0, buf, p); p += 4; }
10914
+ }
10915
+ this.pos += bytes;
10916
+ return this;
10917
+ };
10918
+
10919
+ /**
10920
+ * Writes an array of signed 32 bit values as packed, fixed 32 bits.
10921
+ * @function
10922
+ * @param {number[]} value Values to write
10923
+ * @returns {Writer} `this`
10924
+ */
10925
+ Writer.prototype.sfixed32s = Writer.prototype.fixed32s;
10926
+
10927
+ /**
10928
+ * Writes an array of unsigned 64 bit values as packed, fixed 64 bits.
10929
+ * @param {Array.<Long|number|string>} value Values to write
10930
+ * @returns {Writer} `this`
10931
+ */
10932
+ Writer.prototype.fixed64s = function write_fixed64s(value) {
10933
+ var n = value.length, bytes = n * 8;
10934
+ this.uint32(bytes);
10935
+ this._reserve(bytes);
10936
+ var p = this.pos, i, bits, dv = getLazyView(this, n, VIEW_THRESHOLD_INT);
10937
+ if (dv)
10938
+ for (i = 0; i < n; ++i) { bits = LongBits.from(value[i]); dv.setUint32(p, bits.lo, true); dv.setUint32(p + 4, bits.hi, true); p += 8; }
10939
+ else {
10940
+ var buf = this.buf;
10941
+ for (i = 0; i < n; ++i) { bits = LongBits.from(value[i]); writeFixed32(bits.lo, buf, p); writeFixed32(bits.hi, buf, p + 4); p += 8; }
10942
+ }
10943
+ this.pos += bytes;
10944
+ return this;
10945
+ };
10946
+
10947
+ /**
10948
+ * Writes an array of signed 64 bit values as packed, fixed 64 bits.
10949
+ * @function
10950
+ * @param {Array.<Long|number|string>} value Values to write
10951
+ * @returns {Writer} `this`
10952
+ */
10953
+ Writer.prototype.sfixed64s = Writer.prototype.fixed64s;
10954
+
10955
+ /**
10956
+ * Writes an array of floats (32 bit) as a packed repeated field.
10957
+ * @param {number[]} value Values to write
10958
+ * @returns {Writer} `this`
10959
+ */
10960
+ Writer.prototype.floats = function write_floats(value) {
10961
+ var n = value.length, bytes = n * 4;
10962
+ this.uint32(bytes);
10963
+ this._reserve(bytes);
10964
+ var p = this.pos, i, dv = getLazyView(this, n, VIEW_THRESHOLD_FLOAT);
10965
+ if (dv)
10966
+ for (i = 0; i < n; ++i) { dv.setFloat32(p, value[i], true); p += 4; }
10967
+ else {
10968
+ var buf = this.buf;
10969
+ for (i = 0; i < n; ++i) { util.float.writeFloatLE(value[i], buf, p); p += 4; }
10970
+ }
10971
+ this.pos += bytes;
10972
+ return this;
10973
+ };
10974
+
10975
+ /**
10976
+ * Writes an array of doubles (64 bit float) as a packed repeated field.
10977
+ * @param {number[]} value Values to write
10978
+ * @returns {Writer} `this`
10979
+ */
10980
+ Writer.prototype.doubles = function write_doubles(value) {
10981
+ var n = value.length, bytes = n * 8;
10982
+ this.uint32(bytes);
10983
+ this._reserve(bytes);
10984
+ var p = this.pos, i, dv = getLazyView(this, n, VIEW_THRESHOLD_FLOAT);
10985
+ if (dv)
10986
+ for (i = 0; i < n; ++i) { dv.setFloat64(p, value[i], true); p += 8; }
10987
+ else {
10988
+ var buf = this.buf;
10989
+ for (i = 0; i < n; ++i) { util.float.writeDoubleLE(value[i], buf, p); p += 8; }
10990
+ }
10991
+ this.pos += bytes;
10992
+ return this;
10584
10993
  };
10585
10994
 
10586
10995
  /**
10587
10996
  * Forks this writer's state by pushing it to a stack.
10588
- * Calling {@link Writer#reset|reset} or {@link Writer#ldelim|ldelim} resets the writer to the previous state.
10589
10997
  * @returns {Writer} `this`
10590
10998
  */
10591
10999
  Writer.prototype.fork = function fork() {
10592
- this.states = new State(this);
10593
- this.head = this.tail = new Op(noop, 0, 0);
10594
- this.len = 0;
11000
+ this._reserve(1);
11001
+ (this.states || (this.states = [])).push(this.pos);
11002
+ this.pos += 1;
10595
11003
  return this;
10596
11004
  };
10597
11005
 
@@ -10600,47 +11008,66 @@ Writer.prototype.fork = function fork() {
10600
11008
  * @returns {Writer} `this`
10601
11009
  */
10602
11010
  Writer.prototype.reset = function reset() {
10603
- if (this.states) {
10604
- this.head = this.states.head;
10605
- this.tail = this.states.tail;
10606
- this.len = this.states.len;
10607
- this.states = this.states.next;
11011
+ var states = this.states;
11012
+ if (states && states.length) {
11013
+ this.pos = states.pop();
10608
11014
  } else {
10609
- this.head = this.tail = new Op(noop, 0, 0);
10610
- this.len = 0;
11015
+ this.pos = 0;
10611
11016
  }
10612
11017
  return this;
10613
11018
  };
10614
11019
 
10615
11020
  /**
10616
- * Resets to the last state and appends the fork state's current write length as a varint followed by its operations.
11021
+ * Resets to the last state and prepends the fork state's current write length as a varint.
10617
11022
  * @returns {Writer} `this`
10618
11023
  */
10619
11024
  Writer.prototype.ldelim = function ldelim() {
10620
- var head = this.head,
10621
- tail = this.tail,
10622
- len = this.len;
10623
- this.reset().uint32(len);
10624
- if (len) {
10625
- this.tail.next = head.next; // skip noop
10626
- this.tail = tail;
10627
- this.len += len;
11025
+ var states = this.states,
11026
+ len,
11027
+ vlen;
11028
+ if (states && states.length) {
11029
+ var lenPos = states.pop();
11030
+ len = this.pos - lenPos - 1;
11031
+ vlen = sizeVarint32(len);
11032
+ if (vlen > 1) { // grow the reserved single byte and shift content forward
11033
+ this._reserve(vlen - 1);
11034
+ this.buf.copyWithin(lenPos + vlen, lenPos + 1, lenPos + 1 + len);
11035
+ this.pos += vlen - 1;
11036
+ writeVarint32(len, this.buf, lenPos);
11037
+ } else {
11038
+ this.buf[lenPos] = len;
11039
+ }
11040
+ } else { // not forked: prefix the entire buffer with its length
11041
+ // TODO: Compatibility with older generated code.
11042
+ // Remove this branch in the next major release.
11043
+ len = this.pos;
11044
+ vlen = sizeVarint32(len);
11045
+ this._reserve(vlen);
11046
+ this.buf.copyWithin(vlen, 0, len);
11047
+ writeVarint32(len, this.buf, 0);
11048
+ this.pos += vlen;
10628
11049
  }
10629
11050
  return this;
10630
11051
  };
10631
11052
 
10632
11053
  /**
10633
11054
  * Finishes the write operation.
11055
+ * Returns a buffer sized to the written data by default.
11056
+ * @param {boolean} [shared=false] Whether to return a shared view instead of a unique copy
10634
11057
  * @returns {Uint8Array} Finished buffer
10635
11058
  */
10636
- Writer.prototype.finish = function finish() {
10637
- return this.finishInto(this.constructor.alloc(this.len), 0);
11059
+ Writer.prototype.finish = function finish(shared) {
11060
+ if (shared)
11061
+ return this.buf.subarray(0, this.pos);
11062
+ var buf = this.constructor.alloc(this.pos);
11063
+ buf.set(this.buf.subarray(0, this.pos), 0);
11064
+ return buf;
10638
11065
  };
10639
11066
 
10640
11067
  /**
10641
11068
  * Finishes the write operation, writing into the provided buffer.
10642
11069
  * The caller must ensure that `buf` has enough space starting at `offset`
10643
- * to hold {@link Writer#len} bytes.
11070
+ * to hold {@link Writer#pos} bytes.
10644
11071
  * @param {T} buf Target buffer
10645
11072
  * @param {number} [offset=0] Offset to start writing at
10646
11073
  * @returns {T} The provided buffer
@@ -10649,13 +11076,7 @@ Writer.prototype.finish = function finish() {
10649
11076
  Writer.prototype.finishInto = function finishInto(buf, offset) {
10650
11077
  if (offset === undefined)
10651
11078
  offset = 0;
10652
- var head = this.head.next,
10653
- pos = offset;
10654
- while (head) {
10655
- head.fn(head.val, buf, pos);
10656
- pos += head.len;
10657
- head = head.next;
10658
- }
11079
+ buf.set(this.buf.subarray(0, this.pos), offset);
10659
11080
  return buf;
10660
11081
  };
10661
11082
 
@@ -10692,6 +11113,8 @@ function BufferWriter() {
10692
11113
  Writer.call(this);
10693
11114
  }
10694
11115
 
11116
+ var writeStringBuffer;
11117
+
10695
11118
  BufferWriter._configure = function () {
10696
11119
  /**
10697
11120
  * Allocates a buffer of the specified size.
@@ -10699,19 +11122,14 @@ BufferWriter._configure = function () {
10699
11122
  * @param {number} size Buffer size
10700
11123
  * @returns {Buffer} Buffer
10701
11124
  */
10702
- BufferWriter.alloc = util._Buffer_allocUnsafe;
11125
+ BufferWriter.alloc = util.Buffer && util.Buffer.allocUnsafe;
10703
11126
 
10704
- BufferWriter.writeBytesBuffer = util.Buffer && util.Buffer.prototype instanceof Uint8Array && util.Buffer.prototype.set.name === "set"
10705
- ? function writeBytesBuffer_set(val, buf, pos) {
10706
- buf.set(val, pos); // faster than copy (requires node >= 4 where Buffers extend Uint8Array and set is properly inherited)
10707
- // also works for plain array values
11127
+ writeStringBuffer = util.Buffer && util.Buffer.prototype.utf8Write
11128
+ ? function writeStringBuffer_utf8Write(val, buf, pos) {
11129
+ return buf.utf8Write(val, pos);
10708
11130
  }
10709
- /* istanbul ignore next */
10710
- : function writeBytesBuffer_copy(val, buf, pos) {
10711
- if (val.copy) // Buffer values
10712
- val.copy(buf, pos, 0, val.length);
10713
- else for (var i = 0; i < val.length;) // plain array values
10714
- buf[pos++] = val[i++];
11131
+ : function writeStringBuffer_write(val, buf, pos) {
11132
+ return buf.write(val, pos);
10715
11133
  };
10716
11134
  };
10717
11135
 
@@ -10721,48 +11139,42 @@ BufferWriter._configure = function () {
10721
11139
  */
10722
11140
  BufferWriter.prototype.bytes = function write_bytes_buffer(value) {
10723
11141
  if (util.isString(value))
10724
- value = util._Buffer_from(value, "base64");
11142
+ value = util.Buffer.from(value, "base64");
10725
11143
  var len = value.length >>> 0;
10726
11144
  this.uint32(len);
10727
- if (len)
10728
- this._push(BufferWriter.writeBytesBuffer, len, value);
11145
+ if (len) {
11146
+ this._reserve(len);
11147
+ this.buf.set(value, this.pos);
11148
+ this.pos += len;
11149
+ }
10729
11150
  return this;
10730
11151
  };
10731
11152
 
10732
- /**
10733
- * Writes raw bytes without a tag or length prefix.
10734
- * @name BufferWriter#raw
10735
- * @function
10736
- * @param {Uint8Array} value Raw bytes
10737
- * @returns {BufferWriter} `this`
10738
- */
10739
- BufferWriter.prototype.raw = function write_raw_buffer(value) {
10740
- var len = value.length >>> 0;
10741
- return len ? this._push(BufferWriter.writeBytesBuffer, len, value) : this;
10742
- };
10743
-
10744
- function writeStringBufferAscii(val, buf, pos) {
10745
- for (var i = 0; i < val.length;)
10746
- buf[pos++] = val.charCodeAt(i++);
10747
- }
10748
-
10749
- function writeStringBuffer(val, buf, pos) {
10750
- if (val.length < 40) // plain js is faster for short strings (probably due to redundant assertions)
10751
- util.utf8.write(val, buf, pos);
10752
- else if (buf.utf8Write)
10753
- buf.utf8Write(val, pos);
10754
- else
10755
- buf.write(val, pos);
10756
- }
10757
-
10758
11153
  /**
10759
11154
  * @override
10760
11155
  */
10761
11156
  BufferWriter.prototype.string = function write_string_buffer(value) {
11157
+ var n = value.length;
11158
+ if (!n) {
11159
+ this._reserve(1);
11160
+ this.buf[this.pos++] = 0;
11161
+ return this;
11162
+ }
11163
+ if (n < 0x80) {
11164
+ this._reserve(n * 3 + 5); // worst case
11165
+ var pos = this.pos,
11166
+ buf = this.buf;
11167
+ return this._delim(pos,
11168
+ n < 40
11169
+ ? util.utf8.write(value, buf, pos + 1)
11170
+ : writeStringBuffer(value, buf, pos + 1)
11171
+ );
11172
+ }
10762
11173
  var len = util.Buffer.byteLength(value);
10763
11174
  this.uint32(len);
10764
- if (len)
10765
- this._push(len === value.length && len < 40 ? writeStringBufferAscii : writeStringBuffer, len, value);
11175
+ this._reserve(len);
11176
+ writeStringBuffer(value, this.buf, this.pos);
11177
+ this.pos += len;
10766
11178
  return this;
10767
11179
  };
10768
11180