protobufjs 8.7.0 → 8.7.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/protobuf.js CHANGED
@@ -1,6 +1,6 @@
1
1
  /*!
2
- * protobuf.js v8.7.0 (c) 2016, daniel wirtz
3
- * compiled mon, 06 jul 2026 13:50:00 utc
2
+ * protobuf.js v8.7.2 (c) 2016, daniel wirtz
3
+ * compiled sat, 08 aug 2026 13:15:56 utc
4
4
  * licensed under the bsd-3-clause license
5
5
  * see: https://github.com/dcodeio/protobuf.js for details
6
6
  */
@@ -205,27 +205,33 @@ common("struct", {
205
205
  fields: {
206
206
  nullValue: {
207
207
  type: "NullValue",
208
- id: 1
208
+ id: 1,
209
+ protoName: "null_value"
209
210
  },
210
211
  numberValue: {
211
212
  type: "double",
212
- id: 2
213
+ id: 2,
214
+ protoName: "number_value"
213
215
  },
214
216
  stringValue: {
215
217
  type: "string",
216
- id: 3
218
+ id: 3,
219
+ protoName: "string_value"
217
220
  },
218
221
  boolValue: {
219
222
  type: "bool",
220
- id: 4
223
+ id: 4,
224
+ protoName: "bool_value"
221
225
  },
222
226
  structValue: {
223
227
  type: "Struct",
224
- id: 5
228
+ id: 5,
229
+ protoName: "struct_value"
225
230
  },
226
231
  listValue: {
227
232
  type: "ListValue",
228
- id: 6
233
+ id: 6,
234
+ protoName: "list_value"
229
235
  }
230
236
  }
231
237
  },
@@ -741,12 +747,16 @@ converter.toObject = function toObject(mtype) {
741
747
  else if (field.bytes) {
742
748
  var arrayDefault = Array.prototype.slice.call(field.typeDefault);
743
749
  gen
744
- ("if(o.bytes===String)d%s=%j", prop, String.fromCharCode.apply(String, field.typeDefault))
750
+ ("if(o.bytes===String)d%s=%j", prop, util.base64.encode(field.typeDefault, 0, field.typeDefault.length))
745
751
  ("else{")
746
752
  ("d%s=%j", prop, arrayDefault)
747
753
  ("if(o.bytes!==Array)d%s=util.newBuffer(d%s)", prop, prop)
748
754
  ("}");
749
- } else gen
755
+ } else if ((field.type === "double" || field.type === "float") && typeof field.typeDefault === "number"
756
+ && (!isFinite(field.typeDefault) || Object.is(field.typeDefault, -0))) gen
757
+ ("d%s=%f", prop, field.typeDefault)
758
+ ("if(o.json&&!isFinite(d%s))d%s=String(d%s)", prop, prop, prop);
759
+ else gen
750
760
  ("d%s=%j", prop, field.typeDefault); // also messages (=null)
751
761
  } gen
752
762
  ("}");
