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/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "protobufjs",
|
|
3
|
-
"version": "8.
|
|
3
|
+
"version": "8.3.0",
|
|
4
4
|
"versionScheme": "~",
|
|
5
5
|
"description": "Protocol Buffers for JavaScript & TypeScript.",
|
|
6
6
|
"author": "Daniel Wirtz <dcode+protobufjs@dcode.io>",
|
|
@@ -26,7 +26,7 @@
|
|
|
26
26
|
"bench": "node bench",
|
|
27
27
|
"build": "npm run build:bundle && npm run build:types",
|
|
28
28
|
"build:bundle": "gulp --gulpfile scripts/gulpfile.js",
|
|
29
|
-
"build:types": "node cli/bin/pbts --main --global protobuf --out index.d.ts src/",
|
|
29
|
+
"build:types": "node cli/bin/pbts --main --global protobuf --out index.d.ts src/ && node cli/bin/pbts --main --import \"\\$protobuf=..\" --out ext/descriptor.generated.d.ts ext/descriptor.js && node cli/bin/pbts --main --out ext/textformat.generated.d.ts ext/textformat.js",
|
|
30
30
|
"coverage": "npm run coverage:test && npm run coverage:report",
|
|
31
31
|
"coverage:test": "nyc --silent tape -r ./lib/tape-adapter tests/*.js tests/node/*.js",
|
|
32
32
|
"coverage:report": "nyc report --reporter=lcov --reporter=text",
|
|
@@ -42,20 +42,18 @@
|
|
|
42
42
|
"prof": "node bench/prof",
|
|
43
43
|
"test": "npm run test:sources && npm run test:types",
|
|
44
44
|
"test:sources": "tape -r ./lib/tape-adapter tests/*.js tests/node/*.js",
|
|
45
|
-
"test:types": "tsc tests/comp_typescript.ts --
|
|
45
|
+
"test:types": "tsc tests/comp_typescript.ts --target es2019 --module commonjs --types node --lib es2019 --esModuleInterop --strictNullChecks --experimentalDecorators --emitDecoratorMetadata && tsc -p tsconfig.test-types.json",
|
|
46
46
|
"make": "npm run lint:sources && npm run build && npm run lint:types && node ./scripts/gentests.js && npm test"
|
|
47
47
|
},
|
|
48
48
|
"dependencies": {
|
|
49
|
-
"@types/node": ">=13.7.0",
|
|
50
49
|
"long": "^5.0.0"
|
|
51
50
|
},
|
|
52
51
|
"devDependencies": {
|
|
53
52
|
"@eslint/js": "^10.0.0",
|
|
54
|
-
"
|
|
53
|
+
"@types/node": ">=13.7.0",
|
|
55
54
|
"browserify": "^17.0.0",
|
|
56
55
|
"browserify-wrap": "^1.0.2",
|
|
57
56
|
"bundle-collapser": "^1.3.0",
|
|
58
|
-
"chalk": "^4.0.0",
|
|
59
57
|
"escodegen": "^1.13.0",
|
|
60
58
|
"eslint": "^10.0.0",
|
|
61
59
|
"eslint-plugin-jsdoc": "^62.9.0",
|
|
@@ -63,7 +61,6 @@
|
|
|
63
61
|
"estraverse": "^5.1.0",
|
|
64
62
|
"gh-pages": "^6.0.0",
|
|
65
63
|
"globals": "^17.0.0",
|
|
66
|
-
"google-protobuf": "^4.0.0",
|
|
67
64
|
"gulp": "^5.0.0",
|
|
68
65
|
"gulp-header": "^2.0.9",
|
|
69
66
|
"gulp-if": "^3.0.0",
|
package/src/converter.js
CHANGED
|
@@ -107,15 +107,15 @@ converter.fromObject = function fromObject(mtype) {
|
|
|
107
107
|
/* eslint-disable no-unexpected-multiline, block-scoped-var, no-redeclare */
|
|
108
108
|
var fields = mtype.fieldsArray;
|
|
109
109
|
var gen = util.codegen(["d", "q"], mtype.name + "$fromObject")
|
|
110
|
-
("if(d instanceof
|
|
110
|
+
("if(d instanceof C)")
|
|
111
111
|
("return d")
|
|
112
112
|
("if(q===undefined)q=0")
|
|
113
113
|
("if(q>util.recursionLimit)")
|
|
114
114
|
("throw Error(\"max depth exceeded\")");
|
|
115
115
|
if (!fields.length) return gen
|
|
116
|
-
("return new
|
|
116
|
+
("return new C");
|
|
117
117
|
gen
|
|
118
|
-
("var m=new
|
|
118
|
+
("var m=new C");
|
|
119
119
|
for (var i = 0; i < fields.length; ++i) {
|
|
120
120
|
var field = fields[i].resolve(),
|
|
121
121
|
prop = util.safeProp(field.name),
|
package/src/decoder.js
CHANGED
|
@@ -32,7 +32,7 @@ function decoder(mtype) {
|
|
|
32
32
|
("if(q===undefined)q=0")
|
|
33
33
|
("if(q>Reader.recursionLimit)")
|
|
34
34
|
("throw Error(\"max depth exceeded\")")
|
|
35
|
-
("var c=l===undefined?r.len:r.pos+l,m=g||new
|
|
35
|
+
("var c=l===undefined?r.len:r.pos+l,m=g||new C" + (hasMapField ? ",k,v" : hasImplicitPresenceField ? ",v" : ""))
|
|
36
36
|
("while(r.pos<c){")
|
|
37
37
|
("var s=r.pos")
|
|
38
38
|
("var t=r.tag()")
|
|
@@ -156,7 +156,11 @@ function decoder(mtype) {
|
|
|
156
156
|
("case %i:{", field.id)
|
|
157
157
|
("if(u!==%i)", types.basic[type])
|
|
158
158
|
("break");
|
|
159
|
-
if (
|
|
159
|
+
if (field.resolvedType instanceof Enum && field.typeDefault !== 0) gen
|
|
160
|
+
// TODO: Protoc rejects open enums whose first value is not zero.
|
|
161
|
+
// We should do the same, but for v8 this would be a regression.
|
|
162
|
+
("if((v=r.%s())!==%j)", type, field.typeDefault);
|
|
163
|
+
else if (type === "string" || type === "bytes") gen
|
|
160
164
|
("if((v=r.%s()).length)", type);
|
|
161
165
|
else if (types.long[type] !== undefined) gen
|
|
162
166
|
("if(typeof(v=r.%s())===\"object\"?v.low||v.high:v!==0)", type);
|
package/src/enum.js
CHANGED
|
@@ -17,7 +17,7 @@ var Namespace = require("./namespace"),
|
|
|
17
17
|
* @param {Object.<string,number>} [values] Enum values as an object, by name
|
|
18
18
|
* @param {Object.<string,*>} [options] Declared options
|
|
19
19
|
* @param {string} [comment] The comment for this enum
|
|
20
|
-
* @param {Object.<string,string>} [comments] The value comments for this enum
|
|
20
|
+
* @param {Object.<string,string|null>} [comments] The value comments for this enum
|
|
21
21
|
* @param {Object.<string,Object<string,*>>|undefined} [valuesOptions] The value options for this enum
|
|
22
22
|
*/
|
|
23
23
|
function Enum(name, values, options, comment, comments, valuesOptions) {
|
|
@@ -46,7 +46,7 @@ function Enum(name, values, options, comment, comments, valuesOptions) {
|
|
|
46
46
|
|
|
47
47
|
/**
|
|
48
48
|
* Value comment texts, if any.
|
|
49
|
-
* @type {Object.<string,string>}
|
|
49
|
+
* @type {Object.<string,string|null>}
|
|
50
50
|
*/
|
|
51
51
|
this.comments = comments || {};
|
|
52
52
|
|
|
@@ -96,8 +96,13 @@ Enum.prototype._resolveFeatures = function _resolveFeatures(edition) {
|
|
|
96
96
|
/**
|
|
97
97
|
* Enum descriptor.
|
|
98
98
|
* @interface IEnum
|
|
99
|
+
* @property {string} [edition] Edition
|
|
99
100
|
* @property {Object.<string,number>} values Enum values
|
|
100
101
|
* @property {Object.<string,*>} [options] Enum options
|
|
102
|
+
* @property {Object.<string,Object.<string,*>>} [valuesOptions] Enum value options
|
|
103
|
+
* @property {Array.<number[]|string>} [reserved] Reserved ranges
|
|
104
|
+
* @property {string|null} [comment] Enum comment
|
|
105
|
+
* @property {Object.<string,string|null>} [comments] Value comments
|
|
101
106
|
*/
|
|
102
107
|
|
|
103
108
|
/**
|
|
@@ -108,7 +113,7 @@ Enum.prototype._resolveFeatures = function _resolveFeatures(edition) {
|
|
|
108
113
|
* @throws {TypeError} If arguments are invalid
|
|
109
114
|
*/
|
|
110
115
|
Enum.fromJSON = function fromJSON(name, json) {
|
|
111
|
-
var enm = new Enum(name, json.values, json.options, json.comment, json.comments);
|
|
116
|
+
var enm = new Enum(name, json.values, json.options, json.comment, json.comments, json.valuesOptions);
|
|
112
117
|
enm.reserved = json.reserved;
|
|
113
118
|
if (json.edition)
|
|
114
119
|
enm._edition = json.edition;
|
package/src/field.js
CHANGED
|
@@ -259,10 +259,12 @@ Field.prototype.setOption = function setOption(name, value, ifNotSet) {
|
|
|
259
259
|
/**
|
|
260
260
|
* Field descriptor.
|
|
261
261
|
* @interface IField
|
|
262
|
+
* @property {string} [edition] Edition
|
|
262
263
|
* @property {string} [rule="optional"] Field rule
|
|
263
264
|
* @property {string} type Field type
|
|
264
265
|
* @property {number} id Field id
|
|
265
266
|
* @property {Object.<string,*>} [options] Field options
|
|
267
|
+
* @property {string|null} [comment] Field comment
|
|
266
268
|
*/
|
|
267
269
|
|
|
268
270
|
/**
|
package/src/message.js
CHANGED
|
@@ -14,12 +14,9 @@ var util = require("./util/minimal");
|
|
|
14
14
|
function Message(properties) {
|
|
15
15
|
// not used internally
|
|
16
16
|
if (properties)
|
|
17
|
-
for (var keys = Object.keys(properties), i = 0; i < keys.length; ++i)
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
continue;
|
|
21
|
-
this[key] = properties[key];
|
|
22
|
-
}
|
|
17
|
+
for (var keys = Object.keys(properties), i = 0; i < keys.length; ++i)
|
|
18
|
+
if (properties[keys[i]] != null && keys[i] !== "__proto__")
|
|
19
|
+
this[keys[i]] = properties[keys[i]];
|
|
23
20
|
}
|
|
24
21
|
|
|
25
22
|
/**
|
package/src/method.js
CHANGED
|
@@ -111,7 +111,7 @@ function Method(name, type, requestType, responseType, requestStream, responseSt
|
|
|
111
111
|
* @property {boolean} [requestStream=false] Whether requests are streamed
|
|
112
112
|
* @property {boolean} [responseStream=false] Whether responses are streamed
|
|
113
113
|
* @property {Object.<string,*>} [options] Method options
|
|
114
|
-
* @property {string} comment Method
|
|
114
|
+
* @property {string|null} [comment] Method comment
|
|
115
115
|
* @property {Array.<Object.<string,*>>} [parsedOptions] Method options properly parsed into objects
|
|
116
116
|
*/
|
|
117
117
|
|
package/src/namespace.js
CHANGED
|
@@ -34,7 +34,10 @@ var Type, // cyclic
|
|
|
34
34
|
* @throws {TypeError} If arguments are invalid
|
|
35
35
|
*/
|
|
36
36
|
Namespace.fromJSON = function fromJSON(name, json, depth) {
|
|
37
|
-
depth
|
|
37
|
+
if (depth === undefined)
|
|
38
|
+
depth = 0;
|
|
39
|
+
if (depth > util.recursionLimit)
|
|
40
|
+
throw Error("max depth exceeded");
|
|
38
41
|
return new Namespace(name, json.options).addJSON(json.nested, depth);
|
|
39
42
|
};
|
|
40
43
|
|
|
@@ -197,7 +200,10 @@ Namespace.prototype.toJSON = function toJSON(toJSONOptions) {
|
|
|
197
200
|
* @returns {Namespace} `this`
|
|
198
201
|
*/
|
|
199
202
|
Namespace.prototype.addJSON = function addJSON(nestedJson, depth) {
|
|
200
|
-
depth
|
|
203
|
+
if (depth === undefined)
|
|
204
|
+
depth = 0;
|
|
205
|
+
if (depth > util.recursionLimit)
|
|
206
|
+
throw Error("max depth exceeded");
|
|
201
207
|
var ns = this;
|
|
202
208
|
/* istanbul ignore else */
|
|
203
209
|
if (nestedJson) {
|
|
@@ -337,6 +343,8 @@ Namespace.prototype.define = function define(path, json) {
|
|
|
337
343
|
throw TypeError("illegal path");
|
|
338
344
|
if (path && path.length && path[0] === "")
|
|
339
345
|
throw Error("path must be relative");
|
|
346
|
+
if (path.length > util.recursionLimit)
|
|
347
|
+
throw Error("max depth exceeded");
|
|
340
348
|
|
|
341
349
|
var ptr = this;
|
|
342
350
|
while (path.length > 0) {
|
package/src/object.js
CHANGED
|
@@ -142,7 +142,6 @@ Object.defineProperties(ReflectionObject.prototype, {
|
|
|
142
142
|
/**
|
|
143
143
|
* Converts this reflection object to its descriptor representation.
|
|
144
144
|
* @returns {Object.<string,*>} Descriptor
|
|
145
|
-
* @abstract
|
|
146
145
|
*/
|
|
147
146
|
ReflectionObject.prototype.toJSON = /* istanbul ignore next */ function toJSON() {
|
|
148
147
|
throw Error(); // not implemented, shouldn't happen
|
package/src/oneof.js
CHANGED
package/src/parse.js
CHANGED
|
@@ -312,7 +312,9 @@ function parse(source, root, options) {
|
|
|
312
312
|
|
|
313
313
|
|
|
314
314
|
function parseCommon(parent, token, depth) {
|
|
315
|
-
depth
|
|
315
|
+
if (depth === undefined)
|
|
316
|
+
depth = 0;
|
|
317
|
+
// depth is checked by dispatched functions
|
|
316
318
|
switch (token) {
|
|
317
319
|
|
|
318
320
|
case "option":
|
|
@@ -378,7 +380,10 @@ function parse(source, root, options) {
|
|
|
378
380
|
}
|
|
379
381
|
|
|
380
382
|
function parseType(parent, token, depth) {
|
|
381
|
-
depth
|
|
383
|
+
if (depth === undefined)
|
|
384
|
+
depth = 0;
|
|
385
|
+
if (depth > util.nestingLimit)
|
|
386
|
+
throw Error("max depth exceeded");
|
|
382
387
|
|
|
383
388
|
/* istanbul ignore if */
|
|
384
389
|
if (!nameRe.test(token = next()))
|
|
@@ -507,7 +512,10 @@ function parse(source, root, options) {
|
|
|
507
512
|
}
|
|
508
513
|
|
|
509
514
|
function parseGroup(parent, rule, extend, depth) {
|
|
510
|
-
depth
|
|
515
|
+
if (depth === undefined)
|
|
516
|
+
depth = 0;
|
|
517
|
+
if (depth > util.nestingLimit)
|
|
518
|
+
throw Error("max depth exceeded");
|
|
511
519
|
if (edition >= 2023) {
|
|
512
520
|
throw illegal("group");
|
|
513
521
|
}
|
|
@@ -754,7 +762,10 @@ function parse(source, root, options) {
|
|
|
754
762
|
}
|
|
755
763
|
|
|
756
764
|
function parseOptionValue(parent, name, depth) {
|
|
757
|
-
depth
|
|
765
|
+
if (depth === undefined)
|
|
766
|
+
depth = 0;
|
|
767
|
+
if (depth > util.recursionLimit)
|
|
768
|
+
throw Error("max depth exceeded");
|
|
758
769
|
// { a: "foo" b { c: "bar" } }
|
|
759
770
|
if (skip("{", true)) {
|
|
760
771
|
var objectResult = {};
|
|
@@ -845,7 +856,10 @@ function parse(source, root, options) {
|
|
|
845
856
|
}
|
|
846
857
|
|
|
847
858
|
function parseService(parent, token, depth) {
|
|
848
|
-
depth
|
|
859
|
+
if (depth === undefined)
|
|
860
|
+
depth = 0;
|
|
861
|
+
if (depth > util.recursionLimit)
|
|
862
|
+
throw Error("max depth exceeded");
|
|
849
863
|
|
|
850
864
|
/* istanbul ignore if */
|
|
851
865
|
if (!nameRe.test(token = next()))
|
package/src/root.js
CHANGED
|
@@ -59,7 +59,10 @@ function Root(options) {
|
|
|
59
59
|
* @returns {Root} Root namespace
|
|
60
60
|
*/
|
|
61
61
|
Root.fromJSON = function fromJSON(json, root, depth) {
|
|
62
|
-
depth
|
|
62
|
+
if (depth === undefined)
|
|
63
|
+
depth = 0;
|
|
64
|
+
if (depth > util.recursionLimit)
|
|
65
|
+
throw Error("max depth exceeded");
|
|
63
66
|
if (!root)
|
|
64
67
|
root = new Root();
|
|
65
68
|
if (json.options)
|
package/src/service.js
CHANGED
|
@@ -41,7 +41,9 @@ function Service(name, options) {
|
|
|
41
41
|
* Service descriptor.
|
|
42
42
|
* @interface IService
|
|
43
43
|
* @extends INamespace
|
|
44
|
+
* @property {string} [edition] Edition
|
|
44
45
|
* @property {Object.<string,IMethod>} methods Method descriptors
|
|
46
|
+
* @property {string|null} [comment] Service comment
|
|
45
47
|
*/
|
|
46
48
|
|
|
47
49
|
/**
|
|
@@ -53,7 +55,10 @@ function Service(name, options) {
|
|
|
53
55
|
* @throws {TypeError} If arguments are invalid
|
|
54
56
|
*/
|
|
55
57
|
Service.fromJSON = function fromJSON(name, json, depth) {
|
|
56
|
-
depth
|
|
58
|
+
if (depth === undefined)
|
|
59
|
+
depth = 0;
|
|
60
|
+
if (depth > util.recursionLimit)
|
|
61
|
+
throw Error("max depth exceeded");
|
|
57
62
|
var service = new Service(name, json.options);
|
|
58
63
|
/* istanbul ignore else */
|
|
59
64
|
if (json.methods)
|
package/src/type.js
CHANGED
|
@@ -171,6 +171,8 @@ Object.defineProperties(Type.prototype, {
|
|
|
171
171
|
util.merge(ctor, Message, true);
|
|
172
172
|
|
|
173
173
|
this._ctor = ctor;
|
|
174
|
+
delete this.decode;
|
|
175
|
+
delete this.fromObject;
|
|
174
176
|
|
|
175
177
|
// Messages have non-enumerable default values on their prototype
|
|
176
178
|
var i = 0;
|
|
@@ -224,11 +226,13 @@ function clearCache(type) {
|
|
|
224
226
|
* Message type descriptor.
|
|
225
227
|
* @interface IType
|
|
226
228
|
* @extends INamespace
|
|
229
|
+
* @property {string} [edition] Edition
|
|
227
230
|
* @property {Object.<string,IOneOf>} [oneofs] Oneof descriptors
|
|
228
231
|
* @property {Object.<string,IField>} fields Field descriptors
|
|
229
232
|
* @property {number[][]} [extensions] Extension ranges
|
|
230
233
|
* @property {Array.<number[]|string>} [reserved] Reserved ranges
|
|
231
234
|
* @property {boolean} [group=false] Whether a legacy group or not
|
|
235
|
+
* @property {string|null} [comment] Message type comment
|
|
232
236
|
*/
|
|
233
237
|
|
|
234
238
|
/**
|
|
@@ -239,7 +243,10 @@ function clearCache(type) {
|
|
|
239
243
|
* @returns {Type} Created message type
|
|
240
244
|
*/
|
|
241
245
|
Type.fromJSON = function fromJSON(name, json, depth) {
|
|
242
|
-
depth
|
|
246
|
+
if (depth === undefined)
|
|
247
|
+
depth = 0;
|
|
248
|
+
if (depth > util.nestingLimit)
|
|
249
|
+
throw Error("max depth exceeded");
|
|
243
250
|
var type = new Type(name, json.options);
|
|
244
251
|
type.extensions = json.extensions;
|
|
245
252
|
type.reserved = json.reserved;
|
|
@@ -479,7 +486,8 @@ Type.prototype.setup = function setup() {
|
|
|
479
486
|
this.decode = decoder(this)({
|
|
480
487
|
Reader : Reader,
|
|
481
488
|
types : types,
|
|
482
|
-
util : util
|
|
489
|
+
util : util,
|
|
490
|
+
C : this.ctor
|
|
483
491
|
});
|
|
484
492
|
this.verify = verifier(this)({
|
|
485
493
|
types : types,
|
|
@@ -487,7 +495,8 @@ Type.prototype.setup = function setup() {
|
|
|
487
495
|
});
|
|
488
496
|
this.fromObject = converter.fromObject(this)({
|
|
489
497
|
types : types,
|
|
490
|
-
util : util
|
|
498
|
+
util : util,
|
|
499
|
+
C : this.ctor
|
|
491
500
|
});
|
|
492
501
|
this.toObject = converter.toObject(this)({
|
|
493
502
|
types : types,
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/* eslint-disable no-unused-vars */
|
|
3
|
+
|
|
4
|
+
// Global TypeScript helper typedefs. The unused vars anchor these typedefs so
|
|
5
|
+
// both TypeScript checkJs and pbts can discover them from this script file.
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Constructor type.
|
|
9
|
+
* @template T
|
|
10
|
+
* @typedef {Function & { new(...params: any[]): T; prototype: T }} Constructor
|
|
11
|
+
*/
|
|
12
|
+
var Constructor;
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Properties type.
|
|
16
|
+
* @template T
|
|
17
|
+
* @typedef {{ [P in keyof T]?: T[P] }} Properties
|
|
18
|
+
*/
|
|
19
|
+
var Properties;
|
package/src/util/minimal.js
CHANGED
|
@@ -273,12 +273,19 @@ function merge(dst, src, ifNotSet) { // used by converters
|
|
|
273
273
|
|
|
274
274
|
util.merge = merge;
|
|
275
275
|
|
|
276
|
+
/**
|
|
277
|
+
* Schema declaration nesting limit.
|
|
278
|
+
* @memberof util
|
|
279
|
+
* @type {number}
|
|
280
|
+
*/
|
|
281
|
+
util.nestingLimit = 32; // protoc: MaxMessageDeclarationNestingDepth
|
|
282
|
+
|
|
276
283
|
/**
|
|
277
284
|
* Recursion limit.
|
|
278
285
|
* @memberof util
|
|
279
286
|
* @type {number}
|
|
280
287
|
*/
|
|
281
|
-
util.recursionLimit = 100;
|
|
288
|
+
util.recursionLimit = 100; // protoc: CodedInputStream::default_recursion_limit_
|
|
282
289
|
|
|
283
290
|
/**
|
|
284
291
|
* Makes a property safe for assignment as an own property.
|
package/src/util/utf8.js
CHANGED
|
@@ -31,19 +31,7 @@ utf8.length = function utf8_length(string) {
|
|
|
31
31
|
return len;
|
|
32
32
|
};
|
|
33
33
|
|
|
34
|
-
|
|
35
|
-
* Reads UTF8 bytes as a string.
|
|
36
|
-
* @param {Uint8Array} buffer Source buffer
|
|
37
|
-
* @param {number} start Source start
|
|
38
|
-
* @param {number} end Source end
|
|
39
|
-
* @returns {string} String read
|
|
40
|
-
*/
|
|
41
|
-
utf8.read = function utf8_read(buffer, start, end) {
|
|
42
|
-
if (end - start < 1) {
|
|
43
|
-
return "";
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
var str = "";
|
|
34
|
+
function utf8_read_js(buffer, start, end, str) {
|
|
47
35
|
for (var i = start; i < end;) {
|
|
48
36
|
var t = buffer[i++];
|
|
49
37
|
if (t <= 0x7F) {
|
|
@@ -65,6 +53,44 @@ utf8.read = function utf8_read(buffer, start, end) {
|
|
|
65
53
|
}
|
|
66
54
|
}
|
|
67
55
|
}
|
|
56
|
+
return str;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* Reads UTF8 bytes as a string.
|
|
61
|
+
* @param {Uint8Array} buffer Source buffer
|
|
62
|
+
* @param {number} start Source start
|
|
63
|
+
* @param {number} end Source end
|
|
64
|
+
* @returns {string} String read
|
|
65
|
+
*/
|
|
66
|
+
utf8.read = function utf8_read_ascii(buffer, start, end) {
|
|
67
|
+
if (end - start < 1)
|
|
68
|
+
return "";
|
|
69
|
+
|
|
70
|
+
var str = "",
|
|
71
|
+
i = start,
|
|
72
|
+
c1, c2, c3, c4, c5, c6, c7, c8;
|
|
73
|
+
|
|
74
|
+
for (; i + 7 < end; i += 8) {
|
|
75
|
+
c1 = buffer[i];
|
|
76
|
+
c2 = buffer[i + 1];
|
|
77
|
+
c3 = buffer[i + 2];
|
|
78
|
+
c4 = buffer[i + 3];
|
|
79
|
+
c5 = buffer[i + 4];
|
|
80
|
+
c6 = buffer[i + 5];
|
|
81
|
+
c7 = buffer[i + 6];
|
|
82
|
+
c8 = buffer[i + 7];
|
|
83
|
+
if ((c1 | c2 | c3 | c4 | c5 | c6 | c7 | c8) & 0x80)
|
|
84
|
+
return utf8_read_js(buffer, i, end, str);
|
|
85
|
+
str += String.fromCharCode(c1, c2, c3, c4, c5, c6, c7, c8);
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
for (; i < end; ++i) {
|
|
89
|
+
c1 = buffer[i];
|
|
90
|
+
if (c1 & 0x80)
|
|
91
|
+
return utf8_read_js(buffer, i, end, str);
|
|
92
|
+
str += String.fromCharCode(c1);
|
|
93
|
+
}
|
|
68
94
|
|
|
69
95
|
return str;
|
|
70
96
|
};
|
package/src/util.js
CHANGED
|
@@ -25,20 +25,6 @@ var reservedRe = util.patterns.reservedRe,
|
|
|
25
25
|
*/
|
|
26
26
|
util.fs = require("./util/fs");
|
|
27
27
|
|
|
28
|
-
/**
|
|
29
|
-
* Checks a recursion depth.
|
|
30
|
-
* @param {number|undefined} depth Depth of recursion
|
|
31
|
-
* @returns {number} Depth of recursion
|
|
32
|
-
* @throws {Error} If depth exceeds util.recursionLimit
|
|
33
|
-
*/
|
|
34
|
-
util.checkDepth = function checkDepth(depth) {
|
|
35
|
-
if (depth === undefined)
|
|
36
|
-
depth = 0;
|
|
37
|
-
if (depth > util.recursionLimit)
|
|
38
|
-
throw Error("max depth exceeded");
|
|
39
|
-
return depth;
|
|
40
|
-
};
|
|
41
|
-
|
|
42
28
|
/**
|
|
43
29
|
* Converts an object's values to an array.
|
|
44
30
|
* @param {Object.<string,*>} object Object to convert
|
|
@@ -215,6 +201,8 @@ util.setProperty = function setProperty(dst, path, value, ifNotSet) {
|
|
|
215
201
|
throw TypeError("path must be specified");
|
|
216
202
|
|
|
217
203
|
path = path.split(".");
|
|
204
|
+
if (path.length > util.recursionLimit)
|
|
205
|
+
throw Error("max depth exceeded");
|
|
218
206
|
return setProp(dst, path, value);
|
|
219
207
|
};
|
|
220
208
|
|
package/src/writer.js
CHANGED
|
@@ -173,6 +173,11 @@ function writeByte(val, buf, pos) {
|
|
|
173
173
|
buf[pos] = val & 255;
|
|
174
174
|
}
|
|
175
175
|
|
|
176
|
+
function writeStringAscii(val, buf, pos) {
|
|
177
|
+
for (var i = 0; i < val.length;)
|
|
178
|
+
buf[pos++] = val.charCodeAt(i++);
|
|
179
|
+
}
|
|
180
|
+
|
|
176
181
|
function writeVarint32(val, buf, pos) {
|
|
177
182
|
while (val > 127) {
|
|
178
183
|
buf[pos++] = val & 127 | 128;
|
|
@@ -401,7 +406,7 @@ Writer.prototype.raw = function write_raw(value) {
|
|
|
401
406
|
Writer.prototype.string = function write_string(value) {
|
|
402
407
|
var len = utf8.length(value);
|
|
403
408
|
return len
|
|
404
|
-
? this.uint32(len)._push(utf8.write, len, value)
|
|
409
|
+
? this.uint32(len)._push(len === value.length ? writeStringAscii : utf8.write, len, value)
|
|
405
410
|
: this._push(writeByte, 1, 0);
|
|
406
411
|
};
|
|
407
412
|
|
package/src/writer_buffer.js
CHANGED
|
@@ -66,6 +66,11 @@ BufferWriter.prototype.raw = function write_raw_buffer(value) {
|
|
|
66
66
|
return len ? this._push(BufferWriter.writeBytesBuffer, len, value) : this;
|
|
67
67
|
};
|
|
68
68
|
|
|
69
|
+
function writeStringBufferAscii(val, buf, pos) {
|
|
70
|
+
for (var i = 0; i < val.length;)
|
|
71
|
+
buf[pos++] = val.charCodeAt(i++);
|
|
72
|
+
}
|
|
73
|
+
|
|
69
74
|
function writeStringBuffer(val, buf, pos) {
|
|
70
75
|
if (val.length < 40) // plain js is faster for short strings (probably due to redundant assertions)
|
|
71
76
|
util.utf8.write(val, buf, pos);
|
|
@@ -82,7 +87,7 @@ BufferWriter.prototype.string = function write_string_buffer(value) {
|
|
|
82
87
|
var len = util.Buffer.byteLength(value);
|
|
83
88
|
this.uint32(len);
|
|
84
89
|
if (len)
|
|
85
|
-
this._push(writeStringBuffer, len, value);
|
|
90
|
+
this._push(len === value.length && len < 40 ? writeStringBufferAscii : writeStringBuffer, len, value);
|
|
86
91
|
return this;
|
|
87
92
|
};
|
|
88
93
|
|
package/tsconfig.json
CHANGED
package/src/typescript.jsdoc
DELETED
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Constructor type.
|
|
3
|
-
* @interface Constructor
|
|
4
|
-
* @extends Function
|
|
5
|
-
* @template T
|
|
6
|
-
* @tstype new(...params: any[]): T; prototype: T;
|
|
7
|
-
*/
|
|
8
|
-
|
|
9
|
-
/**
|
|
10
|
-
* Properties type.
|
|
11
|
-
* @typedef Properties
|
|
12
|
-
* @template T
|
|
13
|
-
* @type {Object.<string,*>}
|
|
14
|
-
* @tstype { [P in keyof T]?: T[P] }
|
|
15
|
-
*/
|