protobufjs 8.2.0 → 8.3.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 +113 -75
- package/dist/light/protobuf.js +119 -55
- 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 +61 -18
- 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 +138 -60
- 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/index.d.ts +2 -1
- package/ext/descriptor.d.ts +11 -234
- package/ext/descriptor.generated.d.ts +409 -0
- package/ext/descriptor.js +96 -66
- package/ext/textformat.d.ts +2 -13
- package/ext/textformat.generated.d.ts +11 -0
- package/ext/textformat.js +28 -42
- package/index.d.ts +304 -275
- package/package.json +4 -7
- package/src/converter.js +3 -3
- package/src/decoder.js +6 -2
- package/src/enum.js +8 -3
- package/src/field.js +2 -0
- package/src/message.js +3 -6
- package/src/method.js +1 -1
- package/src/namespace.js +10 -2
- package/src/object.js +0 -1
- package/src/oneof.js +1 -0
- package/src/parse.js +19 -5
- package/src/root.js +4 -1
- package/src/service.js +6 -1
- package/src/type.js +12 -3
- package/src/typescript.js +19 -0
- package/src/util/minimal.js +8 -1
- package/src/util/utf8.js +39 -13
- package/src/util.js +2 -14
- package/src/writer.js +6 -1
- package/src/writer_buffer.js +6 -1
- package/tsconfig.json +2 -4
- package/src/typescript.jsdoc +0 -15
package/dist/protobuf.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/*!
|
|
2
|
-
* protobuf.js v8.
|
|
3
|
-
* compiled
|
|
2
|
+
* protobuf.js v8.3.0 (c) 2016, daniel wirtz
|
|
3
|
+
* compiled wed, 13 may 2026 21:15:34 utc
|
|
4
4
|
* licensed under the bsd-3-clause license
|
|
5
5
|
* see: https://github.com/dcodeio/protobuf.js for details
|
|
6
6
|
*/
|
|
@@ -550,15 +550,15 @@ converter.fromObject = function fromObject(mtype) {
|
|
|
550
550
|
/* eslint-disable no-unexpected-multiline, block-scoped-var, no-redeclare */
|
|
551
551
|
var fields = mtype.fieldsArray;
|
|
552
552
|
var gen = util.codegen(["d", "q"], mtype.name + "$fromObject")
|
|
553
|
-
("if(d instanceof
|
|
553
|
+
("if(d instanceof C)")
|
|
554
554
|
("return d")
|
|
555
555
|
("if(q===undefined)q=0")
|
|
556
556
|
("if(q>util.recursionLimit)")
|
|
557
557
|
("throw Error(\"max depth exceeded\")");
|
|
558
558
|
if (!fields.length) return gen
|
|
559
|
-
("return new
|
|
559
|
+
("return new C");
|
|
560
560
|
gen
|
|
561
|
-
("var m=new
|
|
561
|
+
("var m=new C");
|
|
562
562
|
for (var i = 0; i < fields.length; ++i) {
|
|
563
563
|
var field = fields[i].resolve(),
|
|
564
564
|
prop = util.safeProp(field.name),
|
|
@@ -814,7 +814,7 @@ function decoder(mtype) {
|
|
|
814
814
|
("if(q===undefined)q=0")
|
|
815
815
|
("if(q>Reader.recursionLimit)")
|
|
816
816
|
("throw Error(\"max depth exceeded\")")
|
|
817
|
-
("var c=l===undefined?r.len:r.pos+l,m=g||new
|
|
817
|
+
("var c=l===undefined?r.len:r.pos+l,m=g||new C" + (hasMapField ? ",k,v" : hasImplicitPresenceField ? ",v" : ""))
|
|
818
818
|
("while(r.pos<c){")
|
|
819
819
|
("var s=r.pos")
|
|
820
820
|
("var t=r.tag()")
|
|
@@ -938,7 +938,11 @@ function decoder(mtype) {
|
|
|
938
938
|
("case %i:{", field.id)
|
|
939
939
|
("if(u!==%i)", types.basic[type])
|
|
940
940
|
("break");
|
|
941
|
-
if (
|
|
941
|
+
if (field.resolvedType instanceof Enum && field.typeDefault !== 0) gen
|
|
942
|
+
// TODO: Protoc rejects open enums whose first value is not zero.
|
|
943
|
+
// We should do the same, but for v8 this would be a regression.
|
|
944
|
+
("if((v=r.%s())!==%j)", type, field.typeDefault);
|
|
945
|
+
else if (type === "string" || type === "bytes") gen
|
|
942
946
|
("if((v=r.%s()).length)", type);
|
|
943
947
|
else if (types.long[type] !== undefined) gen
|
|
944
948
|
("if(typeof(v=r.%s())===\"object\"?v.low||v.high:v!==0)", type);
|
|
@@ -1111,7 +1115,7 @@ var Namespace = require(14),
|
|
|
1111
1115
|
* @param {Object.<string,number>} [values] Enum values as an object, by name
|
|
1112
1116
|
* @param {Object.<string,*>} [options] Declared options
|
|
1113
1117
|
* @param {string} [comment] The comment for this enum
|
|
1114
|
-
* @param {Object.<string,string>} [comments] The value comments for this enum
|
|
1118
|
+
* @param {Object.<string,string|null>} [comments] The value comments for this enum
|
|
1115
1119
|
* @param {Object.<string,Object<string,*>>|undefined} [valuesOptions] The value options for this enum
|
|
1116
1120
|
*/
|
|
1117
1121
|
function Enum(name, values, options, comment, comments, valuesOptions) {
|
|
@@ -1140,7 +1144,7 @@ function Enum(name, values, options, comment, comments, valuesOptions) {
|
|
|
1140
1144
|
|
|
1141
1145
|
/**
|
|
1142
1146
|
* Value comment texts, if any.
|
|
1143
|
-
* @type {Object.<string,string>}
|
|
1147
|
+
* @type {Object.<string,string|null>}
|
|
1144
1148
|
*/
|
|
1145
1149
|
this.comments = comments || {};
|
|
1146
1150
|
|
|
@@ -1190,8 +1194,13 @@ Enum.prototype._resolveFeatures = function _resolveFeatures(edition) {
|
|
|
1190
1194
|
/**
|
|
1191
1195
|
* Enum descriptor.
|
|
1192
1196
|
* @interface IEnum
|
|
1197
|
+
* @property {string} [edition] Edition
|
|
1193
1198
|
* @property {Object.<string,number>} values Enum values
|
|
1194
1199
|
* @property {Object.<string,*>} [options] Enum options
|
|
1200
|
+
* @property {Object.<string,Object.<string,*>>} [valuesOptions] Enum value options
|
|
1201
|
+
* @property {Array.<number[]|string>} [reserved] Reserved ranges
|
|
1202
|
+
* @property {string|null} [comment] Enum comment
|
|
1203
|
+
* @property {Object.<string,string|null>} [comments] Value comments
|
|
1195
1204
|
*/
|
|
1196
1205
|
|
|
1197
1206
|
/**
|
|
@@ -1202,7 +1211,7 @@ Enum.prototype._resolveFeatures = function _resolveFeatures(edition) {
|
|
|
1202
1211
|
* @throws {TypeError} If arguments are invalid
|
|
1203
1212
|
*/
|
|
1204
1213
|
Enum.fromJSON = function fromJSON(name, json) {
|
|
1205
|
-
var enm = new Enum(name, json.values, json.options, json.comment, json.comments);
|
|
1214
|
+
var enm = new Enum(name, json.values, json.options, json.comment, json.comments, json.valuesOptions);
|
|
1206
1215
|
enm.reserved = json.reserved;
|
|
1207
1216
|
if (json.edition)
|
|
1208
1217
|
enm._edition = json.edition;
|
|
@@ -1581,10 +1590,12 @@ Field.prototype.setOption = function setOption(name, value, ifNotSet) {
|
|
|
1581
1590
|
/**
|
|
1582
1591
|
* Field descriptor.
|
|
1583
1592
|
* @interface IField
|
|
1593
|
+
* @property {string} [edition] Edition
|
|
1584
1594
|
* @property {string} [rule="optional"] Field rule
|
|
1585
1595
|
* @property {string} type Field type
|
|
1586
1596
|
* @property {number} id Field id
|
|
1587
1597
|
* @property {Object.<string,*>} [options] Field options
|
|
1598
|
+
* @property {string|null} [comment] Field comment
|
|
1588
1599
|
*/
|
|
1589
1600
|
|
|
1590
1601
|
/**
|
|
@@ -2081,12 +2092,9 @@ var util = require(38);
|
|
|
2081
2092
|
function Message(properties) {
|
|
2082
2093
|
// not used internally
|
|
2083
2094
|
if (properties)
|
|
2084
|
-
for (var keys = Object.keys(properties), i = 0; i < keys.length; ++i)
|
|
2085
|
-
|
|
2086
|
-
|
|
2087
|
-
continue;
|
|
2088
|
-
this[key] = properties[key];
|
|
2089
|
-
}
|
|
2095
|
+
for (var keys = Object.keys(properties), i = 0; i < keys.length; ++i)
|
|
2096
|
+
if (properties[keys[i]] != null && keys[i] !== "__proto__")
|
|
2097
|
+
this[keys[i]] = properties[keys[i]];
|
|
2090
2098
|
}
|
|
2091
2099
|
|
|
2092
2100
|
/**
|
|
@@ -2320,7 +2328,7 @@ function Method(name, type, requestType, responseType, requestStream, responseSt
|
|
|
2320
2328
|
* @property {boolean} [requestStream=false] Whether requests are streamed
|
|
2321
2329
|
* @property {boolean} [responseStream=false] Whether responses are streamed
|
|
2322
2330
|
* @property {Object.<string,*>} [options] Method options
|
|
2323
|
-
* @property {string} comment Method
|
|
2331
|
+
* @property {string|null} [comment] Method comment
|
|
2324
2332
|
* @property {Array.<Object.<string,*>>} [parsedOptions] Method options properly parsed into objects
|
|
2325
2333
|
*/
|
|
2326
2334
|
|
|
@@ -2406,7 +2414,10 @@ var Type, // cyclic
|
|
|
2406
2414
|
* @throws {TypeError} If arguments are invalid
|
|
2407
2415
|
*/
|
|
2408
2416
|
Namespace.fromJSON = function fromJSON(name, json, depth) {
|
|
2409
|
-
depth
|
|
2417
|
+
if (depth === undefined)
|
|
2418
|
+
depth = 0;
|
|
2419
|
+
if (depth > util.recursionLimit)
|
|
2420
|
+
throw Error("max depth exceeded");
|
|
2410
2421
|
return new Namespace(name, json.options).addJSON(json.nested, depth);
|
|
2411
2422
|
};
|
|
2412
2423
|
|
|
@@ -2569,7 +2580,10 @@ Namespace.prototype.toJSON = function toJSON(toJSONOptions) {
|
|
|
2569
2580
|
* @returns {Namespace} `this`
|
|
2570
2581
|
*/
|
|
2571
2582
|
Namespace.prototype.addJSON = function addJSON(nestedJson, depth) {
|
|
2572
|
-
depth
|
|
2583
|
+
if (depth === undefined)
|
|
2584
|
+
depth = 0;
|
|
2585
|
+
if (depth > util.recursionLimit)
|
|
2586
|
+
throw Error("max depth exceeded");
|
|
2573
2587
|
var ns = this;
|
|
2574
2588
|
/* istanbul ignore else */
|
|
2575
2589
|
if (nestedJson) {
|
|
@@ -2709,6 +2723,8 @@ Namespace.prototype.define = function define(path, json) {
|
|
|
2709
2723
|
throw TypeError("illegal path");
|
|
2710
2724
|
if (path && path.length && path[0] === "")
|
|
2711
2725
|
throw Error("path must be relative");
|
|
2726
|
+
if (path.length > util.recursionLimit)
|
|
2727
|
+
throw Error("max depth exceeded");
|
|
2712
2728
|
|
|
2713
2729
|
var ptr = this;
|
|
2714
2730
|
while (path.length > 0) {
|
|
@@ -3073,7 +3089,6 @@ Object.defineProperties(ReflectionObject.prototype, {
|
|
|
3073
3089
|
/**
|
|
3074
3090
|
* Converts this reflection object to its descriptor representation.
|
|
3075
3091
|
* @returns {Object.<string,*>} Descriptor
|
|
3076
|
-
* @abstract
|
|
3077
3092
|
*/
|
|
3078
3093
|
ReflectionObject.prototype.toJSON = /* istanbul ignore next */ function toJSON() {
|
|
3079
3094
|
throw Error(); // not implemented, shouldn't happen
|
|
@@ -3370,6 +3385,7 @@ function OneOf(name, fieldNames, options, comment) {
|
|
|
3370
3385
|
* @interface IOneOf
|
|
3371
3386
|
* @property {Array.<string>} oneof Oneof field names
|
|
3372
3387
|
* @property {Object.<string,*>} [options] Oneof options
|
|
3388
|
+
* @property {string|null} [comment] Oneof comment
|
|
3373
3389
|
*/
|
|
3374
3390
|
|
|
3375
3391
|
/**
|
|
@@ -3854,7 +3870,9 @@ function parse(source, root, options) {
|
|
|
3854
3870
|
|
|
3855
3871
|
|
|
3856
3872
|
function parseCommon(parent, token, depth) {
|
|
3857
|
-
depth
|
|
3873
|
+
if (depth === undefined)
|
|
3874
|
+
depth = 0;
|
|
3875
|
+
// depth is checked by dispatched functions
|
|
3858
3876
|
switch (token) {
|
|
3859
3877
|
|
|
3860
3878
|
case "option":
|
|
@@ -3920,7 +3938,10 @@ function parse(source, root, options) {
|
|
|
3920
3938
|
}
|
|
3921
3939
|
|
|
3922
3940
|
function parseType(parent, token, depth) {
|
|
3923
|
-
depth
|
|
3941
|
+
if (depth === undefined)
|
|
3942
|
+
depth = 0;
|
|
3943
|
+
if (depth > util.nestingLimit)
|
|
3944
|
+
throw Error("max depth exceeded");
|
|
3924
3945
|
|
|
3925
3946
|
/* istanbul ignore if */
|
|
3926
3947
|
if (!nameRe.test(token = next()))
|
|
@@ -4049,7 +4070,10 @@ function parse(source, root, options) {
|
|
|
4049
4070
|
}
|
|
4050
4071
|
|
|
4051
4072
|
function parseGroup(parent, rule, extend, depth) {
|
|
4052
|
-
depth
|
|
4073
|
+
if (depth === undefined)
|
|
4074
|
+
depth = 0;
|
|
4075
|
+
if (depth > util.nestingLimit)
|
|
4076
|
+
throw Error("max depth exceeded");
|
|
4053
4077
|
if (edition >= 2023) {
|
|
4054
4078
|
throw illegal("group");
|
|
4055
4079
|
}
|
|
@@ -4296,7 +4320,10 @@ function parse(source, root, options) {
|
|
|
4296
4320
|
}
|
|
4297
4321
|
|
|
4298
4322
|
function parseOptionValue(parent, name, depth) {
|
|
4299
|
-
depth
|
|
4323
|
+
if (depth === undefined)
|
|
4324
|
+
depth = 0;
|
|
4325
|
+
if (depth > util.recursionLimit)
|
|
4326
|
+
throw Error("max depth exceeded");
|
|
4300
4327
|
// { a: "foo" b { c: "bar" } }
|
|
4301
4328
|
if (skip("{", true)) {
|
|
4302
4329
|
var objectResult = {};
|
|
@@ -4387,7 +4414,10 @@ function parse(source, root, options) {
|
|
|
4387
4414
|
}
|
|
4388
4415
|
|
|
4389
4416
|
function parseService(parent, token, depth) {
|
|
4390
|
-
depth
|
|
4417
|
+
if (depth === undefined)
|
|
4418
|
+
depth = 0;
|
|
4419
|
+
if (depth > util.recursionLimit)
|
|
4420
|
+
throw Error("max depth exceeded");
|
|
4391
4421
|
|
|
4392
4422
|
/* istanbul ignore if */
|
|
4393
4423
|
if (!nameRe.test(token = next()))
|
|
@@ -5247,7 +5277,10 @@ function Root(options) {
|
|
|
5247
5277
|
* @returns {Root} Root namespace
|
|
5248
5278
|
*/
|
|
5249
5279
|
Root.fromJSON = function fromJSON(json, root, depth) {
|
|
5250
|
-
depth
|
|
5280
|
+
if (depth === undefined)
|
|
5281
|
+
depth = 0;
|
|
5282
|
+
if (depth > util.recursionLimit)
|
|
5283
|
+
throw Error("max depth exceeded");
|
|
5251
5284
|
if (!root)
|
|
5252
5285
|
root = new Root();
|
|
5253
5286
|
if (json.options)
|
|
@@ -5840,7 +5873,9 @@ function Service(name, options) {
|
|
|
5840
5873
|
* Service descriptor.
|
|
5841
5874
|
* @interface IService
|
|
5842
5875
|
* @extends INamespace
|
|
5876
|
+
* @property {string} [edition] Edition
|
|
5843
5877
|
* @property {Object.<string,IMethod>} methods Method descriptors
|
|
5878
|
+
* @property {string|null} [comment] Service comment
|
|
5844
5879
|
*/
|
|
5845
5880
|
|
|
5846
5881
|
/**
|
|
@@ -5852,7 +5887,10 @@ function Service(name, options) {
|
|
|
5852
5887
|
* @throws {TypeError} If arguments are invalid
|
|
5853
5888
|
*/
|
|
5854
5889
|
Service.fromJSON = function fromJSON(name, json, depth) {
|
|
5855
|
-
depth
|
|
5890
|
+
if (depth === undefined)
|
|
5891
|
+
depth = 0;
|
|
5892
|
+
if (depth > util.recursionLimit)
|
|
5893
|
+
throw Error("max depth exceeded");
|
|
5856
5894
|
var service = new Service(name, json.options);
|
|
5857
5895
|
/* istanbul ignore else */
|
|
5858
5896
|
if (json.methods)
|
|
@@ -6590,6 +6628,8 @@ Object.defineProperties(Type.prototype, {
|
|
|
6590
6628
|
util.merge(ctor, Message, true);
|
|
6591
6629
|
|
|
6592
6630
|
this._ctor = ctor;
|
|
6631
|
+
delete this.decode;
|
|
6632
|
+
delete this.fromObject;
|
|
6593
6633
|
|
|
6594
6634
|
// Messages have non-enumerable default values on their prototype
|
|
6595
6635
|
var i = 0;
|
|
@@ -6643,11 +6683,13 @@ function clearCache(type) {
|
|
|
6643
6683
|
* Message type descriptor.
|
|
6644
6684
|
* @interface IType
|
|
6645
6685
|
* @extends INamespace
|
|
6686
|
+
* @property {string} [edition] Edition
|
|
6646
6687
|
* @property {Object.<string,IOneOf>} [oneofs] Oneof descriptors
|
|
6647
6688
|
* @property {Object.<string,IField>} fields Field descriptors
|
|
6648
6689
|
* @property {number[][]} [extensions] Extension ranges
|
|
6649
6690
|
* @property {Array.<number[]|string>} [reserved] Reserved ranges
|
|
6650
6691
|
* @property {boolean} [group=false] Whether a legacy group or not
|
|
6692
|
+
* @property {string|null} [comment] Message type comment
|
|
6651
6693
|
*/
|
|
6652
6694
|
|
|
6653
6695
|
/**
|
|
@@ -6658,7 +6700,10 @@ function clearCache(type) {
|
|
|
6658
6700
|
* @returns {Type} Created message type
|
|
6659
6701
|
*/
|
|
6660
6702
|
Type.fromJSON = function fromJSON(name, json, depth) {
|
|
6661
|
-
depth
|
|
6703
|
+
if (depth === undefined)
|
|
6704
|
+
depth = 0;
|
|
6705
|
+
if (depth > util.nestingLimit)
|
|
6706
|
+
throw Error("max depth exceeded");
|
|
6662
6707
|
var type = new Type(name, json.options);
|
|
6663
6708
|
type.extensions = json.extensions;
|
|
6664
6709
|
type.reserved = json.reserved;
|
|
@@ -6898,7 +6943,8 @@ Type.prototype.setup = function setup() {
|
|
|
6898
6943
|
this.decode = decoder(this)({
|
|
6899
6944
|
Reader : Reader,
|
|
6900
6945
|
types : types,
|
|
6901
|
-
util : util
|
|
6946
|
+
util : util,
|
|
6947
|
+
C : this.ctor
|
|
6902
6948
|
});
|
|
6903
6949
|
this.verify = verifier(this)({
|
|
6904
6950
|
types : types,
|
|
@@ -6906,7 +6952,8 @@ Type.prototype.setup = function setup() {
|
|
|
6906
6952
|
});
|
|
6907
6953
|
this.fromObject = converter.fromObject(this)({
|
|
6908
6954
|
types : types,
|
|
6909
|
-
util : util
|
|
6955
|
+
util : util,
|
|
6956
|
+
C : this.ctor
|
|
6910
6957
|
});
|
|
6911
6958
|
this.toObject = converter.toObject(this)({
|
|
6912
6959
|
types : types,
|
|
@@ -7281,20 +7328,6 @@ var reservedRe = util.patterns.reservedRe,
|
|
|
7281
7328
|
*/
|
|
7282
7329
|
util.fs = require(35);
|
|
7283
7330
|
|
|
7284
|
-
/**
|
|
7285
|
-
* Checks a recursion depth.
|
|
7286
|
-
* @param {number|undefined} depth Depth of recursion
|
|
7287
|
-
* @returns {number} Depth of recursion
|
|
7288
|
-
* @throws {Error} If depth exceeds util.recursionLimit
|
|
7289
|
-
*/
|
|
7290
|
-
util.checkDepth = function checkDepth(depth) {
|
|
7291
|
-
if (depth === undefined)
|
|
7292
|
-
depth = 0;
|
|
7293
|
-
if (depth > util.recursionLimit)
|
|
7294
|
-
throw Error("max depth exceeded");
|
|
7295
|
-
return depth;
|
|
7296
|
-
};
|
|
7297
|
-
|
|
7298
7331
|
/**
|
|
7299
7332
|
* Converts an object's values to an array.
|
|
7300
7333
|
* @param {Object.<string,*>} object Object to convert
|
|
@@ -7471,6 +7504,8 @@ util.setProperty = function setProperty(dst, path, value, ifNotSet) {
|
|
|
7471
7504
|
throw TypeError("path must be specified");
|
|
7472
7505
|
|
|
7473
7506
|
path = path.split(".");
|
|
7507
|
+
if (path.length > util.recursionLimit)
|
|
7508
|
+
throw Error("max depth exceeded");
|
|
7474
7509
|
return setProp(dst, path, value);
|
|
7475
7510
|
};
|
|
7476
7511
|
|
|
@@ -8872,12 +8907,19 @@ function merge(dst, src, ifNotSet) { // used by converters
|
|
|
8872
8907
|
|
|
8873
8908
|
util.merge = merge;
|
|
8874
8909
|
|
|
8910
|
+
/**
|
|
8911
|
+
* Schema declaration nesting limit.
|
|
8912
|
+
* @memberof util
|
|
8913
|
+
* @type {number}
|
|
8914
|
+
*/
|
|
8915
|
+
util.nestingLimit = 32; // protoc: MaxMessageDeclarationNestingDepth
|
|
8916
|
+
|
|
8875
8917
|
/**
|
|
8876
8918
|
* Recursion limit.
|
|
8877
8919
|
* @memberof util
|
|
8878
8920
|
* @type {number}
|
|
8879
8921
|
*/
|
|
8880
|
-
util.recursionLimit = 100;
|
|
8922
|
+
util.recursionLimit = 100; // protoc: CodedInputStream::default_recursion_limit_
|
|
8881
8923
|
|
|
8882
8924
|
/**
|
|
8883
8925
|
* Makes a property safe for assignment as an own property.
|
|
@@ -9259,19 +9301,7 @@ utf8.length = function utf8_length(string) {
|
|
|
9259
9301
|
return len;
|
|
9260
9302
|
};
|
|
9261
9303
|
|
|
9262
|
-
|
|
9263
|
-
* Reads UTF8 bytes as a string.
|
|
9264
|
-
* @param {Uint8Array} buffer Source buffer
|
|
9265
|
-
* @param {number} start Source start
|
|
9266
|
-
* @param {number} end Source end
|
|
9267
|
-
* @returns {string} String read
|
|
9268
|
-
*/
|
|
9269
|
-
utf8.read = function utf8_read(buffer, start, end) {
|
|
9270
|
-
if (end - start < 1) {
|
|
9271
|
-
return "";
|
|
9272
|
-
}
|
|
9273
|
-
|
|
9274
|
-
var str = "";
|
|
9304
|
+
function utf8_read_js(buffer, start, end, str) {
|
|
9275
9305
|
for (var i = start; i < end;) {
|
|
9276
9306
|
var t = buffer[i++];
|
|
9277
9307
|
if (t <= 0x7F) {
|
|
@@ -9293,6 +9323,44 @@ utf8.read = function utf8_read(buffer, start, end) {
|
|
|
9293
9323
|
}
|
|
9294
9324
|
}
|
|
9295
9325
|
}
|
|
9326
|
+
return str;
|
|
9327
|
+
}
|
|
9328
|
+
|
|
9329
|
+
/**
|
|
9330
|
+
* Reads UTF8 bytes as a string.
|
|
9331
|
+
* @param {Uint8Array} buffer Source buffer
|
|
9332
|
+
* @param {number} start Source start
|
|
9333
|
+
* @param {number} end Source end
|
|
9334
|
+
* @returns {string} String read
|
|
9335
|
+
*/
|
|
9336
|
+
utf8.read = function utf8_read_ascii(buffer, start, end) {
|
|
9337
|
+
if (end - start < 1)
|
|
9338
|
+
return "";
|
|
9339
|
+
|
|
9340
|
+
var str = "",
|
|
9341
|
+
i = start,
|
|
9342
|
+
c1, c2, c3, c4, c5, c6, c7, c8;
|
|
9343
|
+
|
|
9344
|
+
for (; i + 7 < end; i += 8) {
|
|
9345
|
+
c1 = buffer[i];
|
|
9346
|
+
c2 = buffer[i + 1];
|
|
9347
|
+
c3 = buffer[i + 2];
|
|
9348
|
+
c4 = buffer[i + 3];
|
|
9349
|
+
c5 = buffer[i + 4];
|
|
9350
|
+
c6 = buffer[i + 5];
|
|
9351
|
+
c7 = buffer[i + 6];
|
|
9352
|
+
c8 = buffer[i + 7];
|
|
9353
|
+
if ((c1 | c2 | c3 | c4 | c5 | c6 | c7 | c8) & 0x80)
|
|
9354
|
+
return utf8_read_js(buffer, i, end, str);
|
|
9355
|
+
str += String.fromCharCode(c1, c2, c3, c4, c5, c6, c7, c8);
|
|
9356
|
+
}
|
|
9357
|
+
|
|
9358
|
+
for (; i < end; ++i) {
|
|
9359
|
+
c1 = buffer[i];
|
|
9360
|
+
if (c1 & 0x80)
|
|
9361
|
+
return utf8_read_js(buffer, i, end, str);
|
|
9362
|
+
str += String.fromCharCode(c1);
|
|
9363
|
+
}
|
|
9296
9364
|
|
|
9297
9365
|
return str;
|
|
9298
9366
|
};
|
|
@@ -9794,6 +9862,11 @@ function writeByte(val, buf, pos) {
|
|
|
9794
9862
|
buf[pos] = val & 255;
|
|
9795
9863
|
}
|
|
9796
9864
|
|
|
9865
|
+
function writeStringAscii(val, buf, pos) {
|
|
9866
|
+
for (var i = 0; i < val.length;)
|
|
9867
|
+
buf[pos++] = val.charCodeAt(i++);
|
|
9868
|
+
}
|
|
9869
|
+
|
|
9797
9870
|
function writeVarint32(val, buf, pos) {
|
|
9798
9871
|
while (val > 127) {
|
|
9799
9872
|
buf[pos++] = val & 127 | 128;
|
|
@@ -10022,7 +10095,7 @@ Writer.prototype.raw = function write_raw(value) {
|
|
|
10022
10095
|
Writer.prototype.string = function write_string(value) {
|
|
10023
10096
|
var len = utf8.length(value);
|
|
10024
10097
|
return len
|
|
10025
|
-
? this.uint32(len)._push(utf8.write, len, value)
|
|
10098
|
+
? this.uint32(len)._push(len === value.length ? writeStringAscii : utf8.write, len, value)
|
|
10026
10099
|
: this._push(writeByte, 1, 0);
|
|
10027
10100
|
};
|
|
10028
10101
|
|
|
@@ -10177,6 +10250,11 @@ BufferWriter.prototype.raw = function write_raw_buffer(value) {
|
|
|
10177
10250
|
return len ? this._push(BufferWriter.writeBytesBuffer, len, value) : this;
|
|
10178
10251
|
};
|
|
10179
10252
|
|
|
10253
|
+
function writeStringBufferAscii(val, buf, pos) {
|
|
10254
|
+
for (var i = 0; i < val.length;)
|
|
10255
|
+
buf[pos++] = val.charCodeAt(i++);
|
|
10256
|
+
}
|
|
10257
|
+
|
|
10180
10258
|
function writeStringBuffer(val, buf, pos) {
|
|
10181
10259
|
if (val.length < 40) // plain js is faster for short strings (probably due to redundant assertions)
|
|
10182
10260
|
util.utf8.write(val, buf, pos);
|
|
@@ -10193,7 +10271,7 @@ BufferWriter.prototype.string = function write_string_buffer(value) {
|
|
|
10193
10271
|
var len = util.Buffer.byteLength(value);
|
|
10194
10272
|
this.uint32(len);
|
|
10195
10273
|
if (len)
|
|
10196
|
-
this._push(writeStringBuffer, len, value);
|
|
10274
|
+
this._push(len === value.length && len < 40 ? writeStringBufferAscii : writeStringBuffer, len, value);
|
|
10197
10275
|
return this;
|
|
10198
10276
|
};
|
|
10199
10277
|
|