@@ -899,7 +909,7 @@ function decoder(mtype) {
899
909
  ("break");
900
910
 
901
911
  if (types.basic[type] === undefined) gen
902
- ("v=types[%i].decode(r,r.uint32(),undefined,q+1)", i); // can't be groups
912
+ ("v=types[%i].decode(r,r.uint32(),undefined,q+1,v)", i); // can't be groups
903
913
  else gen
904
914
  ("v=r.%s()", type === "string" ? stringMethod(field) : type);
905
915
 
@@ -1285,8 +1295,11 @@ function Enum(name, values, options, comment, comments, valuesOptions) {
1285
1295
 
1286
1296
  if (values)
1287
1297
  for (var keys = Object.keys(values), i = 0; i < keys.length; ++i)
1288
- if (keys[i] !== "__proto__" && typeof values[keys[i]] === "number") // use forward entries only
1289
- this.valuesById[ this.values[keys[i]] = values[keys[i]] ] = keys[i];
1298
+ if (keys[i] !== "__proto__" && typeof values[keys[i]] === "number") { // use forward entries only
1299
+ this.values[keys[i]] = values[keys[i]];
1300
+ if (this.valuesById[values[keys[i]]] === undefined)
1301
+ this.valuesById[values[keys[i]]] = keys[i];
1302
+ }
1290
1303
  }
1291
1304
 
1292
1305
  /**
@@ -1815,12 +1828,17 @@ Field.prototype.resolve = function resolve() {
1815
1828
 
1816
1829
  // convert to internal data type if necesssary
1817
1830
  if (this.long) {
1818
- this.typeDefault = util.Long.fromNumber(this.typeDefault, this.type === "uint64" || this.type === "fixed64");
1831
+ var unsigned = this.type === "uint64" || this.type === "fixed64";
1832
+ this.typeDefault = typeof this.typeDefault === "string"
1833
+ ? util.Long.fromString(this.typeDefault, unsigned)
1834
+ : util.Long.fromNumber(this.typeDefault, unsigned);
1819
1835
 
1820
1836
  /* istanbul ignore else */
1821
1837
  if (Object.freeze)
1822
1838
  Object.freeze(this.typeDefault); // long instances are meant to be immutable anyway (i.e. use small int cache that even requires it)
1823
1839
 
1840
+ } else if (types.long[this.type] !== undefined && typeof this.typeDefault === "string") {
1841
+ this.typeDefault = parseInt(this.typeDefault, 10);
1824
1842
  } else if (this.bytes && typeof this.typeDefault === "string") {
1825
1843
  var buf;
1826
1844
  if (util.base64.test(this.typeDefault))
@@ -2083,6 +2101,7 @@ exports.configure = configure;
2083
2101
  * @returns {undefined}
2084
2102
  */
2085
2103
  function configure() {
2104
+ exports.util.LongBits._configure(exports.util.Long);
2086
2105
  exports.Writer._configure(exports.BufferWriter);
2087
2106
  exports.Reader._configure(exports.BufferReader);
2088
2107
  }
@@ -3805,6 +3824,8 @@ var base10Re = /^[1-9][0-9]*$/,
3805
3824
  base16NegRe = /^-?0[x][0-9a-fA-F]+$/,
3806
3825
  base8Re = /^0[0-7]+$/,
3807
3826
  base8NegRe = /^-?0[0-7]+$/,
3827
+ integerTypeRe = /^(?:u?int|sint|s?fixed)(?:32|64)$/,
3828
+ unsignedTypeRe = /^(?:uint|fixed)(?:32|64)$/,
3808
3829
  numberRe = util.patterns.numberRe,
3809
3830
  nameRe = /^[a-zA-Z_][a-zA-Z_0-9]*$/,
3810
3831
  typeRefRe = util.patterns.typeRefRe;
@@ -3984,7 +4005,7 @@ function parse(source, root, options) {
3984
4005
  case "nan": case "NAN": case "Nan": case "NaN":
3985
4006
  return NaN;
3986
4007
  case "0":
3987
- return 0;
4008
+ return sign * 0;
3988
4009
  }
3989
4010
  if (base10Re.test(token))
3990
4011
  return sign * parseInt(token, 10);
@@ -4001,32 +4022,31 @@ function parse(source, root, options) {
4001
4022
  throw illegal(token, "number", insideTryCatch);
4002
4023
  }
4003
4024
 
4004
- function parseId(token, acceptNegative, max) {
4005
- if (token === null) {
4025
+ function parseInteger(token, acceptNegative, name) {
4026
+ if (token === null)
4006
4027
  throw illegal(token, "end of input");
4007
- }
4028
+ if (!acceptNegative && token.charAt(0) === "-")
4029
+ throw illegal(token, name || "integer");
4030
+ if (token === "0" || token === "-0")
4031
+ return 0;
4032
+ var value;
4033
+ if (base10NegRe.test(token))
4034
+ value = parseInt(token, 10);
4035
+ else if (base16NegRe.test(token))
4036
+ value = parseInt(token, 16);
4037
+ else if (base8NegRe.test(token))
4038
+ value = parseInt(token, 8);
4039
+ else
4040
+ throw illegal(token, name || "integer");
4041
+ return value || 0;
4042
+ }
4043
+
4044
+ function parseId(token, acceptNegative, max) {
4008
4045
  switch (token) {
4009
4046
  case "max": case "MAX": case "Max":
4010
4047
  return max || maxFieldId;
4011
- case "0":
4012
- return 0;
4013
4048
  }
4014
-
4015
- /* istanbul ignore if */
4016
- if (!acceptNegative && token.charAt(0) === "-")
4017
- throw illegal(token, "id");
4018
-
4019
- if (base10NegRe.test(token))
4020
- return parseInt(token, 10);
4021
- if (base16NegRe.test(token))
4022
- return parseInt(token, 16);
4023
-
4024
- /* istanbul ignore else */
4025
- if (base8NegRe.test(token))
4026
- return parseInt(token, 8);
4027
-
4028
- /* istanbul ignore next */
4029
- throw illegal(token, "id");
4049
+ return parseInteger(token, acceptNegative, "id");
4030
4050
  }
4031
4051
 
4032
4052
  function parsePackage() {
@@ -4341,6 +4361,10 @@ function parse(source, root, options) {
4341
4361
  case ";":
4342
4362
  break;
4343
4363
 
4364
+ case "map":
4365
+ parseMapField(type);
4366
+ break;
4367
+
4344
4368
  case "option":
4345
4369
  parseOption(type, token);
4346
4370
  skip(";");
@@ -4470,7 +4494,8 @@ function parse(source, root, options) {
4470
4494
  if ((token = next()) === null || !nameRe.test(token))
4471
4495
  throw illegal(token, "name");
4472
4496
 
4473
- var enm = new Enum(token);
4497
+ var enm = new Enum(token),
4498
+ values = [];
4474
4499
  ifBlock(enm, function parseEnum_block(token) {
4475
4500
  switch(token) {
4476
4501
  case ";":
@@ -4487,16 +4512,18 @@ function parse(source, root, options) {
4487
4512
  break;
4488
4513
 
4489
4514
  default:
4490
- parseEnumValue(enm, token);
4515
+ values.push(parseEnumValue(token));
4491
4516
  }
4492
4517
  });
4518
+ for (var i = 0; i < values.length; ++i)
4519
+ enm.add(values[i].name, values[i].id, values[i].comment, values[i].options);
4493
4520
  parent.add(enm);
4494
4521
  if (parent === ptr) {
4495
4522
  topLevelObjects.push(enm);
4496
4523
  }
4497
4524
  }
4498
4525
 
4499
- function parseEnumValue(parent, token) {
4526
+ function parseEnumValue(token) {
4500
4527
 
4501
4528
  /* istanbul ignore if */
4502
4529
  if (!nameRe.test(token))
@@ -4528,7 +4555,12 @@ function parse(source, root, options) {
4528
4555
  }, function parseEnumValue_line() {
4529
4556
  parseInlineOptions(dummy); // skip
4530
4557
  });
4531
- parent.add(token, value, dummy.comment, dummy.parsedOptions || dummy.options);
4558
+ return {
4559
+ name: token,
4560
+ id: value,
4561
+ comment: dummy.comment,
4562
+ options: dummy.parsedOptions || dummy.options
4563
+ };
4532
4564
  }
4533
4565
 
4534
4566
  function parseOption(parent, token) {
@@ -4579,16 +4611,27 @@ function parse(source, root, options) {
4579
4611
  var objectResult = {};
4580
4612
 
4581
4613
  while (!skip("}", true)) {
4582
- /* istanbul ignore if */
4583
- if (!nameRe.test(token = next())) {
4584
- throw illegal(token, "name");
4585
- }
4586
- if (token === null) {
4587
- throw illegal(token, "end of input");
4614
+ token = next();
4615
+ var propName;
4616
+ if (token === null)
4617
+ throw illegal(token, "end of input");
4618
+ if (token === "[") {
4619
+ token = next();
4620
+ // Extension name or, for Any, a type URL: "<prefix>/<fully.qualified.Type>".
4621
+ var slash = token === null ? -1 : token.lastIndexOf("/");
4622
+ if (token === null || !typeRefRe.test(slash < 0 ? token : token.slice(slash + 1)))
4623
+ throw illegal(token, "name");
4624
+ propName = "[" + token + "]";
4625
+ skip("]");
4626
+ } else {
4627
+ /* istanbul ignore if */
4628
+ if (!nameRe.test(token)) {
4629
+ throw illegal(token, "name");
4630
+ }
4631
+ propName = token;
4588
4632
  }
4589
4633
 
4590
4634
  var value;
4591
- var propName = token;
4592
4635
 
4593
4636
  skip(":", true);
4594
4637
 
@@ -4596,25 +4639,30 @@ function parse(source, root, options) {
4596
4639
  // option (my_option) = {
4597
4640
  // repeated_value: [ "foo", "bar" ]
4598
4641
  // };
4599
- value = parseOptionValue(parent, name + "." + token, depth + 1);
4642
+ value = parseOptionValue(parent, name + "." + propName, depth + 1);
4600
4643
  } else if (peek() === "[") {
4601
4644
  value = [];
4602
- var lastValue;
4645
+ var lastValue,
4646
+ lastValueIsAggregate;
4603
4647
  if (skip("[", true)) {
4604
4648
  if (!skip("]", true)) {
4605
4649
  do {
4606
- lastValue = readValue(true);
4650
+ lastValueIsAggregate = peek() === "{";
4651
+ lastValue = lastValueIsAggregate
4652
+ ? parseOptionValue(parent, name + "." + propName, depth + 1)
4653
+ : readValue(true);
4607
4654
  value.push(lastValue);
4608
4655
  } while (skip(",", true));
4609
4656
  skip("]");
4610
4657
  if (typeof lastValue !== "undefined") {
4611
- setOption(parent, name + "." + token, lastValue);
4658
+ if (!lastValueIsAggregate)
4659
+ setOption(parent, name + "." + propName, lastValue);
4612
4660
  }
4613
4661
  }
4614
4662
  }
4615
4663
  } else {
4616
4664
  value = readValue(true);
4617
- setOption(parent, name + "." + token, value);
4665
+ setOption(parent, name + "." + propName, value);
4618
4666
  }
4619
4667
 
4620
4668
  var prevValue = Object.prototype.hasOwnProperty.call(objectResult, propName)
@@ -4635,7 +4683,9 @@ function parse(source, root, options) {
4635
4683
  return objectResult;
4636
4684
  }
4637
4685
 
4638
- var simpleValue = readValue(true);
4686
+ var simpleValue = name === "default" && parent instanceof Field && integerTypeRe.test(parent.type)
4687
+ ? parseInteger(next(), !unsignedTypeRe.test(parent.type))
4688
+ : readValue(true);
4639
4689
  setOption(parent, name, simpleValue);
4640
4690
  return simpleValue;
4641
4691
  // Does not enforce a delimiter to be universal
@@ -5262,9 +5312,18 @@ Reader.prototype.double = function read_double() {
5262
5312
  */
5263
5313
  Reader.prototype.uint32s = function read_uint32s(array) {
5264
5314
  if (array === undefined) array = [];
5265
- var end = this.uint32() + this.pos;
5266
- while (this.pos < end)
5267
- array.push(this.uint32());
5315
+ var end = this.uint32() + this.pos, buf = this.buf, pos = this.pos, value;
5316
+ while (pos < end) {
5317
+ value = buf[pos++];
5318
+ if (value < 128)
5319
+ array.push(value);
5320
+ else {
5321
+ this.pos = pos - 1;
5322
+ array.push(this.uint32());
5323
+ pos = this.pos;
5324
+ }
5325
+ }
5326
+ this.pos = pos;
5268
5327
  return array;
5269
5328
  };
5270
5329
 
@@ -5275,9 +5334,18 @@ Reader.prototype.uint32s = function read_uint32s(array) {
5275
5334
  */
5276
5335
  Reader.prototype.int32s = function read_int32s(array) {
5277
5336
  if (array === undefined) array = [];
5278
- var end = this.uint32() + this.pos;
5279
- while (this.pos < end)
5280
- array.push(this.int32());
5337
+ var end = this.uint32() + this.pos, buf = this.buf, pos = this.pos, value;
5338
+ while (pos < end) {
5339
+ value = buf[pos++];
5340
+ if (value < 128)
5341
+ array.push(value);
5342
+ else {
5343
+ this.pos = pos - 1;
5344
+ array.push(this.int32());
5345
+ pos = this.pos;
5346
+ }
5347
+ }
5348
+ this.pos = pos;
5281
5349
  return array;
5282
5350
  };
5283
5351
 
@@ -5301,9 +5369,18 @@ Reader.prototype.sint32s = function read_sint32s(array) {
5301
5369
  */
5302
5370
  Reader.prototype.bools = function read_bools(array) {
5303
5371
  if (array === undefined) array = [];
5304
- var end = this.uint32() + this.pos;
5305
- while (this.pos < end)
5306
- array.push(this.bool());
5372
+ var end = this.uint32() + this.pos, buf = this.buf, pos = this.pos, value;
5373
+ while (pos < end) {
5374
+ value = buf[pos++];
5375
+ if (value < 128)
5376
+ array.push(value !== 0);
5377
+ else {
5378
+ this.pos = pos - 1;
5379
+ array.push(this.bool());
5380
+ pos = this.pos;
5381
+ }
5382
+ }
5383
+ this.pos = pos;
5307
5384
  return array;
5308
5385
  };
5309
5386
 
@@ -8416,7 +8493,9 @@ function codegen(functionParams, functionName) {
8416
8493
  formatStringOrScope = formatStringOrScope.replace(/%([%dfijs])/g, function replace($0, $1) {
8417
8494
  var value = formatParams[formatOffset++];
8418
8495
  switch ($1) {
8419
- case "d": case "f": return String(Number(value));
8496
+ case "d": case "f":
8497
+ value = Number(value);
8498
+ return Object.is(value, -0) ? "-0" : String(value);
8420
8499
  case "i": return String(Math.floor(value));
8421
8500
  case "j": return JSON.stringify(value);
8422
8501
  case "s": return String(value);
@@ -9025,7 +9104,7 @@ module.exports = fs;
9025
9104
  "use strict";
9026
9105
  module.exports = LongBits;
9027
9106
 
9028
- var util = require(37);
9107
+ var Long;
9029
9108
 
9030
9109
  /**
9031
9110
  * Constructs new long bits.
@@ -9104,10 +9183,10 @@ LongBits.fromNumber = function fromNumber(value) {
9104
9183
  LongBits.from = function from(value) {
9105
9184
  if (typeof value === "number")
9106
9185
  return LongBits.fromNumber(value);
9107
- if (util.isString(value)) {
9186
+ if (typeof value === "string" || value instanceof String) {
9108
9187
  /* istanbul ignore else */
9109
- if (util.Long)
9110
- value = util.Long.fromString(value);
9188
+ if (Long)
9189
+ value = Long.fromString(value);
9111
9190
  else
9112
9191
  return LongBits.fromNumber(parseInt(value, 10));
9113
9192
  }
@@ -9136,8 +9215,8 @@ LongBits.prototype.toNumber = function toNumber(unsigned) {
9136
9215
  * @returns {Long} Long
9137
9216
  */
9138
9217
  LongBits.prototype.toLong = function toLong(unsigned) {
9139
- return util.Long
9140
- ? new util.Long(this.lo | 0, this.hi | 0, Boolean(unsigned))
9218
+ return Long
9219
+ ? new Long(this.lo | 0, this.hi | 0, Boolean(unsigned))
9141
9220
  /* istanbul ignore next */
9142
9221
  : { low: this.lo | 0, high: this.hi | 0, unsigned: Boolean(unsigned) };
9143
9222
  };
@@ -9223,7 +9302,11 @@ LongBits.prototype.length = function length() {
9223
9302
  : part2 < 128 ? 9 : 10;
9224
9303
  };
9225
9304
 
9226
- },{"37":37}],37:[function(require,module,exports){
9305
+ LongBits._configure = function(Long_) {
9306
+ Long = Long_;
9307
+ };
9308
+
9309
+ },{}],37:[function(require,module,exports){
9227
9310
  "use strict";
9228
9311
  /* global globalThis */
9229
9312
  var util = exports;
@@ -9906,7 +9989,6 @@ function pool(alloc, slice, size) {
9906
9989
  * @namespace
9907
9990
  */
9908
9991
  var utf8 = exports,
9909
- replacementChar = "\ufffd",
9910
9992
  looseDecoder = new TextDecoder("utf-8", { ignoreBOM: true }),
9911
9993
  strictDecoder;
9912
9994
  var TEXT_DECODER_MIN_LENGTH = 64;
@@ -9941,31 +10023,6 @@ utf8.length = function utf8_length(string) {
9941
10023
  return len;
9942
10024
  };
9943
10025
 
9944
- function utf8_read_js(buffer, start, end, str) {
9945
- for (var i = start; i < end;) {
9946
- var t = buffer[i++];
9947
- if (t <= 0x7F) {
9948
- str += String.fromCharCode(t);
9949
- } else if (t >= 0xC0 && t < 0xE0) {
9950
- var c2 = (t & 0x1F) << 6 | buffer[i++] & 0x3F;
9951
- str += c2 >= 0x80 ? String.fromCharCode(c2) : replacementChar;
9952
- } else if (t >= 0xE0 && t < 0xF0) {
9953
- var c3 = (t & 0xF) << 12 | (buffer[i++] & 0x3F) << 6 | buffer[i++] & 0x3F;
9954
- str += c3 >= 0x800 ? String.fromCharCode(c3) : replacementChar;
9955
- } else if (t >= 0xF0) {
9956
- var t2 = (t & 7) << 18 | (buffer[i++] & 0x3F) << 12 | (buffer[i++] & 0x3F) << 6 | buffer[i++] & 0x3F;
9957
- if (t2 < 0x10000 || t2 > 0x10FFFF)
9958
- str += replacementChar;
9959
- else {
9960
- t2 -= 0x10000;
9961
- str += String.fromCharCode(0xD800 + (t2 >> 10));
9962
- str += String.fromCharCode(0xDC00 + (t2 & 0x3FF));
9963
- }
9964
- }
9965
- }
9966
- return str;
9967
- }
9968
-
9969
10026
  function utf8_read_decoder(decoder, buffer, start, end) {
9970
10027
  var source = start === 0 && end === buffer.length
9971
10028
  ? buffer
@@ -10000,14 +10057,14 @@ utf8.read = function utf8_read_loose(buffer, start, end) {
10000
10057
  c7 = buffer[i + 6];
10001
10058
  c8 = buffer[i + 7];
10002
10059
  if ((c1 | c2 | c3 | c4 | c5 | c6 | c7 | c8) & 0x80)
10003
- return utf8_read_js(buffer, i, end, str);
10060
+ return str + utf8_read_decoder(looseDecoder, buffer, i, end);
10004
10061
  str += String.fromCharCode(c1, c2, c3, c4, c5, c6, c7, c8);
10005
10062
  }
10006
10063
 
10007
10064
  for (; i < end; ++i) {
10008
10065
  c1 = buffer[i];
10009
10066
  if (c1 & 0x80)
10010
- return utf8_read_js(buffer, i, end, str);
10067
+ return str + utf8_read_decoder(looseDecoder, buffer, i, end);
10011
10068
  str += String.fromCharCode(c1);
10012
10069
  }
10013
10070
 
@@ -10413,7 +10470,7 @@ function Writer() {
10413
10470
  * Backing buffer.
10414
10471
  * @type {Uint8Array}
10415
10472
  */
10416
- this.buf = this.constructor.alloc(64);
10473
+ this.buf = this.constructor.alloc(Writer.initialBufferSize);
10417
10474
 
10418
10475
  /**
10419
10476
  * Cached DataView over {@link Writer#buf}.
@@ -10428,6 +10485,12 @@ function Writer() {
10428
10485
  this.states = null;
10429
10486
  }
10430
10487
 
10488
+ /**
10489
+ * Initial backing buffer size in bytes. Defaults to 128.
10490
+ * @type {number}
10491
+ */
10492
+ Writer.initialBufferSize = 128;
10493
+
10431
10494
  /**
10432
10495
  * Current write position.
10433
10496
  * @name Writer#len