typia 7.0.0-dev.20240921 → 7.0.0-dev.20240922
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/lib/programmers/notations/NotationGeneralProgrammer.js +355 -369
- package/lib/programmers/notations/NotationGeneralProgrammer.js.map +1 -1
- package/lib/programmers/protobuf/ProtobufDecodeProgrammer.js +264 -239
- package/lib/programmers/protobuf/ProtobufDecodeProgrammer.js.map +1 -1
- package/lib/programmers/protobuf/ProtobufEncodeProgrammer.js +424 -368
- package/lib/programmers/protobuf/ProtobufEncodeProgrammer.js.map +1 -1
- package/lib/programmers/protobuf/ProtobufMessageProgrammer.js +106 -85
- package/lib/programmers/protobuf/ProtobufMessageProgrammer.js.map +1 -1
- package/package.json +1 -1
- package/src/programmers/notations/NotationGeneralProgrammer.ts +610 -528
- package/src/programmers/protobuf/ProtobufDecodeProgrammer.ts +421 -358
- package/src/programmers/protobuf/ProtobufEncodeProgrammer.ts +752 -613
- package/src/programmers/protobuf/ProtobufMessageProgrammer.ts +96 -63
|
@@ -43,12 +43,16 @@ export namespace ProtobufDecodeProgrammer {
|
|
|
43
43
|
functions: Object.fromEntries(
|
|
44
44
|
collection
|
|
45
45
|
.objects()
|
|
46
|
-
.filter((
|
|
47
|
-
.map((
|
|
48
|
-
`${PREFIX}o${
|
|
46
|
+
.filter((object) => ProtobufUtil.isStaticObject(object))
|
|
47
|
+
.map((object) => [
|
|
48
|
+
`${PREFIX}o${object.index}`,
|
|
49
49
|
StatementFactory.constant(
|
|
50
|
-
props.importer.useLocal(`${PREFIX}o${
|
|
51
|
-
write_object_function(
|
|
50
|
+
props.importer.useLocal(`${PREFIX}o${object.index}`),
|
|
51
|
+
write_object_function({
|
|
52
|
+
context: props.context,
|
|
53
|
+
importer: props.importer,
|
|
54
|
+
object,
|
|
55
|
+
}),
|
|
52
56
|
),
|
|
53
57
|
]),
|
|
54
58
|
),
|
|
@@ -87,7 +91,10 @@ export namespace ProtobufDecodeProgrammer {
|
|
|
87
91
|
),
|
|
88
92
|
),
|
|
89
93
|
ts.factory.createReturnStatement(
|
|
90
|
-
decode_regular_object(
|
|
94
|
+
decode_regular_object({
|
|
95
|
+
top: true,
|
|
96
|
+
object: meta.objects[0]!,
|
|
97
|
+
}),
|
|
91
98
|
),
|
|
92
99
|
],
|
|
93
100
|
true,
|
|
@@ -111,153 +118,163 @@ export namespace ProtobufDecodeProgrammer {
|
|
|
111
118
|
});
|
|
112
119
|
};
|
|
113
120
|
|
|
114
|
-
const write_object_function =
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
+
const write_object_function = (props: {
|
|
122
|
+
context: ITypiaContext;
|
|
123
|
+
importer: FunctionImporter;
|
|
124
|
+
object: MetadataObject;
|
|
125
|
+
}): ts.ArrowFunction =>
|
|
126
|
+
ts.factory.createArrowFunction(
|
|
127
|
+
undefined,
|
|
128
|
+
undefined,
|
|
129
|
+
[
|
|
130
|
+
IdentifierFactory.parameter("reader"),
|
|
131
|
+
IdentifierFactory.parameter(
|
|
132
|
+
"length",
|
|
133
|
+
TypeFactory.keyword("number"),
|
|
134
|
+
ExpressionFactory.number(-1),
|
|
135
|
+
),
|
|
136
|
+
],
|
|
137
|
+
TypeFactory.keyword("any"),
|
|
138
|
+
undefined,
|
|
139
|
+
ts.factory.createBlock(
|
|
121
140
|
[
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
ts.factory.createBinaryExpression(
|
|
135
|
-
ts.factory.createIdentifier("length"),
|
|
136
|
-
ts.factory.createToken(ts.SyntaxKind.EqualsToken),
|
|
137
|
-
ts.factory.createConditionalExpression(
|
|
138
|
-
ts.factory.createLessThan(
|
|
139
|
-
ts.factory.createIdentifier("length"),
|
|
140
|
-
ExpressionFactory.number(0),
|
|
141
|
-
),
|
|
141
|
+
ts.factory.createExpressionStatement(
|
|
142
|
+
ts.factory.createBinaryExpression(
|
|
143
|
+
ts.factory.createIdentifier("length"),
|
|
144
|
+
ts.factory.createToken(ts.SyntaxKind.EqualsToken),
|
|
145
|
+
ts.factory.createConditionalExpression(
|
|
146
|
+
ts.factory.createLessThan(
|
|
147
|
+
ts.factory.createIdentifier("length"),
|
|
148
|
+
ExpressionFactory.number(0),
|
|
149
|
+
),
|
|
150
|
+
undefined,
|
|
151
|
+
ts.factory.createCallExpression(
|
|
152
|
+
IdentifierFactory.access(READER())("size"),
|
|
142
153
|
undefined,
|
|
154
|
+
undefined,
|
|
155
|
+
),
|
|
156
|
+
undefined,
|
|
157
|
+
ts.factory.createAdd(
|
|
143
158
|
ts.factory.createCallExpression(
|
|
144
|
-
IdentifierFactory.access(READER())("
|
|
159
|
+
IdentifierFactory.access(READER())("index"),
|
|
145
160
|
undefined,
|
|
146
161
|
undefined,
|
|
147
162
|
),
|
|
148
|
-
|
|
149
|
-
ts.factory.createAdd(
|
|
150
|
-
ts.factory.createCallExpression(
|
|
151
|
-
IdentifierFactory.access(READER())("index"),
|
|
152
|
-
undefined,
|
|
153
|
-
undefined,
|
|
154
|
-
),
|
|
155
|
-
ts.factory.createIdentifier("length"),
|
|
156
|
-
),
|
|
163
|
+
ts.factory.createIdentifier("length"),
|
|
157
164
|
),
|
|
158
165
|
),
|
|
159
166
|
),
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
),
|
|
167
|
-
|
|
167
|
+
),
|
|
168
|
+
...write_object_function_body({
|
|
169
|
+
context: props.context,
|
|
170
|
+
importer: props.importer,
|
|
171
|
+
condition: ts.factory.createLessThan(
|
|
172
|
+
ts.factory.createCallExpression(
|
|
173
|
+
IdentifierFactory.access(READER())("index"),
|
|
174
|
+
undefined,
|
|
175
|
+
undefined,
|
|
168
176
|
),
|
|
169
|
-
|
|
170
|
-
output: "output",
|
|
171
|
-
})(obj.properties),
|
|
172
|
-
ts.factory.createReturnStatement(
|
|
173
|
-
ts.factory.createIdentifier("output"),
|
|
177
|
+
ts.factory.createIdentifier("length"),
|
|
174
178
|
),
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
+
tag: "tag",
|
|
180
|
+
output: "output",
|
|
181
|
+
properties: props.object.properties,
|
|
182
|
+
}),
|
|
183
|
+
ts.factory.createReturnStatement(
|
|
184
|
+
ts.factory.createIdentifier("output"),
|
|
185
|
+
),
|
|
186
|
+
],
|
|
187
|
+
true,
|
|
188
|
+
),
|
|
189
|
+
);
|
|
179
190
|
|
|
180
|
-
const write_object_function_body =
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
191
|
+
const write_object_function_body = (props: {
|
|
192
|
+
context: ITypiaContext;
|
|
193
|
+
importer: FunctionImporter;
|
|
194
|
+
condition: ts.Expression;
|
|
195
|
+
tag: string;
|
|
196
|
+
output: string;
|
|
197
|
+
properties: MetadataProperty[];
|
|
198
|
+
}): ts.Statement[] => {
|
|
199
|
+
let index: number = 1;
|
|
200
|
+
const clauses: ts.CaseClause[] = props.properties
|
|
201
|
+
.map((p) => {
|
|
202
|
+
const clause = decode_property({
|
|
203
|
+
context: props.context,
|
|
204
|
+
importer: props.importer,
|
|
205
|
+
index,
|
|
206
|
+
accessor: IdentifierFactory.access(
|
|
207
|
+
ts.factory.createIdentifier(props.output),
|
|
208
|
+
)(p.key.getSoleLiteral()!),
|
|
209
|
+
metadata: p.value,
|
|
210
|
+
});
|
|
211
|
+
index += ProtobufUtil.size(p.value);
|
|
212
|
+
return clause;
|
|
213
|
+
})
|
|
214
|
+
.flat();
|
|
215
|
+
return [
|
|
216
|
+
StatementFactory.constant(
|
|
217
|
+
props.output,
|
|
218
|
+
ts.factory.createAsExpression(
|
|
219
|
+
ts.factory.createObjectLiteralExpression(
|
|
220
|
+
props.properties
|
|
221
|
+
.filter(
|
|
222
|
+
(p) =>
|
|
223
|
+
!(
|
|
224
|
+
props.context.compilerOptions.exactOptionalPropertyTypes ===
|
|
225
|
+
true && p.value.optional === true
|
|
215
226
|
),
|
|
227
|
+
)
|
|
228
|
+
.map((p) =>
|
|
229
|
+
ts.factory.createPropertyAssignment(
|
|
230
|
+
IdentifierFactory.identifier(p.key.getSoleLiteral()!),
|
|
231
|
+
write_property_default_value(p.value),
|
|
216
232
|
),
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
TypeFactory.keyword("any"),
|
|
233
|
+
),
|
|
234
|
+
true,
|
|
220
235
|
),
|
|
236
|
+
TypeFactory.keyword("any"),
|
|
221
237
|
),
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
238
|
+
),
|
|
239
|
+
ts.factory.createWhileStatement(
|
|
240
|
+
props.condition,
|
|
241
|
+
ts.factory.createBlock([
|
|
242
|
+
StatementFactory.constant(
|
|
243
|
+
props.tag,
|
|
244
|
+
ts.factory.createCallExpression(
|
|
245
|
+
IdentifierFactory.access(READER())("uint32"),
|
|
246
|
+
undefined,
|
|
247
|
+
undefined,
|
|
232
248
|
),
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
),
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
),
|
|
250
|
-
|
|
251
|
-
|
|
249
|
+
),
|
|
250
|
+
ts.factory.createSwitchStatement(
|
|
251
|
+
ts.factory.createUnsignedRightShift(
|
|
252
|
+
ts.factory.createIdentifier(props.tag),
|
|
253
|
+
ExpressionFactory.number(3),
|
|
254
|
+
),
|
|
255
|
+
ts.factory.createCaseBlock([
|
|
256
|
+
...clauses,
|
|
257
|
+
ts.factory.createDefaultClause([
|
|
258
|
+
ts.factory.createExpressionStatement(
|
|
259
|
+
ts.factory.createCallExpression(
|
|
260
|
+
IdentifierFactory.access(READER())("skipType"),
|
|
261
|
+
undefined,
|
|
262
|
+
[
|
|
263
|
+
ts.factory.createBitwiseAnd(
|
|
264
|
+
ts.factory.createIdentifier(props.tag),
|
|
265
|
+
ExpressionFactory.number(7),
|
|
266
|
+
),
|
|
267
|
+
],
|
|
252
268
|
),
|
|
253
|
-
|
|
254
|
-
|
|
269
|
+
),
|
|
270
|
+
ts.factory.createBreakStatement(),
|
|
255
271
|
]),
|
|
256
|
-
),
|
|
257
|
-
|
|
258
|
-
),
|
|
259
|
-
|
|
260
|
-
|
|
272
|
+
]),
|
|
273
|
+
),
|
|
274
|
+
]),
|
|
275
|
+
),
|
|
276
|
+
];
|
|
277
|
+
};
|
|
261
278
|
|
|
262
279
|
const write_property_default_value = (value: Metadata) =>
|
|
263
280
|
ts.factory.createAsExpression(
|
|
@@ -303,87 +320,118 @@ export namespace ProtobufDecodeProgrammer {
|
|
|
303
320
|
/* -----------------------------------------------------------
|
|
304
321
|
DECODERS
|
|
305
322
|
----------------------------------------------------------- */
|
|
306
|
-
const decode_property =
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
ts.factory.
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
ts.factory.
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
ts.factory.
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
v,
|
|
336
|
-
),
|
|
323
|
+
const decode_property = (props: {
|
|
324
|
+
context: ITypiaContext;
|
|
325
|
+
importer: FunctionImporter;
|
|
326
|
+
index: number;
|
|
327
|
+
accessor: ts.ElementAccessExpression | ts.PropertyAccessExpression;
|
|
328
|
+
metadata: Metadata;
|
|
329
|
+
}): ts.CaseClause[] => {
|
|
330
|
+
const clauses: ts.CaseClause[] = [];
|
|
331
|
+
const emplace = (name: string, value: ts.Expression | ts.Statement[]) =>
|
|
332
|
+
clauses.push(
|
|
333
|
+
ts.factory.createCaseClause(
|
|
334
|
+
ExpressionFactory.number(props.index++),
|
|
335
|
+
Array.isArray(value)
|
|
336
|
+
? [
|
|
337
|
+
ts.factory.createExpressionStatement(
|
|
338
|
+
ts.factory.createIdentifier(`// type: ${name}`),
|
|
339
|
+
),
|
|
340
|
+
...value,
|
|
341
|
+
ts.factory.createBreakStatement(),
|
|
342
|
+
]
|
|
343
|
+
: [
|
|
344
|
+
ts.factory.createExpressionStatement(
|
|
345
|
+
ts.factory.createIdentifier(`// ${name}`),
|
|
346
|
+
),
|
|
347
|
+
ts.factory.createExpressionStatement(
|
|
348
|
+
ts.factory.createBinaryExpression(
|
|
349
|
+
props.accessor,
|
|
350
|
+
ts.factory.createToken(ts.SyntaxKind.EqualsToken),
|
|
351
|
+
value,
|
|
337
352
|
),
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
)
|
|
353
|
+
),
|
|
354
|
+
ts.factory.createBreakStatement(),
|
|
355
|
+
],
|
|
356
|
+
),
|
|
357
|
+
);
|
|
342
358
|
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
359
|
+
const required: boolean =
|
|
360
|
+
props.metadata.isRequired() && !props.metadata.nullable;
|
|
361
|
+
for (const atomic of ProtobufUtil.getAtomics(props.metadata))
|
|
362
|
+
emplace(
|
|
363
|
+
atomic,
|
|
364
|
+
decode_atomic({
|
|
365
|
+
metadata: props.metadata,
|
|
366
|
+
type: atomic,
|
|
367
|
+
}),
|
|
368
|
+
);
|
|
369
|
+
if (props.metadata.natives.length) emplace("bytes", decode_bytes("bytes"));
|
|
370
|
+
for (const array of props.metadata.arrays)
|
|
371
|
+
emplace(
|
|
372
|
+
`Array<${array.type.value.getName()}>`,
|
|
373
|
+
decode_array({
|
|
374
|
+
accessor: props.accessor,
|
|
375
|
+
array,
|
|
376
|
+
required,
|
|
377
|
+
}),
|
|
378
|
+
);
|
|
379
|
+
for (const entry of props.metadata.maps)
|
|
380
|
+
emplace(
|
|
381
|
+
`Map<string, ${entry.value.getName()}>`,
|
|
382
|
+
decode_map({
|
|
383
|
+
context: props.context,
|
|
384
|
+
importer: props.importer,
|
|
385
|
+
accessor: props.accessor,
|
|
386
|
+
entry,
|
|
387
|
+
required,
|
|
388
|
+
}),
|
|
389
|
+
);
|
|
390
|
+
for (const object of props.metadata.objects)
|
|
391
|
+
emplace(
|
|
392
|
+
object.name,
|
|
393
|
+
ProtobufUtil.isStaticObject(object)
|
|
394
|
+
? decode_regular_object({
|
|
395
|
+
top: false,
|
|
396
|
+
object,
|
|
397
|
+
})
|
|
398
|
+
: decode_dynamic_object({
|
|
399
|
+
context: props.context,
|
|
400
|
+
importer: props.importer,
|
|
401
|
+
accessor: props.accessor,
|
|
402
|
+
object,
|
|
403
|
+
required,
|
|
404
|
+
}),
|
|
405
|
+
);
|
|
406
|
+
return clauses;
|
|
407
|
+
};
|
|
363
408
|
|
|
364
|
-
const decode_atomic =
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
409
|
+
const decode_atomic = (props: {
|
|
410
|
+
metadata: Metadata;
|
|
411
|
+
type: ProtobufAtomic;
|
|
412
|
+
}): ts.Expression => {
|
|
413
|
+
if (props.type === "string") return decode_bytes("string");
|
|
368
414
|
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
415
|
+
const call: ts.CallExpression = ts.factory.createCallExpression(
|
|
416
|
+
IdentifierFactory.access(ts.factory.createIdentifier("reader"))(
|
|
417
|
+
props.type,
|
|
418
|
+
),
|
|
419
|
+
undefined,
|
|
420
|
+
undefined,
|
|
421
|
+
);
|
|
422
|
+
if (props.type !== "int64" && props.type !== "uint64") return call;
|
|
375
423
|
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
424
|
+
const isNumber: boolean = ProtobufUtil.getNumbers(props.metadata).some(
|
|
425
|
+
(n) => n === props.type,
|
|
426
|
+
);
|
|
427
|
+
return isNumber
|
|
428
|
+
? ts.factory.createCallExpression(
|
|
429
|
+
ts.factory.createIdentifier("Number"),
|
|
430
|
+
undefined,
|
|
431
|
+
[call],
|
|
432
|
+
)
|
|
433
|
+
: call;
|
|
434
|
+
};
|
|
387
435
|
|
|
388
436
|
const decode_bytes = (method: "bytes" | "string"): ts.Expression =>
|
|
389
437
|
ts.factory.createCallExpression(
|
|
@@ -392,16 +440,16 @@ export namespace ProtobufDecodeProgrammer {
|
|
|
392
440
|
undefined,
|
|
393
441
|
);
|
|
394
442
|
|
|
395
|
-
const decode_array = (
|
|
396
|
-
accessor: ts.ElementAccessExpression | ts.PropertyAccessExpression
|
|
397
|
-
array: MetadataArray
|
|
398
|
-
required: boolean
|
|
399
|
-
): ts.Statement[] => {
|
|
443
|
+
const decode_array = (props: {
|
|
444
|
+
accessor: ts.ElementAccessExpression | ts.PropertyAccessExpression;
|
|
445
|
+
array: MetadataArray;
|
|
446
|
+
required: boolean;
|
|
447
|
+
}): ts.Statement[] => {
|
|
400
448
|
const statements: Array<ts.Expression | ts.Statement> = [];
|
|
401
|
-
if (required === false)
|
|
449
|
+
if (props.required === false)
|
|
402
450
|
statements.push(
|
|
403
451
|
ts.factory.createBinaryExpression(
|
|
404
|
-
accessor,
|
|
452
|
+
props.accessor,
|
|
405
453
|
ts.factory.createToken(ts.SyntaxKind.QuestionQuestionEqualsToken),
|
|
406
454
|
ts.factory.createAsExpression(
|
|
407
455
|
ts.factory.createArrayLiteralExpression(),
|
|
@@ -409,13 +457,21 @@ export namespace ProtobufDecodeProgrammer {
|
|
|
409
457
|
),
|
|
410
458
|
),
|
|
411
459
|
);
|
|
412
|
-
const atomics = ProtobufUtil.getAtomics(array.type.value);
|
|
460
|
+
const atomics = ProtobufUtil.getAtomics(props.array.type.value);
|
|
413
461
|
const decoder = atomics.length
|
|
414
|
-
? () =>
|
|
415
|
-
|
|
462
|
+
? () =>
|
|
463
|
+
decode_atomic({
|
|
464
|
+
metadata: props.array.type.value,
|
|
465
|
+
type: atomics[0]!,
|
|
466
|
+
})
|
|
467
|
+
: props.array.type.value.natives.length
|
|
416
468
|
? () => decode_bytes("bytes")
|
|
417
|
-
: array.type.value.objects.length
|
|
418
|
-
? () =>
|
|
469
|
+
: props.array.type.value.objects.length
|
|
470
|
+
? () =>
|
|
471
|
+
decode_regular_object({
|
|
472
|
+
top: false,
|
|
473
|
+
object: props.array.type.value.objects[0]!,
|
|
474
|
+
})
|
|
419
475
|
: null;
|
|
420
476
|
if (decoder === null) throw new Error("Never reach here.");
|
|
421
477
|
else if (atomics.length && atomics[0] !== "string") {
|
|
@@ -456,7 +512,7 @@ export namespace ProtobufDecodeProgrammer {
|
|
|
456
512
|
),
|
|
457
513
|
ts.factory.createExpressionStatement(
|
|
458
514
|
ts.factory.createCallExpression(
|
|
459
|
-
IdentifierFactory.access(accessor)("push"),
|
|
515
|
+
IdentifierFactory.access(props.accessor)("push"),
|
|
460
516
|
undefined,
|
|
461
517
|
[decoder()],
|
|
462
518
|
),
|
|
@@ -467,7 +523,7 @@ export namespace ProtobufDecodeProgrammer {
|
|
|
467
523
|
),
|
|
468
524
|
ts.factory.createExpressionStatement(
|
|
469
525
|
ts.factory.createCallExpression(
|
|
470
|
-
IdentifierFactory.access(accessor)("push"),
|
|
526
|
+
IdentifierFactory.access(props.accessor)("push"),
|
|
471
527
|
undefined,
|
|
472
528
|
[decoder()],
|
|
473
529
|
),
|
|
@@ -477,7 +533,7 @@ export namespace ProtobufDecodeProgrammer {
|
|
|
477
533
|
} else
|
|
478
534
|
statements.push(
|
|
479
535
|
ts.factory.createCallExpression(
|
|
480
|
-
IdentifierFactory.access(accessor)("push"),
|
|
536
|
+
IdentifierFactory.access(props.accessor)("push"),
|
|
481
537
|
undefined,
|
|
482
538
|
[decoder()],
|
|
483
539
|
),
|
|
@@ -487,159 +543,166 @@ export namespace ProtobufDecodeProgrammer {
|
|
|
487
543
|
);
|
|
488
544
|
};
|
|
489
545
|
|
|
490
|
-
const decode_regular_object =
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
546
|
+
const decode_regular_object = (props: {
|
|
547
|
+
top: boolean;
|
|
548
|
+
object: MetadataObject;
|
|
549
|
+
}): ts.Expression =>
|
|
550
|
+
ts.factory.createCallExpression(
|
|
551
|
+
ts.factory.createIdentifier(`${PREFIX}o${props.object.index}`),
|
|
552
|
+
undefined,
|
|
553
|
+
[
|
|
554
|
+
ts.factory.createIdentifier("reader"),
|
|
555
|
+
...(props.top
|
|
556
|
+
? []
|
|
557
|
+
: [
|
|
558
|
+
ts.factory.createCallExpression(
|
|
559
|
+
IdentifierFactory.access(READER())("uint32"),
|
|
560
|
+
undefined,
|
|
561
|
+
undefined,
|
|
562
|
+
),
|
|
563
|
+
]),
|
|
564
|
+
],
|
|
565
|
+
);
|
|
509
566
|
|
|
510
|
-
const decode_dynamic_object =
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
),
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
),
|
|
532
|
-
ts.factory.createToken(ts.SyntaxKind.EqualsToken),
|
|
533
|
-
ts.factory.createIdentifier("entry.value"),
|
|
567
|
+
const decode_dynamic_object = (props: {
|
|
568
|
+
context: ITypiaContext;
|
|
569
|
+
importer: FunctionImporter;
|
|
570
|
+
accessor: ts.ElementAccessExpression | ts.PropertyAccessExpression;
|
|
571
|
+
object: MetadataObject;
|
|
572
|
+
required: boolean;
|
|
573
|
+
}): ts.Statement[] => {
|
|
574
|
+
const top: MetadataProperty = props.object.properties[0]!;
|
|
575
|
+
return decode_entry({
|
|
576
|
+
context: props.context,
|
|
577
|
+
importer: props.importer,
|
|
578
|
+
initializer: () =>
|
|
579
|
+
ts.factory.createBinaryExpression(
|
|
580
|
+
props.accessor,
|
|
581
|
+
ts.factory.createToken(ts.SyntaxKind.QuestionQuestionEqualsToken),
|
|
582
|
+
ts.factory.createObjectLiteralExpression(),
|
|
583
|
+
),
|
|
584
|
+
setter: () =>
|
|
585
|
+
ts.factory.createBinaryExpression(
|
|
586
|
+
ts.factory.createElementAccessExpression(
|
|
587
|
+
props.accessor,
|
|
588
|
+
ts.factory.createIdentifier("entry.key"),
|
|
534
589
|
),
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
)
|
|
551
|
-
|
|
590
|
+
ts.factory.createToken(ts.SyntaxKind.EqualsToken),
|
|
591
|
+
ts.factory.createIdentifier("entry.value"),
|
|
592
|
+
),
|
|
593
|
+
entry: MetadataProperty.create({
|
|
594
|
+
...top,
|
|
595
|
+
key: (() => {
|
|
596
|
+
const key: Metadata = Metadata.initialize();
|
|
597
|
+
key.atomics.push(
|
|
598
|
+
MetadataAtomic.create({
|
|
599
|
+
type: "string",
|
|
600
|
+
tags: [],
|
|
601
|
+
}),
|
|
602
|
+
);
|
|
603
|
+
return key;
|
|
604
|
+
})(),
|
|
605
|
+
}),
|
|
606
|
+
required: props.required,
|
|
607
|
+
});
|
|
608
|
+
};
|
|
552
609
|
|
|
553
|
-
const decode_map =
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
610
|
+
const decode_map = (props: {
|
|
611
|
+
context: ITypiaContext;
|
|
612
|
+
importer: FunctionImporter;
|
|
613
|
+
accessor: ts.ElementAccessExpression | ts.PropertyAccessExpression;
|
|
614
|
+
entry: Metadata.Entry;
|
|
615
|
+
required: boolean;
|
|
616
|
+
}): ts.Statement[] =>
|
|
617
|
+
decode_entry({
|
|
618
|
+
context: props.context,
|
|
619
|
+
importer: props.importer,
|
|
620
|
+
initializer: () =>
|
|
621
|
+
ts.factory.createBinaryExpression(
|
|
622
|
+
props.accessor,
|
|
623
|
+
ts.factory.createToken(ts.SyntaxKind.QuestionQuestionEqualsToken),
|
|
624
|
+
ts.factory.createNewExpression(
|
|
625
|
+
ts.factory.createIdentifier("Map"),
|
|
626
|
+
[TypeFactory.keyword("any"), TypeFactory.keyword("any")],
|
|
627
|
+
[],
|
|
571
628
|
),
|
|
572
|
-
|
|
629
|
+
),
|
|
630
|
+
setter: () =>
|
|
631
|
+
ts.factory.createCallExpression(
|
|
632
|
+
IdentifierFactory.access(props.accessor)("set"),
|
|
633
|
+
undefined,
|
|
634
|
+
[
|
|
635
|
+
ts.factory.createIdentifier("entry.key"),
|
|
636
|
+
ts.factory.createIdentifier("entry.value"),
|
|
637
|
+
],
|
|
638
|
+
),
|
|
639
|
+
entry: props.entry,
|
|
640
|
+
required: props.required,
|
|
641
|
+
});
|
|
642
|
+
|
|
643
|
+
const decode_entry = (props: {
|
|
644
|
+
context: ITypiaContext;
|
|
645
|
+
importer: FunctionImporter;
|
|
646
|
+
initializer: () => ts.Expression;
|
|
647
|
+
setter: () => ts.Expression;
|
|
648
|
+
entry: Metadata.Entry;
|
|
649
|
+
required: boolean;
|
|
650
|
+
}): ts.Statement[] => {
|
|
651
|
+
const statements: ts.Statement[] = [
|
|
652
|
+
...(props.required
|
|
653
|
+
? []
|
|
654
|
+
: [ts.factory.createExpressionStatement(props.initializer())]),
|
|
655
|
+
StatementFactory.constant(
|
|
656
|
+
"piece",
|
|
657
|
+
ts.factory.createAdd(
|
|
573
658
|
ts.factory.createCallExpression(
|
|
574
|
-
IdentifierFactory.access(
|
|
659
|
+
IdentifierFactory.access(READER())("uint32"),
|
|
660
|
+
undefined,
|
|
575
661
|
undefined,
|
|
576
|
-
[
|
|
577
|
-
ts.factory.createIdentifier("entry.key"),
|
|
578
|
-
ts.factory.createIdentifier("entry.value"),
|
|
579
|
-
],
|
|
580
662
|
),
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
(importer: FunctionImporter) =>
|
|
586
|
-
(props: {
|
|
587
|
-
initializer: () => ts.Expression;
|
|
588
|
-
setter: () => ts.Expression;
|
|
589
|
-
}) =>
|
|
590
|
-
(map: Metadata.Entry, required: boolean): ts.Statement[] => {
|
|
591
|
-
const statements: ts.Statement[] = [
|
|
592
|
-
...(required
|
|
593
|
-
? []
|
|
594
|
-
: [ts.factory.createExpressionStatement(props.initializer())]),
|
|
595
|
-
StatementFactory.constant(
|
|
596
|
-
"piece",
|
|
597
|
-
ts.factory.createAdd(
|
|
598
|
-
ts.factory.createCallExpression(
|
|
599
|
-
IdentifierFactory.access(READER())("uint32"),
|
|
600
|
-
undefined,
|
|
601
|
-
undefined,
|
|
602
|
-
),
|
|
603
|
-
ts.factory.createCallExpression(
|
|
604
|
-
IdentifierFactory.access(READER())("index"),
|
|
605
|
-
undefined,
|
|
606
|
-
undefined,
|
|
607
|
-
),
|
|
663
|
+
ts.factory.createCallExpression(
|
|
664
|
+
IdentifierFactory.access(READER())("index"),
|
|
665
|
+
undefined,
|
|
666
|
+
undefined,
|
|
608
667
|
),
|
|
609
668
|
),
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
),
|
|
617
|
-
|
|
669
|
+
),
|
|
670
|
+
...write_object_function_body({
|
|
671
|
+
context: props.context,
|
|
672
|
+
importer: props.importer,
|
|
673
|
+
condition: ts.factory.createLessThan(
|
|
674
|
+
ts.factory.createCallExpression(
|
|
675
|
+
IdentifierFactory.access(READER())("index"),
|
|
676
|
+
undefined,
|
|
677
|
+
undefined,
|
|
618
678
|
),
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
679
|
+
ts.factory.createIdentifier("piece"),
|
|
680
|
+
),
|
|
681
|
+
tag: "kind",
|
|
682
|
+
output: "entry",
|
|
683
|
+
properties: [
|
|
622
684
|
MetadataProperty.create({
|
|
623
685
|
key: MetadataFactory.soleLiteral("key"),
|
|
624
|
-
value:
|
|
686
|
+
value: props.entry.key,
|
|
625
687
|
description: null,
|
|
626
688
|
jsDocTags: [],
|
|
627
689
|
}),
|
|
628
690
|
MetadataProperty.create({
|
|
629
691
|
key: MetadataFactory.soleLiteral("value"),
|
|
630
|
-
value:
|
|
692
|
+
value: props.entry.value,
|
|
631
693
|
description: null,
|
|
632
694
|
jsDocTags: [],
|
|
633
695
|
}),
|
|
634
|
-
]
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
),
|
|
641
|
-
|
|
642
|
-
|
|
696
|
+
],
|
|
697
|
+
}),
|
|
698
|
+
ts.factory.createExpressionStatement(props.setter()),
|
|
699
|
+
];
|
|
700
|
+
return [
|
|
701
|
+
ts.factory.createExpressionStatement(
|
|
702
|
+
ExpressionFactory.selfCall(ts.factory.createBlock(statements, true)),
|
|
703
|
+
),
|
|
704
|
+
];
|
|
705
|
+
};
|
|
643
706
|
}
|
|
644
707
|
|
|
645
708
|
const PREFIX = "$pd";
|