ts-proto 2.7.5 → 2.7.7
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/build/src/main.js +19 -8
- package/build/src/types.d.ts +1 -0
- package/build/src/types.js +5 -0
- package/package.json +1 -1
package/build/src/main.js
CHANGED
|
@@ -800,6 +800,7 @@ function makeExtensionClass(options) {
|
|
|
800
800
|
number: number;
|
|
801
801
|
tag: number;
|
|
802
802
|
singularTag?: number;
|
|
803
|
+
packedTag?: number;
|
|
803
804
|
encode?: (message: T) => Uint8Array[];
|
|
804
805
|
decode?: (tag: number, input: Uint8Array[]) => T;
|
|
805
806
|
repeated: boolean;
|
|
@@ -1340,7 +1341,7 @@ function generateEncode(ctx, fullName, messageDesc) {
|
|
|
1340
1341
|
`);
|
|
1341
1342
|
}
|
|
1342
1343
|
}
|
|
1343
|
-
else if ((0, types_1.
|
|
1344
|
+
else if ((0, types_1.packedField)(field, currentFile.isProto3Syntax) === undefined) {
|
|
1344
1345
|
const listWriteSnippet = (0, ts_poet_1.code) `
|
|
1345
1346
|
for (const v of ${messageProperty}) {
|
|
1346
1347
|
${writeSnippet("v!")};
|
|
@@ -1512,6 +1513,9 @@ function generateSetExtension(ctx, fullName) {
|
|
|
1512
1513
|
if (extension.singularTag !== undefined) {
|
|
1513
1514
|
delete message._unknownFields[extension.singularTag];
|
|
1514
1515
|
}
|
|
1516
|
+
if (extension.packedTag !== undefined) {
|
|
1517
|
+
delete message._unknownFields[extension.packedTag];
|
|
1518
|
+
}
|
|
1515
1519
|
}
|
|
1516
1520
|
|
|
1517
1521
|
if (encoded.length !== 0) {
|
|
@@ -1539,14 +1543,17 @@ function generateGetExtension(ctx, fullName) {
|
|
|
1539
1543
|
results = extension.decode!(extension.tag, list);
|
|
1540
1544
|
}
|
|
1541
1545
|
|
|
1542
|
-
if (extension.singularTag === undefined
|
|
1546
|
+
if (extension.singularTag === undefined ||
|
|
1547
|
+
extension.packedTag === undefined) {
|
|
1543
1548
|
return results;
|
|
1544
1549
|
}
|
|
1545
1550
|
|
|
1546
|
-
|
|
1551
|
+
const nonDefaultTag = (extension.singularTag === extension.tag) ?
|
|
1552
|
+
extension.packedTag : extension.singularTag;
|
|
1553
|
+
list = message._unknownFields[nonDefaultTag];
|
|
1547
1554
|
|
|
1548
1555
|
if (list !== undefined) {
|
|
1549
|
-
const results2 = extension.decode!(
|
|
1556
|
+
const results2 = extension.decode!(nonDefaultTag, list);
|
|
1550
1557
|
|
|
1551
1558
|
if (results !== undefined && (results as any).length !== 0) {
|
|
1552
1559
|
results = (results as any).concat(results2);
|
|
@@ -1561,15 +1568,19 @@ function generateGetExtension(ctx, fullName) {
|
|
|
1561
1568
|
}
|
|
1562
1569
|
function generateExtension(ctx, message, extension) {
|
|
1563
1570
|
const type = (0, types_1.toTypeName)(ctx, message, extension);
|
|
1571
|
+
const { currentFile } = ctx;
|
|
1564
1572
|
const packedTag = (0, types_1.isRepeated)(extension) && (0, types_1.packedType)(extension.type) !== undefined ? ((extension.number << 3) | 2) >>> 0 : undefined;
|
|
1565
1573
|
const singularTag = ((extension.number << 3) | (0, types_1.basicWireType)(extension.type)) >>> 0;
|
|
1566
|
-
const
|
|
1574
|
+
const packed = (0, types_1.isRepeated)(extension) && (0, types_1.packedField)(extension, currentFile.isProto3Syntax);
|
|
1575
|
+
const tag = packed ? packedTag : singularTag;
|
|
1567
1576
|
const chunks = [];
|
|
1568
1577
|
chunks.push((0, ts_poet_1.code) `{`);
|
|
1569
1578
|
chunks.push((0, ts_poet_1.code) `number: ${extension.number},`);
|
|
1570
1579
|
chunks.push((0, ts_poet_1.code) `tag: ${tag},`);
|
|
1571
|
-
if (packedTag !== undefined)
|
|
1580
|
+
if (packedTag !== undefined) {
|
|
1572
1581
|
chunks.push((0, ts_poet_1.code) `singularTag: ${singularTag},`);
|
|
1582
|
+
chunks.push((0, ts_poet_1.code) `packedTag: ${packedTag},`);
|
|
1583
|
+
}
|
|
1573
1584
|
chunks.push((0, ts_poet_1.code) `repeated: ${extension.label == ts_proto_descriptors_1.FieldDescriptorProto_Label.LABEL_REPEATED},`);
|
|
1574
1585
|
chunks.push((0, ts_poet_1.code) `packed: ${extension.options?.packed ? true : false},`);
|
|
1575
1586
|
const BinaryReader = (0, ts_poet_1.imp)("BinaryReader@@bufbuild/protobuf/wire");
|
|
@@ -1634,7 +1645,7 @@ function generateExtension(ctx, message, extension) {
|
|
|
1634
1645
|
}
|
|
1635
1646
|
const writeSnippet = getEncodeSnippet(ctx, extension);
|
|
1636
1647
|
if ((0, types_1.isRepeated)(extension)) {
|
|
1637
|
-
if (
|
|
1648
|
+
if (!packed) {
|
|
1638
1649
|
chunks.push((0, ts_poet_1.code) `
|
|
1639
1650
|
for (const v of value) {
|
|
1640
1651
|
const writer = new ${BinaryWriter}();
|
|
@@ -1688,7 +1699,7 @@ function generateExtension(ctx, message, extension) {
|
|
|
1688
1699
|
for (const buffer of input) {
|
|
1689
1700
|
const reader = new ${BinaryReader}(buffer);
|
|
1690
1701
|
`);
|
|
1691
|
-
if (
|
|
1702
|
+
if (packedTag === undefined) {
|
|
1692
1703
|
chunks.push((0, ts_poet_1.code) `
|
|
1693
1704
|
values.push(${readSnippet});
|
|
1694
1705
|
`);
|
package/build/src/types.d.ts
CHANGED
|
@@ -11,6 +11,7 @@ export declare function basicTypeName(ctx: Context, field: FieldDescriptorProto,
|
|
|
11
11
|
}): Code;
|
|
12
12
|
/** Returns the Reader method for the primitive's read/write call. */
|
|
13
13
|
export declare function toReaderCall(field: FieldDescriptorProto): string;
|
|
14
|
+
export declare function packedField(field: FieldDescriptorProto, isProto3Syntax: boolean): number | undefined;
|
|
14
15
|
export declare function packedType(type: FieldDescriptorProto_Type): number | undefined;
|
|
15
16
|
export declare function getFieldOptionsJsType(field: FieldDescriptorProto, options: Options): FieldDescriptorProto_Type | undefined;
|
|
16
17
|
export declare function defaultValue(ctx: Context, field: FieldDescriptorProto): any;
|
package/build/src/types.js
CHANGED
|
@@ -4,6 +4,7 @@ exports.basicWireType = basicWireType;
|
|
|
4
4
|
exports.basicLongWireType = basicLongWireType;
|
|
5
5
|
exports.basicTypeName = basicTypeName;
|
|
6
6
|
exports.toReaderCall = toReaderCall;
|
|
7
|
+
exports.packedField = packedField;
|
|
7
8
|
exports.packedType = packedType;
|
|
8
9
|
exports.getFieldOptionsJsType = getFieldOptionsJsType;
|
|
9
10
|
exports.defaultValue = defaultValue;
|
|
@@ -185,6 +186,10 @@ function toReaderCall(field) {
|
|
|
185
186
|
throw new Error(`Not a primitive field ${field}`);
|
|
186
187
|
}
|
|
187
188
|
}
|
|
189
|
+
function packedField(field, isProto3Syntax) {
|
|
190
|
+
const shouldPack = field.options?.packed ?? isProto3Syntax;
|
|
191
|
+
return shouldPack ? packedType(field.type) : undefined;
|
|
192
|
+
}
|
|
188
193
|
function packedType(type) {
|
|
189
194
|
switch (type) {
|
|
190
195
|
case ts_proto_descriptors_1.FieldDescriptorProto_Type.TYPE_DOUBLE:
|