ts-proto 1.159.3 → 1.160.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/build/main.js +53 -2
- package/package.json +1 -1
package/build/main.js
CHANGED
|
@@ -943,7 +943,24 @@ function getEncodeWriteSnippet(ctx, field) {
|
|
|
943
943
|
}
|
|
944
944
|
else if ((0, types_1.isLong)(field) && options.forceLong === options_1.LongOption.BIGINT) {
|
|
945
945
|
const tag = ((field.number << 3) | (0, types_1.basicWireType)(field.type)) >>> 0;
|
|
946
|
-
|
|
946
|
+
const fieldType = (0, types_1.toReaderCall)(field);
|
|
947
|
+
switch (fieldType) {
|
|
948
|
+
case "int64":
|
|
949
|
+
case "sint64":
|
|
950
|
+
case "sfixed64":
|
|
951
|
+
return (place) => (0, ts_poet_1.code) `if (BigInt.asIntN(64, ${place}) !== ${place}) {
|
|
952
|
+
throw new Error('value provided for field ${place} of type ${fieldType} too large');
|
|
953
|
+
}
|
|
954
|
+
writer.uint32(${tag}).${(0, types_1.toReaderCall)(field)}(${place}.toString())`;
|
|
955
|
+
case "uint64":
|
|
956
|
+
case "fixed64":
|
|
957
|
+
return (place) => (0, ts_poet_1.code) `if (BigInt.asUintN(64, ${place}) !== ${place}) {
|
|
958
|
+
throw new Error('value provided for field ${place} of type ${fieldType} too large');
|
|
959
|
+
}
|
|
960
|
+
writer.uint32(${tag}).${(0, types_1.toReaderCall)(field)}(${place}.toString())`;
|
|
961
|
+
default:
|
|
962
|
+
throw new Error(`unexpected BigInt type: ${fieldType}`);
|
|
963
|
+
}
|
|
947
964
|
}
|
|
948
965
|
else if ((0, types_1.isScalar)(field) || (0, types_1.isEnum)(field)) {
|
|
949
966
|
const tag = ((field.number << 3) | (0, types_1.basicWireType)(field.type)) >>> 0;
|
|
@@ -1080,13 +1097,47 @@ function generateEncode(ctx, fullName, messageDesc) {
|
|
|
1080
1097
|
// Ideally we'd reuse `writeSnippet` but it has tagging embedded inside of it.
|
|
1081
1098
|
const tag = ((field.number << 3) | 2) >>> 0;
|
|
1082
1099
|
const rhs = (x) => ((0, types_1.isLong)(field) && options.forceLong === options_1.LongOption.BIGINT ? `${x}.toString()` : x);
|
|
1083
|
-
|
|
1100
|
+
let listWriteSnippet = (0, ts_poet_1.code) `
|
|
1084
1101
|
writer.uint32(${tag}).fork();
|
|
1085
1102
|
for (const v of message.${fieldName}) {
|
|
1086
1103
|
writer.${(0, types_1.toReaderCall)(field)}(${rhs("v")});
|
|
1087
1104
|
}
|
|
1088
1105
|
writer.ldelim();
|
|
1089
1106
|
`;
|
|
1107
|
+
if ((0, types_1.isLong)(field) && options.forceLong === options_1.LongOption.BIGINT) {
|
|
1108
|
+
const fieldType = (0, types_1.toReaderCall)(field);
|
|
1109
|
+
switch (fieldType) {
|
|
1110
|
+
case "int64":
|
|
1111
|
+
case "sint64":
|
|
1112
|
+
case "sfixed64":
|
|
1113
|
+
listWriteSnippet = (0, ts_poet_1.code) `
|
|
1114
|
+
writer.uint32(${tag}).fork();
|
|
1115
|
+
for (const v of message.${fieldName}) {
|
|
1116
|
+
if (BigInt.asIntN(64, v) !== v) {
|
|
1117
|
+
throw new Error('a value provided in array field ${fieldName} of type ${fieldType} is too large');
|
|
1118
|
+
}
|
|
1119
|
+
writer.${(0, types_1.toReaderCall)(field)}(${rhs("v")});
|
|
1120
|
+
}
|
|
1121
|
+
writer.ldelim();
|
|
1122
|
+
`;
|
|
1123
|
+
break;
|
|
1124
|
+
case "uint64":
|
|
1125
|
+
case "fixed64":
|
|
1126
|
+
listWriteSnippet = (0, ts_poet_1.code) `
|
|
1127
|
+
writer.uint32(${tag}).fork();
|
|
1128
|
+
for (const v of message.${fieldName}) {
|
|
1129
|
+
if (BigInt.asUintN(64, v) !== v) {
|
|
1130
|
+
throw new Error('a value provided in array field ${fieldName} of type ${fieldType} is too large');
|
|
1131
|
+
}
|
|
1132
|
+
writer.${(0, types_1.toReaderCall)(field)}(${rhs("v")});
|
|
1133
|
+
}
|
|
1134
|
+
writer.ldelim();
|
|
1135
|
+
`;
|
|
1136
|
+
break;
|
|
1137
|
+
default:
|
|
1138
|
+
throw new Error(`unexpected BigInt type: ${fieldType}`);
|
|
1139
|
+
}
|
|
1140
|
+
}
|
|
1090
1141
|
if (isOptional) {
|
|
1091
1142
|
chunks.push((0, ts_poet_1.code) `
|
|
1092
1143
|
if (message.${fieldName} !== undefined && message.${fieldName}.length !== 0) {
|