protobufjs 8.7.2 → 8.8.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/README.md +24 -17
- package/dist/light/protobuf.js +124 -14
- package/dist/light/protobuf.js.map +1 -1
- package/dist/light/protobuf.min.js +3 -3
- package/dist/light/protobuf.min.js.map +1 -1
- package/dist/minimal/protobuf.js +63 -9
- package/dist/minimal/protobuf.js.map +1 -1
- package/dist/minimal/protobuf.min.js +3 -3
- package/dist/minimal/protobuf.min.js.map +1 -1
- package/dist/protobuf.js +133 -18
- package/dist/protobuf.js.map +1 -1
- package/dist/protobuf.min.js +3 -3
- package/dist/protobuf.min.js.map +1 -1
- package/ext/descriptor.generated.d.ts +7 -0
- package/ext/descriptor.js +24 -0
- package/ext/protojson.js +14 -4
- package/ext/textformat.js +8 -4
- package/google/protobuf/descriptor.json +20 -1
- package/google/protobuf/descriptor.proto +14 -1
- package/index.d.ts +12 -0
- package/package.json +1 -1
- package/src/decoder.js +31 -2
- package/src/enum.js +10 -0
- package/src/object.js +5 -2
- package/src/parse.js +9 -4
- package/src/reader.js +61 -7
- package/src/type.js +10 -0
- package/src/wrappers.js +5 -1
package/src/reader.js
CHANGED
|
@@ -94,12 +94,32 @@ Reader.prototype.raw = function read_raw(start, end) {
|
|
|
94
94
|
return this.buf.subarray(start, end);
|
|
95
95
|
};
|
|
96
96
|
|
|
97
|
+
function readVarint32NearEnd(reader) {
|
|
98
|
+
// Safely read up to four bytes of a varint32 near the reader limit
|
|
99
|
+
var value = 0;
|
|
100
|
+
for (var i = 0; i < 4; ++i) {
|
|
101
|
+
if (reader.pos >= reader.len)
|
|
102
|
+
throw indexOutOfRange(reader);
|
|
103
|
+
var b = reader.buf[reader.pos++];
|
|
104
|
+
value = (value | (b & 127) << i * 7) >>> 0;
|
|
105
|
+
if (b < 128)
|
|
106
|
+
return value;
|
|
107
|
+
}
|
|
108
|
+
throw indexOutOfRange(reader);
|
|
109
|
+
}
|
|
110
|
+
|
|
97
111
|
/**
|
|
98
112
|
* Reads a varint as an unsigned 32 bit value.
|
|
99
113
|
* @function
|
|
100
114
|
* @returns {number} Value read
|
|
101
115
|
*/
|
|
102
116
|
Reader.prototype.uint32 = function read_uint32() {
|
|
117
|
+
if (this.len - this.pos < 5) {
|
|
118
|
+
if (this.pos >= this.len)
|
|
119
|
+
throw indexOutOfRange(this);
|
|
120
|
+
if (this.buf[this.pos] >= 128)
|
|
121
|
+
return readVarint32NearEnd(this);
|
|
122
|
+
}
|
|
103
123
|
var buf = this.buf,
|
|
104
124
|
pos = this.pos,
|
|
105
125
|
value = (buf[pos] & 127) >>> 0;
|
|
@@ -150,6 +170,12 @@ Reader.prototype.uint32 = function read_uint32() {
|
|
|
150
170
|
* @returns {number} Tag read
|
|
151
171
|
*/
|
|
152
172
|
Reader.prototype.tag = function read_tag() {
|
|
173
|
+
if (this.len - this.pos < 5) {
|
|
174
|
+
if (this.pos >= this.len)
|
|
175
|
+
throw indexOutOfRange(this);
|
|
176
|
+
if (this.buf[this.pos] >= 128)
|
|
177
|
+
return readVarint32NearEnd(this);
|
|
178
|
+
}
|
|
153
179
|
var buf = this.buf,
|
|
154
180
|
pos = this.pos,
|
|
155
181
|
value = (buf[pos] & 127) >>> 0;
|
|
@@ -395,7 +421,9 @@ Reader.prototype.double = function read_double() {
|
|
|
395
421
|
*/
|
|
396
422
|
Reader.prototype.uint32s = function read_uint32s(array) {
|
|
397
423
|
if (array === undefined) array = [];
|
|
398
|
-
var end = this.uint32() + this.pos, buf = this.buf, pos = this.pos, value;
|
|
424
|
+
var end = this.uint32() + this.pos, len = this.len, buf = this.buf, pos = this.pos, value;
|
|
425
|
+
if (end > len) throw indexOutOfRange(this, end - this.pos);
|
|
426
|
+
this.len = end;
|
|
399
427
|
while (pos < end) {
|
|
400
428
|
value = buf[pos++];
|
|
401
429
|
if (value < 128)
|
|
@@ -407,6 +435,8 @@ Reader.prototype.uint32s = function read_uint32s(array) {
|
|
|
407
435
|
}
|
|
408
436
|
}
|
|
409
437
|
this.pos = pos;
|
|
438
|
+
if (pos !== end) throw RangeError("index out of range");
|
|
439
|
+
this.len = len;
|
|
410
440
|
return array;
|
|
411
441
|
};
|
|
412
442
|
|
|
@@ -417,7 +447,9 @@ Reader.prototype.uint32s = function read_uint32s(array) {
|
|
|
417
447
|
*/
|
|
418
448
|
Reader.prototype.int32s = function read_int32s(array) {
|
|
419
449
|
if (array === undefined) array = [];
|
|
420
|
-
var end = this.uint32() + this.pos, buf = this.buf, pos = this.pos, value;
|
|
450
|
+
var end = this.uint32() + this.pos, len = this.len, buf = this.buf, pos = this.pos, value;
|
|
451
|
+
if (end > len) throw indexOutOfRange(this, end - this.pos);
|
|
452
|
+
this.len = end;
|
|
421
453
|
while (pos < end) {
|
|
422
454
|
value = buf[pos++];
|
|
423
455
|
if (value < 128)
|
|
@@ -429,6 +461,8 @@ Reader.prototype.int32s = function read_int32s(array) {
|
|
|
429
461
|
}
|
|
430
462
|
}
|
|
431
463
|
this.pos = pos;
|
|
464
|
+
if (pos !== end) throw RangeError("index out of range");
|
|
465
|
+
this.len = len;
|
|
432
466
|
return array;
|
|
433
467
|
};
|
|
434
468
|
|
|
@@ -439,9 +473,13 @@ Reader.prototype.int32s = function read_int32s(array) {
|
|
|
439
473
|
*/
|
|
440
474
|
Reader.prototype.sint32s = function read_sint32s(array) {
|
|
441
475
|
if (array === undefined) array = [];
|
|
442
|
-
var end = this.uint32() + this.pos;
|
|
476
|
+
var end = this.uint32() + this.pos, len = this.len;
|
|
477
|
+
if (end > len) throw indexOutOfRange(this, end - this.pos);
|
|
478
|
+
this.len = end;
|
|
443
479
|
while (this.pos < end)
|
|
444
480
|
array.push(this.sint32());
|
|
481
|
+
if (this.pos !== end) throw RangeError("index out of range");
|
|
482
|
+
this.len = len;
|
|
445
483
|
return array;
|
|
446
484
|
};
|
|
447
485
|
|
|
@@ -452,7 +490,9 @@ Reader.prototype.sint32s = function read_sint32s(array) {
|
|
|
452
490
|
*/
|
|
453
491
|
Reader.prototype.bools = function read_bools(array) {
|
|
454
492
|
if (array === undefined) array = [];
|
|
455
|
-
var end = this.uint32() + this.pos, buf = this.buf, pos = this.pos, value;
|
|
493
|
+
var end = this.uint32() + this.pos, len = this.len, buf = this.buf, pos = this.pos, value;
|
|
494
|
+
if (end > len) throw indexOutOfRange(this, end - this.pos);
|
|
495
|
+
this.len = end;
|
|
456
496
|
while (pos < end) {
|
|
457
497
|
value = buf[pos++];
|
|
458
498
|
if (value < 128)
|
|
@@ -464,6 +504,8 @@ Reader.prototype.bools = function read_bools(array) {
|
|
|
464
504
|
}
|
|
465
505
|
}
|
|
466
506
|
this.pos = pos;
|
|
507
|
+
if (pos !== end) throw RangeError("index out of range");
|
|
508
|
+
this.len = len;
|
|
467
509
|
return array;
|
|
468
510
|
};
|
|
469
511
|
|
|
@@ -582,9 +624,13 @@ Reader.prototype.doubles = function read_doubles(array) {
|
|
|
582
624
|
*/
|
|
583
625
|
Reader.prototype.uint64s = function read_uint64s(array) {
|
|
584
626
|
if (array === undefined) array = [];
|
|
585
|
-
var end = this.uint32() + this.pos;
|
|
627
|
+
var end = this.uint32() + this.pos, len = this.len;
|
|
628
|
+
if (end > len) throw indexOutOfRange(this, end - this.pos);
|
|
629
|
+
this.len = end;
|
|
586
630
|
while (this.pos < end)
|
|
587
631
|
array.push(this.uint64());
|
|
632
|
+
if (this.pos !== end) throw RangeError("index out of range");
|
|
633
|
+
this.len = len;
|
|
588
634
|
return array;
|
|
589
635
|
};
|
|
590
636
|
|
|
@@ -595,9 +641,13 @@ Reader.prototype.uint64s = function read_uint64s(array) {
|
|
|
595
641
|
*/
|
|
596
642
|
Reader.prototype.int64s = function read_int64s(array) {
|
|
597
643
|
if (array === undefined) array = [];
|
|
598
|
-
var end = this.uint32() + this.pos;
|
|
644
|
+
var end = this.uint32() + this.pos, len = this.len;
|
|
645
|
+
if (end > len) throw indexOutOfRange(this, end - this.pos);
|
|
646
|
+
this.len = end;
|
|
599
647
|
while (this.pos < end)
|
|
600
648
|
array.push(this.int64());
|
|
649
|
+
if (this.pos !== end) throw RangeError("index out of range");
|
|
650
|
+
this.len = len;
|
|
601
651
|
return array;
|
|
602
652
|
};
|
|
603
653
|
|
|
@@ -608,9 +658,13 @@ Reader.prototype.int64s = function read_int64s(array) {
|
|
|
608
658
|
*/
|
|
609
659
|
Reader.prototype.sint64s = function read_sint64s(array) {
|
|
610
660
|
if (array === undefined) array = [];
|
|
611
|
-
var end = this.uint32() + this.pos;
|
|
661
|
+
var end = this.uint32() + this.pos, len = this.len;
|
|
662
|
+
if (end > len) throw indexOutOfRange(this, end - this.pos);
|
|
663
|
+
this.len = end;
|
|
612
664
|
while (this.pos < end)
|
|
613
665
|
array.push(this.sint64());
|
|
666
|
+
if (this.pos !== end) throw RangeError("index out of range");
|
|
667
|
+
this.len = len;
|
|
614
668
|
return array;
|
|
615
669
|
};
|
|
616
670
|
|
package/src/type.js
CHANGED
|
@@ -70,6 +70,12 @@ function Type(name, options) {
|
|
|
70
70
|
*/
|
|
71
71
|
this.group = undefined; // toJSON
|
|
72
72
|
|
|
73
|
+
/**
|
|
74
|
+
* Declared symbol visibility, if any.
|
|
75
|
+
* @type {"local"|"export"|undefined}
|
|
76
|
+
*/
|
|
77
|
+
this.visibility = undefined; // toJSON
|
|
78
|
+
|
|
73
79
|
/**
|
|
74
80
|
* Cached fields by id.
|
|
75
81
|
* @type {Object.<number,Field>|null}
|
|
@@ -254,6 +260,7 @@ function clearCache(type) {
|
|
|
254
260
|
* @property {number[][]} [extensions] Extension ranges
|
|
255
261
|
* @property {Array.<number[]|string>} [reserved] Reserved ranges
|
|
256
262
|
* @property {boolean} [group=false] Whether a legacy group or not
|
|
263
|
+
* @property {"local"|"export"} [visibility] Declared symbol visibility
|
|
257
264
|
* @property {string|null} [comment] Message type comment
|
|
258
265
|
*/
|
|
259
266
|
|
|
@@ -304,6 +311,8 @@ Type.fromJSON = function fromJSON(name, json, depth) {
|
|
|
304
311
|
type.reserved = json.reserved;
|
|
305
312
|
if (json.group)
|
|
306
313
|
type.group = true;
|
|
314
|
+
if (json.visibility)
|
|
315
|
+
type.visibility = json.visibility;
|
|
307
316
|
if (json.comment)
|
|
308
317
|
type.comment = json.comment;
|
|
309
318
|
if (json.edition)
|
|
@@ -328,6 +337,7 @@ Type.prototype.toJSON = function toJSON(toJSONOptions) {
|
|
|
328
337
|
"extensions" , this.extensions && this.extensions.length ? this.extensions : undefined,
|
|
329
338
|
"reserved" , this.reserved && this.reserved.length ? this.reserved : undefined,
|
|
330
339
|
"group" , this.group || undefined,
|
|
340
|
+
"visibility" , this.visibility,
|
|
331
341
|
"nested" , inherited && inherited.nested || undefined,
|
|
332
342
|
"comment" , keepComments ? this.comment : undefined
|
|
333
343
|
]);
|
package/src/wrappers.js
CHANGED
|
@@ -40,6 +40,10 @@ var Message = require("./message"),
|
|
|
40
40
|
wrappers[".google.protobuf.Any"] = {
|
|
41
41
|
|
|
42
42
|
fromObject: function(object, depth) {
|
|
43
|
+
if (depth === undefined)
|
|
44
|
+
depth = 0;
|
|
45
|
+
if (depth > util.recursionLimit)
|
|
46
|
+
throw Error("max depth exceeded");
|
|
43
47
|
|
|
44
48
|
// unwrap value type if mapped
|
|
45
49
|
if (object && object["@type"]) {
|
|
@@ -57,7 +61,7 @@ wrappers[".google.protobuf.Any"] = {
|
|
|
57
61
|
}
|
|
58
62
|
return this.create({
|
|
59
63
|
type_url: type_url,
|
|
60
|
-
value: type.encode(type.fromObject(object, depth
|
|
64
|
+
value: type.encode(type.fromObject(object, depth + 1)).finish()
|
|
61
65
|
});
|
|
62
66
|
}
|
|
63
67
|
}
|