protobufjs 8.0.1-experimental → 8.0.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/LICENSE +39 -39
- package/README.md +727 -727
- package/dist/light/protobuf.js +7724 -7352
- 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 +2606 -2546
- 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 +9593 -9132
- package/dist/protobuf.js.map +1 -1
- package/dist/protobuf.min.js +3 -3
- package/dist/protobuf.min.js.map +1 -1
- package/ext/debug/README.md +4 -4
- package/ext/debug/index.js +71 -71
- package/ext/descriptor/README.md +72 -72
- package/ext/descriptor/index.d.ts +195 -191
- package/ext/descriptor/index.js +1181 -1052
- package/ext/descriptor/test.js +54 -54
- package/google/LICENSE +27 -27
- package/google/README.md +1 -1
- package/google/api/annotations.json +82 -82
- package/google/api/annotations.proto +10 -10
- package/google/api/http.json +85 -85
- package/google/api/http.proto +30 -30
- package/google/protobuf/api.json +117 -117
- package/google/protobuf/api.proto +33 -33
- package/google/protobuf/descriptor.json +1381 -738
- package/google/protobuf/descriptor.proto +535 -286
- package/google/protobuf/source_context.json +19 -19
- package/google/protobuf/source_context.proto +7 -7
- package/google/protobuf/type.json +201 -201
- package/google/protobuf/type.proto +89 -89
- package/index.d.ts +2817 -2792
- package/index.js +4 -4
- package/light.d.ts +2 -2
- package/light.js +3 -3
- package/minimal.d.ts +2 -2
- package/minimal.js +4 -4
- package/package.json +96 -112
- package/scripts/postinstall.js +32 -32
- package/src/common.js +399 -399
- package/src/converter.js +310 -301
- package/src/decoder.js +135 -127
- package/src/encoder.js +100 -100
- package/src/enum.js +226 -241
- package/src/field.js +453 -432
- package/src/index-light.js +104 -104
- package/src/index-minimal.js +36 -36
- package/src/index.js +12 -12
- package/src/mapfield.js +126 -126
- package/src/message.js +139 -139
- package/src/method.js +160 -160
- package/src/namespace.js +550 -434
- package/src/object.js +385 -330
- package/src/oneof.js +222 -222
- package/src/parse.js +1032 -948
- package/src/reader.js +426 -416
- package/src/reader_buffer.js +51 -51
- package/src/root.js +404 -384
- package/src/roots.js +17 -17
- package/src/rpc/service.js +142 -142
- package/src/rpc.js +36 -36
- package/src/service.js +193 -168
- package/src/tokenize.js +421 -416
- package/src/type.js +625 -590
- package/src/types.js +196 -196
- package/src/typescript.jsdoc +15 -15
- package/src/util/aspromise.d.ts +13 -0
- package/src/util/aspromise.js +52 -0
- package/src/util/base64.d.ts +32 -0
- package/src/util/base64.js +139 -0
- package/src/util/codegen.d.ts +31 -0
- package/src/util/codegen.js +113 -0
- package/src/util/eventemitter.d.ts +45 -0
- package/src/util/eventemitter.js +84 -0
- package/src/util/fetch.d.ts +56 -0
- package/src/util/fetch.js +114 -0
- package/src/util/float.d.ts +83 -0
- package/src/util/float.js +335 -0
- package/src/util/inquire.d.ts +9 -0
- package/src/util/inquire.js +37 -0
- package/src/util/longbits.js +200 -200
- package/src/util/minimal.js +461 -438
- package/src/util/path.d.ts +22 -0
- package/src/util/path.js +72 -0
- package/src/util/patterns.js +8 -0
- package/src/util/pool.d.ts +32 -0
- package/src/util/pool.js +48 -0
- package/src/util/utf8.d.ts +24 -0
- package/src/util/utf8.js +104 -0
- package/src/util.js +215 -213
- package/src/verifier.js +180 -177
- package/src/wrappers.js +103 -102
- package/src/writer.js +465 -465
- package/src/writer_buffer.js +85 -85
- package/tsconfig.json +8 -8
package/src/decoder.js
CHANGED
|
@@ -1,127 +1,135 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
module.exports = decoder;
|
|
3
|
-
|
|
4
|
-
var Enum = require("./enum"),
|
|
5
|
-
types = require("./types"),
|
|
6
|
-
util = require("./util");
|
|
7
|
-
|
|
8
|
-
function missing(field) {
|
|
9
|
-
return "missing required '" + field.name + "'";
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
/**
|
|
13
|
-
* Generates a decoder specific to the specified message type.
|
|
14
|
-
* @param {Type} mtype Message type
|
|
15
|
-
* @returns {Codegen} Codegen instance
|
|
16
|
-
*/
|
|
17
|
-
function decoder(mtype) {
|
|
18
|
-
/* eslint-disable no-unexpected-multiline */
|
|
19
|
-
var gen = util.codegen(["r", "l", "e"], mtype.name + "$decode")
|
|
20
|
-
("if(!(r instanceof Reader))")
|
|
21
|
-
("r=Reader.create(r)")
|
|
22
|
-
("
|
|
23
|
-
("
|
|
24
|
-
("
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
("
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
("
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
("
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
gen
|
|
53
|
-
("
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
gen
|
|
65
|
-
("
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
("break")
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
("
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
//
|
|
92
|
-
if (types.
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
("
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
("
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
(
|
|
126
|
-
|
|
127
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
module.exports = decoder;
|
|
3
|
+
|
|
4
|
+
var Enum = require("./enum"),
|
|
5
|
+
types = require("./types"),
|
|
6
|
+
util = require("./util");
|
|
7
|
+
|
|
8
|
+
function missing(field) {
|
|
9
|
+
return "missing required '" + field.name + "'";
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Generates a decoder specific to the specified message type.
|
|
14
|
+
* @param {Type} mtype Message type
|
|
15
|
+
* @returns {Codegen} Codegen instance
|
|
16
|
+
*/
|
|
17
|
+
function decoder(mtype) {
|
|
18
|
+
/* eslint-disable no-unexpected-multiline */
|
|
19
|
+
var gen = util.codegen(["r", "l", "e", "n"], mtype.name + "$decode")
|
|
20
|
+
("if(!(r instanceof Reader))")
|
|
21
|
+
("r=Reader.create(r)")
|
|
22
|
+
("if(n===undefined)n=0")
|
|
23
|
+
("if(n>Reader.recursionLimit)")
|
|
24
|
+
("throw Error(\"maximum nesting depth exceeded\")")
|
|
25
|
+
("var c=l===undefined?r.len:r.pos+l,m=new this.ctor" + (mtype.fieldsArray.filter(function(field) { return field.map; }).length ? ",k,value" : ""))
|
|
26
|
+
("while(r.pos<c){")
|
|
27
|
+
("var t=r.uint32()")
|
|
28
|
+
("if(t===e)")
|
|
29
|
+
("break")
|
|
30
|
+
("switch(t>>>3){");
|
|
31
|
+
|
|
32
|
+
var i = 0;
|
|
33
|
+
for (; i < /* initializes */ mtype.fieldsArray.length; ++i) {
|
|
34
|
+
var field = mtype._fieldsArray[i].resolve(),
|
|
35
|
+
type = field.resolvedType instanceof Enum ? "int32" : field.type,
|
|
36
|
+
ref = "m" + util.safeProp(field.name); gen
|
|
37
|
+
("case %i: {", field.id);
|
|
38
|
+
|
|
39
|
+
// Map fields
|
|
40
|
+
if (field.map) { gen
|
|
41
|
+
("if(%s===util.emptyObject)", ref)
|
|
42
|
+
("%s={}", ref)
|
|
43
|
+
("var c2 = r.uint32()+r.pos");
|
|
44
|
+
|
|
45
|
+
if (types.defaults[field.keyType] !== undefined) gen
|
|
46
|
+
("k=%j", types.defaults[field.keyType]);
|
|
47
|
+
else gen
|
|
48
|
+
("k=null");
|
|
49
|
+
|
|
50
|
+
if (types.defaults[type] !== undefined) gen
|
|
51
|
+
("value=%j", types.defaults[type]);
|
|
52
|
+
else gen
|
|
53
|
+
("value=null");
|
|
54
|
+
|
|
55
|
+
gen
|
|
56
|
+
("while(r.pos<c2){")
|
|
57
|
+
("var tag2=r.uint32()")
|
|
58
|
+
("switch(tag2>>>3){")
|
|
59
|
+
("case 1: k=r.%s(); break", field.keyType)
|
|
60
|
+
("case 2:");
|
|
61
|
+
|
|
62
|
+
if (types.basic[type] === undefined) gen
|
|
63
|
+
("value=types[%i].decode(r,r.uint32(),undefined,n+1)", i); // can't be groups
|
|
64
|
+
else gen
|
|
65
|
+
("value=r.%s()", type);
|
|
66
|
+
|
|
67
|
+
gen
|
|
68
|
+
("break")
|
|
69
|
+
("default:")
|
|
70
|
+
("r.skipType(tag2&7,n)")
|
|
71
|
+
("break")
|
|
72
|
+
("}")
|
|
73
|
+
("}");
|
|
74
|
+
|
|
75
|
+
if (types.long[field.keyType] !== undefined) gen
|
|
76
|
+
("%s[typeof k===\"object\"?util.longToHash(k):k]=value", ref);
|
|
77
|
+
else {
|
|
78
|
+
if (field.keyType === "string") gen
|
|
79
|
+
("if(k===\"__proto__\")")
|
|
80
|
+
("util.makeProp(%s,k)", ref);
|
|
81
|
+
gen
|
|
82
|
+
("%s[k]=value", ref);
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
// Repeated fields
|
|
86
|
+
} else if (field.repeated) { gen
|
|
87
|
+
|
|
88
|
+
("if(!(%s&&%s.length))", ref, ref)
|
|
89
|
+
("%s=[]", ref);
|
|
90
|
+
|
|
91
|
+
// Packable (always check for forward and backward compatiblity)
|
|
92
|
+
if (types.packed[type] !== undefined) gen
|
|
93
|
+
("if((t&7)===2){")
|
|
94
|
+
("var c2=r.uint32()+r.pos")
|
|
95
|
+
("while(r.pos<c2)")
|
|
96
|
+
("%s.push(r.%s())", ref, type)
|
|
97
|
+
("}else");
|
|
98
|
+
|
|
99
|
+
// Non-packed
|
|
100
|
+
if (types.basic[type] === undefined) gen(field.delimited
|
|
101
|
+
? "%s.push(types[%i].decode(r,undefined,((t&~7)|4),n+1))"
|
|
102
|
+
: "%s.push(types[%i].decode(r,r.uint32(),undefined,n+1))", ref, i);
|
|
103
|
+
else gen
|
|
104
|
+
("%s.push(r.%s())", ref, type);
|
|
105
|
+
|
|
106
|
+
// Non-repeated
|
|
107
|
+
} else if (types.basic[type] === undefined) gen(field.delimited
|
|
108
|
+
? "%s=types[%i].decode(r,undefined,((t&~7)|4),n+1)"
|
|
109
|
+
: "%s=types[%i].decode(r,r.uint32(),undefined,n+1)", ref, i);
|
|
110
|
+
else gen
|
|
111
|
+
("%s=r.%s()", ref, type);
|
|
112
|
+
gen
|
|
113
|
+
("break")
|
|
114
|
+
("}");
|
|
115
|
+
// Unknown fields
|
|
116
|
+
} gen
|
|
117
|
+
("default:")
|
|
118
|
+
("r.skipType(t&7,n)")
|
|
119
|
+
("break")
|
|
120
|
+
|
|
121
|
+
("}")
|
|
122
|
+
("}");
|
|
123
|
+
|
|
124
|
+
// Field presence
|
|
125
|
+
for (i = 0; i < mtype._fieldsArray.length; ++i) {
|
|
126
|
+
var rfield = mtype._fieldsArray[i];
|
|
127
|
+
if (rfield.required) gen
|
|
128
|
+
("if(!m.hasOwnProperty(%j))", rfield.name)
|
|
129
|
+
("throw util.ProtocolError(%j,{instance:m})", missing(rfield));
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
return gen
|
|
133
|
+
("return m");
|
|
134
|
+
/* eslint-enable no-unexpected-multiline */
|
|
135
|
+
}
|
package/src/encoder.js
CHANGED
|
@@ -1,100 +1,100 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
module.exports = encoder;
|
|
3
|
-
|
|
4
|
-
var Enum = require("./enum"),
|
|
5
|
-
types = require("./types"),
|
|
6
|
-
util = require("./util");
|
|
7
|
-
|
|
8
|
-
/**
|
|
9
|
-
* Generates a partial message type encoder.
|
|
10
|
-
* @param {Codegen} gen Codegen instance
|
|
11
|
-
* @param {Field} field Reflected field
|
|
12
|
-
* @param {number} fieldIndex Field index
|
|
13
|
-
* @param {string} ref Variable reference
|
|
14
|
-
* @returns {Codegen} Codegen instance
|
|
15
|
-
* @ignore
|
|
16
|
-
*/
|
|
17
|
-
function genTypePartial(gen, field, fieldIndex, ref) {
|
|
18
|
-
return field.delimited
|
|
19
|
-
? gen("types[%i].encode(%s,w.uint32(%i)).uint32(%i)", fieldIndex, ref, (field.id << 3 | 3) >>> 0, (field.id << 3 | 4) >>> 0)
|
|
20
|
-
: gen("types[%i].encode(%s,w.uint32(%i).fork()).ldelim()", fieldIndex, ref, (field.id << 3 | 2) >>> 0);
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
/**
|
|
24
|
-
* Generates an encoder specific to the specified message type.
|
|
25
|
-
* @param {Type} mtype Message type
|
|
26
|
-
* @returns {Codegen} Codegen instance
|
|
27
|
-
*/
|
|
28
|
-
function encoder(mtype) {
|
|
29
|
-
/* eslint-disable no-unexpected-multiline, block-scoped-var, no-redeclare */
|
|
30
|
-
var gen = util.codegen(["m", "w"], mtype.name + "$encode")
|
|
31
|
-
("if(!w)")
|
|
32
|
-
("w=Writer.create()");
|
|
33
|
-
|
|
34
|
-
var i, ref;
|
|
35
|
-
|
|
36
|
-
// "when a message is serialized its known fields should be written sequentially by field number"
|
|
37
|
-
var fields = /* initializes */ mtype.fieldsArray.slice().sort(util.compareFieldsById);
|
|
38
|
-
|
|
39
|
-
for (var i = 0; i < fields.length; ++i) {
|
|
40
|
-
var field = fields[i].resolve(),
|
|
41
|
-
index = mtype._fieldsArray.indexOf(field),
|
|
42
|
-
type = field.resolvedType instanceof Enum ? "int32" : field.type,
|
|
43
|
-
wireType = types.basic[type];
|
|
44
|
-
ref = "m" + util.safeProp(field.name);
|
|
45
|
-
|
|
46
|
-
// Map fields
|
|
47
|
-
if (field.map) {
|
|
48
|
-
gen
|
|
49
|
-
("if(%s!=null&&Object.hasOwnProperty.call(m,%j)){", ref, field.name) // !== undefined && !== null
|
|
50
|
-
("for(var ks=Object.keys(%s),i=0;i<ks.length;++i){", ref)
|
|
51
|
-
("w.uint32(%i).fork().uint32(%i).%s(ks[i])", (field.id << 3 | 2) >>> 0, 8 | types.mapKey[field.keyType], field.keyType);
|
|
52
|
-
if (wireType === undefined) gen
|
|
53
|
-
("types[%i].encode(%s[ks[i]],w.uint32(18).fork()).ldelim().ldelim()", index, ref); // can't be groups
|
|
54
|
-
else gen
|
|
55
|
-
(".uint32(%i).%s(%s[ks[i]]).ldelim()", 16 | wireType, type, ref);
|
|
56
|
-
gen
|
|
57
|
-
("}")
|
|
58
|
-
("}");
|
|
59
|
-
|
|
60
|
-
// Repeated fields
|
|
61
|
-
} else if (field.repeated) { gen
|
|
62
|
-
("if(%s!=null&&%s.length){", ref, ref); // !== undefined && !== null
|
|
63
|
-
|
|
64
|
-
// Packed repeated
|
|
65
|
-
if (field.packed && types.packed[type] !== undefined) { gen
|
|
66
|
-
|
|
67
|
-
("w.uint32(%i).fork()", (field.id << 3 | 2) >>> 0)
|
|
68
|
-
("for(var i=0;i<%s.length;++i)", ref)
|
|
69
|
-
("w.%s(%s[i])", type, ref)
|
|
70
|
-
("w.ldelim()");
|
|
71
|
-
|
|
72
|
-
// Non-packed
|
|
73
|
-
} else { gen
|
|
74
|
-
|
|
75
|
-
("for(var i=0;i<%s.length;++i)", ref);
|
|
76
|
-
if (wireType === undefined)
|
|
77
|
-
genTypePartial(gen, field, index, ref + "[i]");
|
|
78
|
-
else gen
|
|
79
|
-
("w.uint32(%i).%s(%s[i])", (field.id << 3 | wireType) >>> 0, type, ref);
|
|
80
|
-
|
|
81
|
-
} gen
|
|
82
|
-
("}");
|
|
83
|
-
|
|
84
|
-
// Non-repeated
|
|
85
|
-
} else {
|
|
86
|
-
if (field.optional) gen
|
|
87
|
-
("if(%s!=null&&Object.hasOwnProperty.call(m,%j))", ref, field.name); // !== undefined && !== null
|
|
88
|
-
|
|
89
|
-
if (wireType === undefined)
|
|
90
|
-
genTypePartial(gen, field, index, ref);
|
|
91
|
-
else gen
|
|
92
|
-
("w.uint32(%i).%s(%s)", (field.id << 3 | wireType) >>> 0, type, ref);
|
|
93
|
-
|
|
94
|
-
}
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
return gen
|
|
98
|
-
("return w");
|
|
99
|
-
/* eslint-enable no-unexpected-multiline, block-scoped-var, no-redeclare */
|
|
100
|
-
}
|
|
1
|
+
"use strict";
|
|
2
|
+
module.exports = encoder;
|
|
3
|
+
|
|
4
|
+
var Enum = require("./enum"),
|
|
5
|
+
types = require("./types"),
|
|
6
|
+
util = require("./util");
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Generates a partial message type encoder.
|
|
10
|
+
* @param {Codegen} gen Codegen instance
|
|
11
|
+
* @param {Field} field Reflected field
|
|
12
|
+
* @param {number} fieldIndex Field index
|
|
13
|
+
* @param {string} ref Variable reference
|
|
14
|
+
* @returns {Codegen} Codegen instance
|
|
15
|
+
* @ignore
|
|
16
|
+
*/
|
|
17
|
+
function genTypePartial(gen, field, fieldIndex, ref) {
|
|
18
|
+
return field.delimited
|
|
19
|
+
? gen("types[%i].encode(%s,w.uint32(%i)).uint32(%i)", fieldIndex, ref, (field.id << 3 | 3) >>> 0, (field.id << 3 | 4) >>> 0)
|
|
20
|
+
: gen("types[%i].encode(%s,w.uint32(%i).fork()).ldelim()", fieldIndex, ref, (field.id << 3 | 2) >>> 0);
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* Generates an encoder specific to the specified message type.
|
|
25
|
+
* @param {Type} mtype Message type
|
|
26
|
+
* @returns {Codegen} Codegen instance
|
|
27
|
+
*/
|
|
28
|
+
function encoder(mtype) {
|
|
29
|
+
/* eslint-disable no-unexpected-multiline, block-scoped-var, no-redeclare */
|
|
30
|
+
var gen = util.codegen(["m", "w"], mtype.name + "$encode")
|
|
31
|
+
("if(!w)")
|
|
32
|
+
("w=Writer.create()");
|
|
33
|
+
|
|
34
|
+
var i, ref;
|
|
35
|
+
|
|
36
|
+
// "when a message is serialized its known fields should be written sequentially by field number"
|
|
37
|
+
var fields = /* initializes */ mtype.fieldsArray.slice().sort(util.compareFieldsById);
|
|
38
|
+
|
|
39
|
+
for (var i = 0; i < fields.length; ++i) {
|
|
40
|
+
var field = fields[i].resolve(),
|
|
41
|
+
index = mtype._fieldsArray.indexOf(field),
|
|
42
|
+
type = field.resolvedType instanceof Enum ? "int32" : field.type,
|
|
43
|
+
wireType = types.basic[type];
|
|
44
|
+
ref = "m" + util.safeProp(field.name);
|
|
45
|
+
|
|
46
|
+
// Map fields
|
|
47
|
+
if (field.map) {
|
|
48
|
+
gen
|
|
49
|
+
("if(%s!=null&&Object.hasOwnProperty.call(m,%j)){", ref, field.name) // !== undefined && !== null
|
|
50
|
+
("for(var ks=Object.keys(%s),i=0;i<ks.length;++i){", ref)
|
|
51
|
+
("w.uint32(%i).fork().uint32(%i).%s(ks[i])", (field.id << 3 | 2) >>> 0, 8 | types.mapKey[field.keyType], field.keyType);
|
|
52
|
+
if (wireType === undefined) gen
|
|
53
|
+
("types[%i].encode(%s[ks[i]],w.uint32(18).fork()).ldelim().ldelim()", index, ref); // can't be groups
|
|
54
|
+
else gen
|
|
55
|
+
(".uint32(%i).%s(%s[ks[i]]).ldelim()", 16 | wireType, type, ref);
|
|
56
|
+
gen
|
|
57
|
+
("}")
|
|
58
|
+
("}");
|
|
59
|
+
|
|
60
|
+
// Repeated fields
|
|
61
|
+
} else if (field.repeated) { gen
|
|
62
|
+
("if(%s!=null&&%s.length){", ref, ref); // !== undefined && !== null
|
|
63
|
+
|
|
64
|
+
// Packed repeated
|
|
65
|
+
if (field.packed && types.packed[type] !== undefined) { gen
|
|
66
|
+
|
|
67
|
+
("w.uint32(%i).fork()", (field.id << 3 | 2) >>> 0)
|
|
68
|
+
("for(var i=0;i<%s.length;++i)", ref)
|
|
69
|
+
("w.%s(%s[i])", type, ref)
|
|
70
|
+
("w.ldelim()");
|
|
71
|
+
|
|
72
|
+
// Non-packed
|
|
73
|
+
} else { gen
|
|
74
|
+
|
|
75
|
+
("for(var i=0;i<%s.length;++i)", ref);
|
|
76
|
+
if (wireType === undefined)
|
|
77
|
+
genTypePartial(gen, field, index, ref + "[i]");
|
|
78
|
+
else gen
|
|
79
|
+
("w.uint32(%i).%s(%s[i])", (field.id << 3 | wireType) >>> 0, type, ref);
|
|
80
|
+
|
|
81
|
+
} gen
|
|
82
|
+
("}");
|
|
83
|
+
|
|
84
|
+
// Non-repeated
|
|
85
|
+
} else {
|
|
86
|
+
if (field.optional) gen
|
|
87
|
+
("if(%s!=null&&Object.hasOwnProperty.call(m,%j))", ref, field.name); // !== undefined && !== null
|
|
88
|
+
|
|
89
|
+
if (wireType === undefined)
|
|
90
|
+
genTypePartial(gen, field, index, ref);
|
|
91
|
+
else gen
|
|
92
|
+
("w.uint32(%i).%s(%s)", (field.id << 3 | wireType) >>> 0, type, ref);
|
|
93
|
+
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
return gen
|
|
98
|
+
("return w");
|
|
99
|
+
/* eslint-enable no-unexpected-multiline, block-scoped-var, no-redeclare */
|
|
100
|
+
}
|