@bufbuild/protobuf 1.5.0 → 1.6.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/dist/cjs/binary-encoding.d.ts +3 -4
- package/dist/cjs/binary-encoding.js +3 -4
- package/dist/cjs/binary-format.d.ts +10 -1
- package/dist/cjs/create-registry-from-desc.js +1 -0
- package/dist/cjs/field.d.ts +36 -2
- package/dist/cjs/google/protobuf/descriptor_pb.js +1 -1
- package/dist/cjs/google/protobuf/struct_pb.js +1 -1
- package/dist/cjs/google/protobuf/type_pb.js +1 -1
- package/dist/cjs/private/binary-format-common.d.ts +3 -2
- package/dist/cjs/private/binary-format-common.js +36 -15
- package/dist/cjs/private/binary-format-proto2.js +2 -2
- package/dist/cjs/private/binary-format-proto3.js +2 -2
- package/dist/cjs/proto-delimited.js +3 -2
- package/dist/cjs/proto2.js +7 -3
- package/dist/cjs/proto3.js +14 -10
- package/dist/esm/binary-encoding.d.ts +3 -4
- package/dist/esm/binary-encoding.js +3 -4
- package/dist/esm/binary-format.d.ts +10 -1
- package/dist/esm/create-registry-from-desc.js +2 -1
- package/dist/esm/field.d.ts +36 -2
- package/dist/esm/google/protobuf/descriptor_pb.js +1 -1
- package/dist/esm/google/protobuf/struct_pb.js +1 -1
- package/dist/esm/google/protobuf/type_pb.js +1 -1
- package/dist/esm/private/binary-format-common.d.ts +3 -2
- package/dist/esm/private/binary-format-common.js +36 -15
- package/dist/esm/private/binary-format-proto2.js +2 -2
- package/dist/esm/private/binary-format-proto3.js +2 -2
- package/dist/esm/proto-delimited.js +3 -2
- package/dist/esm/proto2.js +7 -3
- package/dist/esm/proto3.js +14 -10
- package/package.json +7 -3
|
@@ -25,13 +25,12 @@ export declare enum WireType {
|
|
|
25
25
|
*/
|
|
26
26
|
LengthDelimited = 2,
|
|
27
27
|
/**
|
|
28
|
-
*
|
|
29
|
-
*
|
|
28
|
+
* Start of a tag-delimited aggregate, such as a proto2 group, or a message
|
|
29
|
+
* in editions with message_encoding = DELIMITED.
|
|
30
30
|
*/
|
|
31
31
|
StartGroup = 3,
|
|
32
32
|
/**
|
|
33
|
-
*
|
|
34
|
-
* @deprecated
|
|
33
|
+
* End of a tag-delimited aggregate.
|
|
35
34
|
*/
|
|
36
35
|
EndGroup = 4,
|
|
37
36
|
/**
|
|
@@ -46,13 +46,12 @@ var WireType;
|
|
|
46
46
|
*/
|
|
47
47
|
WireType[WireType["LengthDelimited"] = 2] = "LengthDelimited";
|
|
48
48
|
/**
|
|
49
|
-
*
|
|
50
|
-
*
|
|
49
|
+
* Start of a tag-delimited aggregate, such as a proto2 group, or a message
|
|
50
|
+
* in editions with message_encoding = DELIMITED.
|
|
51
51
|
*/
|
|
52
52
|
WireType[WireType["StartGroup"] = 3] = "StartGroup";
|
|
53
53
|
/**
|
|
54
|
-
*
|
|
55
|
-
* @deprecated
|
|
54
|
+
* End of a tag-delimited aggregate.
|
|
56
55
|
*/
|
|
57
56
|
WireType[WireType["EndGroup"] = 4] = "EndGroup";
|
|
58
57
|
/**
|
|
@@ -16,8 +16,17 @@ export interface BinaryFormat {
|
|
|
16
16
|
makeWriteOptions(options?: Partial<BinaryWriteOptions>): Readonly<BinaryWriteOptions>;
|
|
17
17
|
/**
|
|
18
18
|
* Parse a message from binary data, merging fields.
|
|
19
|
+
*
|
|
20
|
+
* Supports two message encodings:
|
|
21
|
+
* - length-prefixed: delimitedMessageEncoding is false or omitted, and
|
|
22
|
+
* lengthOrEndTagFieldNo is the expected length of the message in the reader.
|
|
23
|
+
* - delimited: delimitedMessageEncoding is true, and lengthOrEndTagFieldNo is
|
|
24
|
+
* the field number in a tag with wire type end-group signalling the end of
|
|
25
|
+
* the message in the reader.
|
|
26
|
+
*
|
|
27
|
+
* delimitedMessageEncoding is optional for backwards compatibility.
|
|
19
28
|
*/
|
|
20
|
-
readMessage(message: Message, reader: IBinaryReader,
|
|
29
|
+
readMessage(message: Message, reader: IBinaryReader, lengthOrEndTagFieldNo: number, options: BinaryReadOptions, delimitedMessageEncoding?: boolean): void;
|
|
21
30
|
/**
|
|
22
31
|
* Serialize a message to binary data.
|
|
23
32
|
*/
|
|
@@ -234,6 +234,7 @@ function makeMessageFieldInfo(field, resolver) {
|
|
|
234
234
|
name: field.name,
|
|
235
235
|
jsonName: field.jsonName,
|
|
236
236
|
T: messageType,
|
|
237
|
+
delimited: field.proto.type == descriptor_pb_js_1.FieldDescriptorProto_Type.GROUP,
|
|
237
238
|
};
|
|
238
239
|
if (field.repeated) {
|
|
239
240
|
return Object.assign(Object.assign({}, base), { repeated: true, packed: field.packed, oneof: undefined });
|
package/dist/cjs/field.d.ts
CHANGED
|
@@ -23,6 +23,7 @@ import type { MessageType } from "./message-type.js";
|
|
|
23
23
|
*
|
|
24
24
|
* - "oneof": If the field is member of a oneof group.
|
|
25
25
|
* - "default": Only proto2: An explicit default value.
|
|
26
|
+
* - "delimited": Only proto2: Use the tag-delimited group encoding.
|
|
26
27
|
*/
|
|
27
28
|
export type FieldInfo = fiRules<fiScalar> | fiRules<fiEnum> | fiRules<fiMessage> | fiRules<fiMap>;
|
|
28
29
|
/**
|
|
@@ -46,6 +47,7 @@ export interface OneofInfo {
|
|
|
46
47
|
readonly packed: false;
|
|
47
48
|
readonly opt: false;
|
|
48
49
|
readonly default: undefined;
|
|
50
|
+
readonly delimited?: undefined;
|
|
49
51
|
readonly fields: readonly FieldInfo[];
|
|
50
52
|
/**
|
|
51
53
|
* Return field information by local name.
|
|
@@ -119,6 +121,13 @@ interface fiScalar extends fiShared {
|
|
|
119
121
|
* Only proto2: An explicit default value.
|
|
120
122
|
*/
|
|
121
123
|
readonly default: number | boolean | string | bigint | Uint8Array | undefined;
|
|
124
|
+
/**
|
|
125
|
+
* Serialize this message with the delimited format, also known as group
|
|
126
|
+
* encoding, as opposed to the standard length prefix.
|
|
127
|
+
*
|
|
128
|
+
* Only valid for message fields.
|
|
129
|
+
*/
|
|
130
|
+
readonly delimited?: undefined;
|
|
122
131
|
}
|
|
123
132
|
interface fiMessage extends fiShared {
|
|
124
133
|
readonly kind: "message";
|
|
@@ -138,6 +147,13 @@ interface fiMessage extends fiShared {
|
|
|
138
147
|
* An explicit default value (only proto2). Never set for messages.
|
|
139
148
|
*/
|
|
140
149
|
readonly default: undefined;
|
|
150
|
+
/**
|
|
151
|
+
* Serialize this message with the delimited format, also known as group
|
|
152
|
+
* encoding, as opposed to the standard length prefix.
|
|
153
|
+
*
|
|
154
|
+
* Only valid for message fields.
|
|
155
|
+
*/
|
|
156
|
+
readonly delimited?: boolean;
|
|
141
157
|
}
|
|
142
158
|
interface fiEnum extends fiShared {
|
|
143
159
|
readonly kind: "enum";
|
|
@@ -163,6 +179,13 @@ interface fiEnum extends fiShared {
|
|
|
163
179
|
* Only proto2: An explicit default value.
|
|
164
180
|
*/
|
|
165
181
|
readonly default: number | undefined;
|
|
182
|
+
/**
|
|
183
|
+
* Serialize this message with the delimited format, also known as group
|
|
184
|
+
* encoding, as opposed to the standard length prefix.
|
|
185
|
+
*
|
|
186
|
+
* Only valid for message fields.
|
|
187
|
+
*/
|
|
188
|
+
readonly delimited?: undefined;
|
|
166
189
|
}
|
|
167
190
|
interface fiMap extends fiShared {
|
|
168
191
|
readonly kind: "map";
|
|
@@ -199,6 +222,13 @@ interface fiMap extends fiShared {
|
|
|
199
222
|
* An explicit default value (only proto2). Never set for maps.
|
|
200
223
|
*/
|
|
201
224
|
readonly default: undefined;
|
|
225
|
+
/**
|
|
226
|
+
* Serialize this message with the delimited format, also known as group
|
|
227
|
+
* encoding, as opposed to the standard length prefix.
|
|
228
|
+
*
|
|
229
|
+
* Only valid for message fields.
|
|
230
|
+
*/
|
|
231
|
+
readonly delimited?: undefined;
|
|
202
232
|
}
|
|
203
233
|
type fiRules<T> = Omit<T, "oneof" | "repeat" | "repeated" | "packed" | "opt"> & ({
|
|
204
234
|
readonly repeated: false;
|
|
@@ -221,7 +251,7 @@ type fiRules<T> = Omit<T, "oneof" | "repeat" | "repeated" | "packed" | "opt"> &
|
|
|
221
251
|
readonly opt: false;
|
|
222
252
|
readonly oneof: OneofInfo;
|
|
223
253
|
});
|
|
224
|
-
type fiPartialRules<T extends fiScalar | fiMap | fiEnum | fiMessage> = Omit<T, "jsonName" | "localName" | "oneof" | "repeat" | "repeated" | "packed" | "opt" | "default" | "L"> & ({
|
|
254
|
+
type fiPartialRules<T extends fiScalar | fiMap | fiEnum | fiMessage> = Omit<T, "jsonName" | "localName" | "oneof" | "repeat" | "repeated" | "packed" | "opt" | "default" | "L" | "delimited"> & ({
|
|
225
255
|
readonly jsonName?: string;
|
|
226
256
|
readonly repeated?: false;
|
|
227
257
|
readonly packed?: false;
|
|
@@ -229,6 +259,7 @@ type fiPartialRules<T extends fiScalar | fiMap | fiEnum | fiMessage> = Omit<T, "
|
|
|
229
259
|
readonly oneof?: undefined;
|
|
230
260
|
default?: T["default"];
|
|
231
261
|
L?: LongType;
|
|
262
|
+
delimited?: boolean;
|
|
232
263
|
} | {
|
|
233
264
|
readonly jsonName?: string;
|
|
234
265
|
readonly repeated?: false;
|
|
@@ -237,6 +268,7 @@ type fiPartialRules<T extends fiScalar | fiMap | fiEnum | fiMessage> = Omit<T, "
|
|
|
237
268
|
readonly oneof?: undefined;
|
|
238
269
|
default?: T["default"];
|
|
239
270
|
L?: LongType;
|
|
271
|
+
delimited?: boolean;
|
|
240
272
|
} | {
|
|
241
273
|
readonly jsonName?: string;
|
|
242
274
|
readonly repeated?: boolean;
|
|
@@ -245,6 +277,7 @@ type fiPartialRules<T extends fiScalar | fiMap | fiEnum | fiMessage> = Omit<T, "
|
|
|
245
277
|
readonly oneof?: undefined;
|
|
246
278
|
default?: T["default"];
|
|
247
279
|
L?: LongType;
|
|
280
|
+
delimited?: boolean;
|
|
248
281
|
} | {
|
|
249
282
|
readonly jsonName?: string;
|
|
250
283
|
readonly repeated?: false;
|
|
@@ -253,6 +286,7 @@ type fiPartialRules<T extends fiScalar | fiMap | fiEnum | fiMessage> = Omit<T, "
|
|
|
253
286
|
readonly oneof: string;
|
|
254
287
|
default?: T["default"];
|
|
255
288
|
L?: LongType;
|
|
289
|
+
delimited?: boolean;
|
|
256
290
|
});
|
|
257
291
|
/**
|
|
258
292
|
* Scalar value types. This is a subset of field types declared by protobuf
|
|
@@ -273,7 +307,7 @@ export declare enum ScalarType {
|
|
|
273
307
|
UINT32 = 13,
|
|
274
308
|
SFIXED32 = 15,
|
|
275
309
|
SFIXED64 = 16,
|
|
276
|
-
SINT32 = 17
|
|
310
|
+
SINT32 = 17,// Uses ZigZag encoding.
|
|
277
311
|
SINT64 = 18
|
|
278
312
|
}
|
|
279
313
|
/**
|
|
@@ -21,7 +21,7 @@ exports.GeneratedCodeInfo_Annotation_Semantic = exports.GeneratedCodeInfo_Annota
|
|
|
21
21
|
// The messages in this file describe the definitions found in .proto files.
|
|
22
22
|
// A valid .proto file can be translated directly to a FileDescriptorProto
|
|
23
23
|
// without any other information (e.g. without reading its imports).
|
|
24
|
-
// @generated by protoc-gen-es v1.
|
|
24
|
+
// @generated by protoc-gen-es v1.6.0 with parameter "bootstrap_wkt=true,ts_nocheck=false,target=ts"
|
|
25
25
|
// @generated from file google/protobuf/descriptor.proto (package google.protobuf, syntax proto2)
|
|
26
26
|
/* eslint-disable */
|
|
27
27
|
const proto2_js_1 = require("../../proto2.js");
|
|
@@ -14,7 +14,7 @@
|
|
|
14
14
|
// limitations under the License.
|
|
15
15
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
16
16
|
exports.ListValue = exports.Value = exports.Struct = exports.NullValue = void 0;
|
|
17
|
-
// @generated by protoc-gen-es v1.
|
|
17
|
+
// @generated by protoc-gen-es v1.6.0 with parameter "bootstrap_wkt=true,ts_nocheck=false,target=ts"
|
|
18
18
|
// @generated from file google/protobuf/struct.proto (package google.protobuf, syntax proto3)
|
|
19
19
|
/* eslint-disable */
|
|
20
20
|
const proto3_js_1 = require("../../proto3.js");
|
|
@@ -14,7 +14,7 @@
|
|
|
14
14
|
// limitations under the License.
|
|
15
15
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
16
16
|
exports.Option = exports.EnumValue = exports.Enum = exports.Field_Cardinality = exports.Field_Kind = exports.Field = exports.Type = exports.Syntax = void 0;
|
|
17
|
-
// @generated by protoc-gen-es v1.
|
|
17
|
+
// @generated by protoc-gen-es v1.6.0 with parameter "bootstrap_wkt=true,ts_nocheck=false,target=ts"
|
|
18
18
|
// @generated from file google/protobuf/type.proto (package google.protobuf, syntax proto3)
|
|
19
19
|
/* eslint-disable */
|
|
20
20
|
const proto3_js_1 = require("../../proto3.js");
|
|
@@ -2,12 +2,13 @@ import type { IBinaryReader, IBinaryWriter } from "../binary-encoding.js";
|
|
|
2
2
|
import type { BinaryFormat, BinaryWriteOptions } from "../binary-format.js";
|
|
3
3
|
import type { FieldInfo } from "../field.js";
|
|
4
4
|
import { ScalarType } from "../field.js";
|
|
5
|
-
import type { MessageType } from "../message-type.js";
|
|
6
5
|
export declare function makeBinaryFormatCommon(): Omit<BinaryFormat, "writeMessage">;
|
|
7
6
|
export declare function readScalarLTString(reader: IBinaryReader, type: ScalarType): any;
|
|
8
7
|
export declare function writeMapEntry(writer: IBinaryWriter, options: BinaryWriteOptions, field: FieldInfo & {
|
|
9
8
|
kind: "map";
|
|
10
9
|
}, key: any, value: any): void;
|
|
11
|
-
export declare function writeMessageField(writer: IBinaryWriter, options: BinaryWriteOptions,
|
|
10
|
+
export declare function writeMessageField(writer: IBinaryWriter, options: BinaryWriteOptions, field: FieldInfo & {
|
|
11
|
+
kind: "message";
|
|
12
|
+
}, value: any): void;
|
|
12
13
|
export declare function writeScalar(writer: IBinaryWriter, type: ScalarType, fieldNo: number, value: any, emitIntrinsicDefault: boolean): void;
|
|
13
14
|
export declare function writePacked(writer: IBinaryWriter, type: ScalarType, fieldNo: number, value: any[]): void;
|
|
@@ -65,11 +65,19 @@ function makeBinaryFormatCommon() {
|
|
|
65
65
|
}
|
|
66
66
|
m[unknownFieldsSymbol].push({ no, wireType, data });
|
|
67
67
|
},
|
|
68
|
-
readMessage(message, reader,
|
|
68
|
+
readMessage(message, reader, lengthOrEndTagFieldNo, options, delimitedMessageEncoding) {
|
|
69
69
|
const type = message.getType();
|
|
70
|
-
|
|
70
|
+
// eslint-disable-next-line @typescript-eslint/strict-boolean-expressions
|
|
71
|
+
const end = delimitedMessageEncoding
|
|
72
|
+
? reader.len
|
|
73
|
+
: reader.pos + lengthOrEndTagFieldNo;
|
|
74
|
+
let fieldNo, wireType;
|
|
71
75
|
while (reader.pos < end) {
|
|
72
|
-
|
|
76
|
+
[fieldNo, wireType] = reader.tag();
|
|
77
|
+
if (wireType == binary_encoding_js_1.WireType.EndGroup) {
|
|
78
|
+
break;
|
|
79
|
+
}
|
|
80
|
+
const field = type.fields.find(fieldNo);
|
|
73
81
|
if (!field) {
|
|
74
82
|
const data = reader.skip(wireType);
|
|
75
83
|
if (options.readUnknownFields) {
|
|
@@ -117,14 +125,14 @@ function makeBinaryFormatCommon() {
|
|
|
117
125
|
const messageType = field.T;
|
|
118
126
|
if (repeated) {
|
|
119
127
|
// safe to assume presence of array, oneof cannot contain repeated values
|
|
120
|
-
target[localName].push(readMessageField(reader, new messageType(), options));
|
|
128
|
+
target[localName].push(readMessageField(reader, new messageType(), options, field));
|
|
121
129
|
}
|
|
122
130
|
else {
|
|
123
131
|
if (target[localName] instanceof message_js_1.Message) {
|
|
124
|
-
readMessageField(reader, target[localName], options);
|
|
132
|
+
readMessageField(reader, target[localName], options, field);
|
|
125
133
|
}
|
|
126
134
|
else {
|
|
127
|
-
target[localName] = readMessageField(reader, new messageType(), options);
|
|
135
|
+
target[localName] = readMessageField(reader, new messageType(), options, field);
|
|
128
136
|
if (messageType.fieldWrapper &&
|
|
129
137
|
!field.oneof &&
|
|
130
138
|
!field.repeated) {
|
|
@@ -140,15 +148,21 @@ function makeBinaryFormatCommon() {
|
|
|
140
148
|
break;
|
|
141
149
|
}
|
|
142
150
|
}
|
|
151
|
+
if (delimitedMessageEncoding && // eslint-disable-line @typescript-eslint/strict-boolean-expressions
|
|
152
|
+
(wireType != binary_encoding_js_1.WireType.EndGroup || fieldNo !== lengthOrEndTagFieldNo)) {
|
|
153
|
+
throw new Error(`invalid end group tag`);
|
|
154
|
+
}
|
|
143
155
|
},
|
|
144
156
|
};
|
|
145
157
|
}
|
|
146
158
|
exports.makeBinaryFormatCommon = makeBinaryFormatCommon;
|
|
147
159
|
// Read a message, avoiding MessageType.fromBinary() to re-use the
|
|
148
160
|
// BinaryReadOptions and the IBinaryReader.
|
|
149
|
-
function readMessageField(reader, message, options) {
|
|
161
|
+
function readMessageField(reader, message, options, field) {
|
|
150
162
|
const format = message.getType().runtime.bin;
|
|
151
|
-
|
|
163
|
+
const delimited = field === null || field === void 0 ? void 0 : field.delimited;
|
|
164
|
+
format.readMessage(message, reader, delimited ? field === null || field === void 0 ? void 0 : field.no : reader.uint32(), // eslint-disable-line @typescript-eslint/strict-boolean-expressions
|
|
165
|
+
options, delimited);
|
|
152
166
|
return message;
|
|
153
167
|
}
|
|
154
168
|
// Read a map field, expecting key field = 1, value field = 2
|
|
@@ -170,7 +184,7 @@ function readMapEntry(field, reader, options) {
|
|
|
170
184
|
val = reader.int32();
|
|
171
185
|
break;
|
|
172
186
|
case "message":
|
|
173
|
-
val = readMessageField(reader, new field.V.T(), options);
|
|
187
|
+
val = readMessageField(reader, new field.V.T(), options, undefined);
|
|
174
188
|
break;
|
|
175
189
|
}
|
|
176
190
|
break;
|
|
@@ -274,18 +288,25 @@ function writeMapEntry(writer, options, field, key, value) {
|
|
|
274
288
|
writeScalar(writer, field_js_1.ScalarType.INT32, 2, value, true);
|
|
275
289
|
break;
|
|
276
290
|
case "message":
|
|
277
|
-
|
|
291
|
+
writer.tag(2, binary_encoding_js_1.WireType.LengthDelimited).bytes(value.toBinary(options));
|
|
278
292
|
break;
|
|
279
293
|
}
|
|
280
294
|
writer.join();
|
|
281
295
|
}
|
|
282
296
|
exports.writeMapEntry = writeMapEntry;
|
|
283
|
-
function writeMessageField(writer, options,
|
|
297
|
+
function writeMessageField(writer, options, field, value) {
|
|
284
298
|
if (value !== undefined) {
|
|
285
|
-
const message = (0, field_wrapper_js_1.wrapField)(
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
299
|
+
const message = (0, field_wrapper_js_1.wrapField)(field.T, value);
|
|
300
|
+
// eslint-disable-next-line @typescript-eslint/strict-boolean-expressions
|
|
301
|
+
if (field === null || field === void 0 ? void 0 : field.delimited)
|
|
302
|
+
writer
|
|
303
|
+
.tag(field.no, binary_encoding_js_1.WireType.StartGroup)
|
|
304
|
+
.raw(message.toBinary(options))
|
|
305
|
+
.tag(field.no, binary_encoding_js_1.WireType.EndGroup);
|
|
306
|
+
else
|
|
307
|
+
writer
|
|
308
|
+
.tag(field.no, binary_encoding_js_1.WireType.LengthDelimited)
|
|
309
|
+
.bytes(message.toBinary(options));
|
|
289
310
|
}
|
|
290
311
|
}
|
|
291
312
|
exports.writeMessageField = writeMessageField;
|
|
@@ -65,11 +65,11 @@ function makeBinaryFormatProto2() {
|
|
|
65
65
|
case "message":
|
|
66
66
|
if (repeated) {
|
|
67
67
|
for (const item of value) {
|
|
68
|
-
(0, binary_format_common_js_1.writeMessageField)(writer, options, field
|
|
68
|
+
(0, binary_format_common_js_1.writeMessageField)(writer, options, field, item);
|
|
69
69
|
}
|
|
70
70
|
}
|
|
71
71
|
else {
|
|
72
|
-
(0, binary_format_common_js_1.writeMessageField)(writer, options, field
|
|
72
|
+
(0, binary_format_common_js_1.writeMessageField)(writer, options, field, value);
|
|
73
73
|
}
|
|
74
74
|
break;
|
|
75
75
|
case "map":
|
|
@@ -56,11 +56,11 @@ function makeBinaryFormatProto3() {
|
|
|
56
56
|
case "message":
|
|
57
57
|
if (repeated) {
|
|
58
58
|
for (const item of value) {
|
|
59
|
-
(0, binary_format_common_js_1.writeMessageField)(writer, options, field
|
|
59
|
+
(0, binary_format_common_js_1.writeMessageField)(writer, options, field, item);
|
|
60
60
|
}
|
|
61
61
|
}
|
|
62
62
|
else {
|
|
63
|
-
(0, binary_format_common_js_1.writeMessageField)(writer, options, field
|
|
63
|
+
(0, binary_format_common_js_1.writeMessageField)(writer, options, field, value);
|
|
64
64
|
}
|
|
65
65
|
break;
|
|
66
66
|
case "map":
|
|
@@ -23,8 +23,9 @@ var __await = (this && this.__await) || function (v) { return this instanceof __
|
|
|
23
23
|
var __asyncGenerator = (this && this.__asyncGenerator) || function (thisArg, _arguments, generator) {
|
|
24
24
|
if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined.");
|
|
25
25
|
var g = generator.apply(thisArg, _arguments || []), i, q = [];
|
|
26
|
-
return i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () { return this; }, i;
|
|
27
|
-
function
|
|
26
|
+
return i = {}, verb("next"), verb("throw"), verb("return", awaitReturn), i[Symbol.asyncIterator] = function () { return this; }, i;
|
|
27
|
+
function awaitReturn(f) { return function (v) { return Promise.resolve(v).then(f, reject); }; }
|
|
28
|
+
function verb(n, f) { if (g[n]) { i[n] = function (v) { return new Promise(function (a, b) { q.push([n, v, a, b]) > 1 || resume(n, v); }); }; if (f) i[n] = f(i[n]); } }
|
|
28
29
|
function resume(n, v) { try { step(g[n](v)); } catch (e) { settle(q[0][3], e); } }
|
|
29
30
|
function step(r) { r.value instanceof __await ? Promise.resolve(r.value.v).then(fulfill, reject) : settle(q[0][2], r); }
|
|
30
31
|
function fulfill(value) { resume("next", value); }
|
package/dist/cjs/proto2.js
CHANGED
|
@@ -57,7 +57,7 @@ exports.proto2 = (0, proto_runtime_js_1.makeProtoRuntime)("proto2", (0, json_for
|
|
|
57
57
|
} }));
|
|
58
58
|
/* eslint-disable @typescript-eslint/no-explicit-any,@typescript-eslint/no-unsafe-assignment,@typescript-eslint/no-unsafe-member-access,@typescript-eslint/no-unsafe-argument */
|
|
59
59
|
function normalizeFieldInfosProto2(fieldInfos) {
|
|
60
|
-
var _a, _b, _c, _d;
|
|
60
|
+
var _a, _b, _c, _d, _e;
|
|
61
61
|
const r = [];
|
|
62
62
|
let o;
|
|
63
63
|
for (const field of typeof fieldInfos == "function"
|
|
@@ -70,8 +70,6 @@ function normalizeFieldInfosProto2(fieldInfos) {
|
|
|
70
70
|
if (field.kind == "scalar") {
|
|
71
71
|
f.L = (_c = field.L) !== null && _c !== void 0 ? _c : field_js_2.LongType.BIGINT;
|
|
72
72
|
}
|
|
73
|
-
// In contrast to proto3, repeated fields are unpacked except when explicitly specified.
|
|
74
|
-
f.packed = (_d = field.packed) !== null && _d !== void 0 ? _d : false;
|
|
75
73
|
// We do not surface options at this time
|
|
76
74
|
// f.options = field.options ?? emptyReadonlyObject;
|
|
77
75
|
if (field.oneof !== undefined) {
|
|
@@ -82,6 +80,12 @@ function normalizeFieldInfosProto2(fieldInfos) {
|
|
|
82
80
|
f.oneof = o;
|
|
83
81
|
o.addField(f);
|
|
84
82
|
}
|
|
83
|
+
// proto2 specific:
|
|
84
|
+
if (field.kind == "message") {
|
|
85
|
+
f.delimited = (_d = field.delimited) !== null && _d !== void 0 ? _d : false;
|
|
86
|
+
}
|
|
87
|
+
// In contrast to proto3, repeated fields are unpacked except when explicitly specified.
|
|
88
|
+
f.packed = (_e = field.packed) !== null && _e !== void 0 ? _e : false;
|
|
85
89
|
r.push(f);
|
|
86
90
|
}
|
|
87
91
|
return r;
|
package/dist/cjs/proto3.js
CHANGED
|
@@ -73,16 +73,6 @@ function normalizeFieldInfosProto3(fieldInfos) {
|
|
|
73
73
|
if (field.kind == "scalar") {
|
|
74
74
|
f.L = (_c = field.L) !== null && _c !== void 0 ? _c : field_js_1.LongType.BIGINT;
|
|
75
75
|
}
|
|
76
|
-
// From the proto3 language guide:
|
|
77
|
-
// > In proto3, repeated fields of scalar numeric types are packed by default.
|
|
78
|
-
// This information is incomplete - according to the conformance tests, BOOL
|
|
79
|
-
// and ENUM are packed by default as well. This means only STRING and BYTES
|
|
80
|
-
// are not packed by default, which makes sense because they are length-delimited.
|
|
81
|
-
f.packed =
|
|
82
|
-
(_d = field.packed) !== null && _d !== void 0 ? _d : (field.kind == "enum" ||
|
|
83
|
-
(field.kind == "scalar" &&
|
|
84
|
-
field.T != field_js_1.ScalarType.BYTES &&
|
|
85
|
-
field.T != field_js_1.ScalarType.STRING));
|
|
86
76
|
// We do not surface options at this time
|
|
87
77
|
// f.options = field.options ?? emptyReadonlyObject;
|
|
88
78
|
if (field.oneof !== undefined) {
|
|
@@ -93,6 +83,20 @@ function normalizeFieldInfosProto3(fieldInfos) {
|
|
|
93
83
|
f.oneof = o;
|
|
94
84
|
o.addField(f);
|
|
95
85
|
}
|
|
86
|
+
// proto3 specific:
|
|
87
|
+
if (field.kind == "message") {
|
|
88
|
+
f.delimited = false;
|
|
89
|
+
}
|
|
90
|
+
// From the proto3 language guide:
|
|
91
|
+
// > In proto3, repeated fields of scalar numeric types are packed by default.
|
|
92
|
+
// This information is incomplete - according to the conformance tests, BOOL
|
|
93
|
+
// and ENUM are packed by default as well. This means only STRING and BYTES
|
|
94
|
+
// are not packed by default, which makes sense because they are length-delimited.
|
|
95
|
+
f.packed =
|
|
96
|
+
(_d = field.packed) !== null && _d !== void 0 ? _d : (field.kind == "enum" ||
|
|
97
|
+
(field.kind == "scalar" &&
|
|
98
|
+
field.T != field_js_1.ScalarType.BYTES &&
|
|
99
|
+
field.T != field_js_1.ScalarType.STRING));
|
|
96
100
|
r.push(f);
|
|
97
101
|
}
|
|
98
102
|
return r;
|
|
@@ -25,13 +25,12 @@ export declare enum WireType {
|
|
|
25
25
|
*/
|
|
26
26
|
LengthDelimited = 2,
|
|
27
27
|
/**
|
|
28
|
-
*
|
|
29
|
-
*
|
|
28
|
+
* Start of a tag-delimited aggregate, such as a proto2 group, or a message
|
|
29
|
+
* in editions with message_encoding = DELIMITED.
|
|
30
30
|
*/
|
|
31
31
|
StartGroup = 3,
|
|
32
32
|
/**
|
|
33
|
-
*
|
|
34
|
-
* @deprecated
|
|
33
|
+
* End of a tag-delimited aggregate.
|
|
35
34
|
*/
|
|
36
35
|
EndGroup = 4,
|
|
37
36
|
/**
|
|
@@ -43,13 +43,12 @@ export var WireType;
|
|
|
43
43
|
*/
|
|
44
44
|
WireType[WireType["LengthDelimited"] = 2] = "LengthDelimited";
|
|
45
45
|
/**
|
|
46
|
-
*
|
|
47
|
-
*
|
|
46
|
+
* Start of a tag-delimited aggregate, such as a proto2 group, or a message
|
|
47
|
+
* in editions with message_encoding = DELIMITED.
|
|
48
48
|
*/
|
|
49
49
|
WireType[WireType["StartGroup"] = 3] = "StartGroup";
|
|
50
50
|
/**
|
|
51
|
-
*
|
|
52
|
-
* @deprecated
|
|
51
|
+
* End of a tag-delimited aggregate.
|
|
53
52
|
*/
|
|
54
53
|
WireType[WireType["EndGroup"] = 4] = "EndGroup";
|
|
55
54
|
/**
|
|
@@ -16,8 +16,17 @@ export interface BinaryFormat {
|
|
|
16
16
|
makeWriteOptions(options?: Partial<BinaryWriteOptions>): Readonly<BinaryWriteOptions>;
|
|
17
17
|
/**
|
|
18
18
|
* Parse a message from binary data, merging fields.
|
|
19
|
+
*
|
|
20
|
+
* Supports two message encodings:
|
|
21
|
+
* - length-prefixed: delimitedMessageEncoding is false or omitted, and
|
|
22
|
+
* lengthOrEndTagFieldNo is the expected length of the message in the reader.
|
|
23
|
+
* - delimited: delimitedMessageEncoding is true, and lengthOrEndTagFieldNo is
|
|
24
|
+
* the field number in a tag with wire type end-group signalling the end of
|
|
25
|
+
* the message in the reader.
|
|
26
|
+
*
|
|
27
|
+
* delimitedMessageEncoding is optional for backwards compatibility.
|
|
19
28
|
*/
|
|
20
|
-
readMessage(message: Message, reader: IBinaryReader,
|
|
29
|
+
readMessage(message: Message, reader: IBinaryReader, lengthOrEndTagFieldNo: number, options: BinaryReadOptions, delimitedMessageEncoding?: boolean): void;
|
|
21
30
|
/**
|
|
22
31
|
* Serialize a message to binary data.
|
|
23
32
|
*/
|
|
@@ -24,7 +24,7 @@ import { FieldMask } from "./google/protobuf/field_mask_pb.js";
|
|
|
24
24
|
import { ListValue, NullValue, Struct, Value, } from "./google/protobuf/struct_pb.js";
|
|
25
25
|
import { getEnumType } from "./private/enum.js";
|
|
26
26
|
import { BoolValue, BytesValue, DoubleValue, FloatValue, Int32Value, Int64Value, StringValue, UInt32Value, UInt64Value, } from "./google/protobuf/wrappers_pb.js";
|
|
27
|
-
import { FileDescriptorSet } from "./google/protobuf/descriptor_pb.js";
|
|
27
|
+
import { FieldDescriptorProto_Type, FileDescriptorSet, } from "./google/protobuf/descriptor_pb.js";
|
|
28
28
|
import { createDescriptorSet } from "./create-descriptor-set.js";
|
|
29
29
|
// well-known message types with specialized JSON representation
|
|
30
30
|
const wkMessages = [
|
|
@@ -230,6 +230,7 @@ function makeMessageFieldInfo(field, resolver) {
|
|
|
230
230
|
name: field.name,
|
|
231
231
|
jsonName: field.jsonName,
|
|
232
232
|
T: messageType,
|
|
233
|
+
delimited: field.proto.type == FieldDescriptorProto_Type.GROUP,
|
|
233
234
|
};
|
|
234
235
|
if (field.repeated) {
|
|
235
236
|
return Object.assign(Object.assign({}, base), { repeated: true, packed: field.packed, oneof: undefined });
|
package/dist/esm/field.d.ts
CHANGED
|
@@ -23,6 +23,7 @@ import type { MessageType } from "./message-type.js";
|
|
|
23
23
|
*
|
|
24
24
|
* - "oneof": If the field is member of a oneof group.
|
|
25
25
|
* - "default": Only proto2: An explicit default value.
|
|
26
|
+
* - "delimited": Only proto2: Use the tag-delimited group encoding.
|
|
26
27
|
*/
|
|
27
28
|
export type FieldInfo = fiRules<fiScalar> | fiRules<fiEnum> | fiRules<fiMessage> | fiRules<fiMap>;
|
|
28
29
|
/**
|
|
@@ -46,6 +47,7 @@ export interface OneofInfo {
|
|
|
46
47
|
readonly packed: false;
|
|
47
48
|
readonly opt: false;
|
|
48
49
|
readonly default: undefined;
|
|
50
|
+
readonly delimited?: undefined;
|
|
49
51
|
readonly fields: readonly FieldInfo[];
|
|
50
52
|
/**
|
|
51
53
|
* Return field information by local name.
|
|
@@ -119,6 +121,13 @@ interface fiScalar extends fiShared {
|
|
|
119
121
|
* Only proto2: An explicit default value.
|
|
120
122
|
*/
|
|
121
123
|
readonly default: number | boolean | string | bigint | Uint8Array | undefined;
|
|
124
|
+
/**
|
|
125
|
+
* Serialize this message with the delimited format, also known as group
|
|
126
|
+
* encoding, as opposed to the standard length prefix.
|
|
127
|
+
*
|
|
128
|
+
* Only valid for message fields.
|
|
129
|
+
*/
|
|
130
|
+
readonly delimited?: undefined;
|
|
122
131
|
}
|
|
123
132
|
interface fiMessage extends fiShared {
|
|
124
133
|
readonly kind: "message";
|
|
@@ -138,6 +147,13 @@ interface fiMessage extends fiShared {
|
|
|
138
147
|
* An explicit default value (only proto2). Never set for messages.
|
|
139
148
|
*/
|
|
140
149
|
readonly default: undefined;
|
|
150
|
+
/**
|
|
151
|
+
* Serialize this message with the delimited format, also known as group
|
|
152
|
+
* encoding, as opposed to the standard length prefix.
|
|
153
|
+
*
|
|
154
|
+
* Only valid for message fields.
|
|
155
|
+
*/
|
|
156
|
+
readonly delimited?: boolean;
|
|
141
157
|
}
|
|
142
158
|
interface fiEnum extends fiShared {
|
|
143
159
|
readonly kind: "enum";
|
|
@@ -163,6 +179,13 @@ interface fiEnum extends fiShared {
|
|
|
163
179
|
* Only proto2: An explicit default value.
|
|
164
180
|
*/
|
|
165
181
|
readonly default: number | undefined;
|
|
182
|
+
/**
|
|
183
|
+
* Serialize this message with the delimited format, also known as group
|
|
184
|
+
* encoding, as opposed to the standard length prefix.
|
|
185
|
+
*
|
|
186
|
+
* Only valid for message fields.
|
|
187
|
+
*/
|
|
188
|
+
readonly delimited?: undefined;
|
|
166
189
|
}
|
|
167
190
|
interface fiMap extends fiShared {
|
|
168
191
|
readonly kind: "map";
|
|
@@ -199,6 +222,13 @@ interface fiMap extends fiShared {
|
|
|
199
222
|
* An explicit default value (only proto2). Never set for maps.
|
|
200
223
|
*/
|
|
201
224
|
readonly default: undefined;
|
|
225
|
+
/**
|
|
226
|
+
* Serialize this message with the delimited format, also known as group
|
|
227
|
+
* encoding, as opposed to the standard length prefix.
|
|
228
|
+
*
|
|
229
|
+
* Only valid for message fields.
|
|
230
|
+
*/
|
|
231
|
+
readonly delimited?: undefined;
|
|
202
232
|
}
|
|
203
233
|
type fiRules<T> = Omit<T, "oneof" | "repeat" | "repeated" | "packed" | "opt"> & ({
|
|
204
234
|
readonly repeated: false;
|
|
@@ -221,7 +251,7 @@ type fiRules<T> = Omit<T, "oneof" | "repeat" | "repeated" | "packed" | "opt"> &
|
|
|
221
251
|
readonly opt: false;
|
|
222
252
|
readonly oneof: OneofInfo;
|
|
223
253
|
});
|
|
224
|
-
type fiPartialRules<T extends fiScalar | fiMap | fiEnum | fiMessage> = Omit<T, "jsonName" | "localName" | "oneof" | "repeat" | "repeated" | "packed" | "opt" | "default" | "L"> & ({
|
|
254
|
+
type fiPartialRules<T extends fiScalar | fiMap | fiEnum | fiMessage> = Omit<T, "jsonName" | "localName" | "oneof" | "repeat" | "repeated" | "packed" | "opt" | "default" | "L" | "delimited"> & ({
|
|
225
255
|
readonly jsonName?: string;
|
|
226
256
|
readonly repeated?: false;
|
|
227
257
|
readonly packed?: false;
|
|
@@ -229,6 +259,7 @@ type fiPartialRules<T extends fiScalar | fiMap | fiEnum | fiMessage> = Omit<T, "
|
|
|
229
259
|
readonly oneof?: undefined;
|
|
230
260
|
default?: T["default"];
|
|
231
261
|
L?: LongType;
|
|
262
|
+
delimited?: boolean;
|
|
232
263
|
} | {
|
|
233
264
|
readonly jsonName?: string;
|
|
234
265
|
readonly repeated?: false;
|
|
@@ -237,6 +268,7 @@ type fiPartialRules<T extends fiScalar | fiMap | fiEnum | fiMessage> = Omit<T, "
|
|
|
237
268
|
readonly oneof?: undefined;
|
|
238
269
|
default?: T["default"];
|
|
239
270
|
L?: LongType;
|
|
271
|
+
delimited?: boolean;
|
|
240
272
|
} | {
|
|
241
273
|
readonly jsonName?: string;
|
|
242
274
|
readonly repeated?: boolean;
|
|
@@ -245,6 +277,7 @@ type fiPartialRules<T extends fiScalar | fiMap | fiEnum | fiMessage> = Omit<T, "
|
|
|
245
277
|
readonly oneof?: undefined;
|
|
246
278
|
default?: T["default"];
|
|
247
279
|
L?: LongType;
|
|
280
|
+
delimited?: boolean;
|
|
248
281
|
} | {
|
|
249
282
|
readonly jsonName?: string;
|
|
250
283
|
readonly repeated?: false;
|
|
@@ -253,6 +286,7 @@ type fiPartialRules<T extends fiScalar | fiMap | fiEnum | fiMessage> = Omit<T, "
|
|
|
253
286
|
readonly oneof: string;
|
|
254
287
|
default?: T["default"];
|
|
255
288
|
L?: LongType;
|
|
289
|
+
delimited?: boolean;
|
|
256
290
|
});
|
|
257
291
|
/**
|
|
258
292
|
* Scalar value types. This is a subset of field types declared by protobuf
|
|
@@ -273,7 +307,7 @@ export declare enum ScalarType {
|
|
|
273
307
|
UINT32 = 13,
|
|
274
308
|
SFIXED32 = 15,
|
|
275
309
|
SFIXED64 = 16,
|
|
276
|
-
SINT32 = 17
|
|
310
|
+
SINT32 = 17,// Uses ZigZag encoding.
|
|
277
311
|
SINT64 = 18
|
|
278
312
|
}
|
|
279
313
|
/**
|
|
@@ -18,7 +18,7 @@
|
|
|
18
18
|
// The messages in this file describe the definitions found in .proto files.
|
|
19
19
|
// A valid .proto file can be translated directly to a FileDescriptorProto
|
|
20
20
|
// without any other information (e.g. without reading its imports).
|
|
21
|
-
// @generated by protoc-gen-es v1.
|
|
21
|
+
// @generated by protoc-gen-es v1.6.0 with parameter "bootstrap_wkt=true,ts_nocheck=false,target=ts"
|
|
22
22
|
// @generated from file google/protobuf/descriptor.proto (package google.protobuf, syntax proto2)
|
|
23
23
|
/* eslint-disable */
|
|
24
24
|
import { proto2 } from "../../proto2.js";
|
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
12
|
// See the License for the specific language governing permissions and
|
|
13
13
|
// limitations under the License.
|
|
14
|
-
// @generated by protoc-gen-es v1.
|
|
14
|
+
// @generated by protoc-gen-es v1.6.0 with parameter "bootstrap_wkt=true,ts_nocheck=false,target=ts"
|
|
15
15
|
// @generated from file google/protobuf/struct.proto (package google.protobuf, syntax proto3)
|
|
16
16
|
/* eslint-disable */
|
|
17
17
|
import { proto3 } from "../../proto3.js";
|
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
12
|
// See the License for the specific language governing permissions and
|
|
13
13
|
// limitations under the License.
|
|
14
|
-
// @generated by protoc-gen-es v1.
|
|
14
|
+
// @generated by protoc-gen-es v1.6.0 with parameter "bootstrap_wkt=true,ts_nocheck=false,target=ts"
|
|
15
15
|
// @generated from file google/protobuf/type.proto (package google.protobuf, syntax proto3)
|
|
16
16
|
/* eslint-disable */
|
|
17
17
|
import { proto3 } from "../../proto3.js";
|
|
@@ -2,12 +2,13 @@ import type { IBinaryReader, IBinaryWriter } from "../binary-encoding.js";
|
|
|
2
2
|
import type { BinaryFormat, BinaryWriteOptions } from "../binary-format.js";
|
|
3
3
|
import type { FieldInfo } from "../field.js";
|
|
4
4
|
import { ScalarType } from "../field.js";
|
|
5
|
-
import type { MessageType } from "../message-type.js";
|
|
6
5
|
export declare function makeBinaryFormatCommon(): Omit<BinaryFormat, "writeMessage">;
|
|
7
6
|
export declare function readScalarLTString(reader: IBinaryReader, type: ScalarType): any;
|
|
8
7
|
export declare function writeMapEntry(writer: IBinaryWriter, options: BinaryWriteOptions, field: FieldInfo & {
|
|
9
8
|
kind: "map";
|
|
10
9
|
}, key: any, value: any): void;
|
|
11
|
-
export declare function writeMessageField(writer: IBinaryWriter, options: BinaryWriteOptions,
|
|
10
|
+
export declare function writeMessageField(writer: IBinaryWriter, options: BinaryWriteOptions, field: FieldInfo & {
|
|
11
|
+
kind: "message";
|
|
12
|
+
}, value: any): void;
|
|
12
13
|
export declare function writeScalar(writer: IBinaryWriter, type: ScalarType, fieldNo: number, value: any, emitIntrinsicDefault: boolean): void;
|
|
13
14
|
export declare function writePacked(writer: IBinaryWriter, type: ScalarType, fieldNo: number, value: any[]): void;
|
|
@@ -62,11 +62,19 @@ export function makeBinaryFormatCommon() {
|
|
|
62
62
|
}
|
|
63
63
|
m[unknownFieldsSymbol].push({ no, wireType, data });
|
|
64
64
|
},
|
|
65
|
-
readMessage(message, reader,
|
|
65
|
+
readMessage(message, reader, lengthOrEndTagFieldNo, options, delimitedMessageEncoding) {
|
|
66
66
|
const type = message.getType();
|
|
67
|
-
|
|
67
|
+
// eslint-disable-next-line @typescript-eslint/strict-boolean-expressions
|
|
68
|
+
const end = delimitedMessageEncoding
|
|
69
|
+
? reader.len
|
|
70
|
+
: reader.pos + lengthOrEndTagFieldNo;
|
|
71
|
+
let fieldNo, wireType;
|
|
68
72
|
while (reader.pos < end) {
|
|
69
|
-
|
|
73
|
+
[fieldNo, wireType] = reader.tag();
|
|
74
|
+
if (wireType == WireType.EndGroup) {
|
|
75
|
+
break;
|
|
76
|
+
}
|
|
77
|
+
const field = type.fields.find(fieldNo);
|
|
70
78
|
if (!field) {
|
|
71
79
|
const data = reader.skip(wireType);
|
|
72
80
|
if (options.readUnknownFields) {
|
|
@@ -114,14 +122,14 @@ export function makeBinaryFormatCommon() {
|
|
|
114
122
|
const messageType = field.T;
|
|
115
123
|
if (repeated) {
|
|
116
124
|
// safe to assume presence of array, oneof cannot contain repeated values
|
|
117
|
-
target[localName].push(readMessageField(reader, new messageType(), options));
|
|
125
|
+
target[localName].push(readMessageField(reader, new messageType(), options, field));
|
|
118
126
|
}
|
|
119
127
|
else {
|
|
120
128
|
if (target[localName] instanceof Message) {
|
|
121
|
-
readMessageField(reader, target[localName], options);
|
|
129
|
+
readMessageField(reader, target[localName], options, field);
|
|
122
130
|
}
|
|
123
131
|
else {
|
|
124
|
-
target[localName] = readMessageField(reader, new messageType(), options);
|
|
132
|
+
target[localName] = readMessageField(reader, new messageType(), options, field);
|
|
125
133
|
if (messageType.fieldWrapper &&
|
|
126
134
|
!field.oneof &&
|
|
127
135
|
!field.repeated) {
|
|
@@ -137,14 +145,20 @@ export function makeBinaryFormatCommon() {
|
|
|
137
145
|
break;
|
|
138
146
|
}
|
|
139
147
|
}
|
|
148
|
+
if (delimitedMessageEncoding && // eslint-disable-line @typescript-eslint/strict-boolean-expressions
|
|
149
|
+
(wireType != WireType.EndGroup || fieldNo !== lengthOrEndTagFieldNo)) {
|
|
150
|
+
throw new Error(`invalid end group tag`);
|
|
151
|
+
}
|
|
140
152
|
},
|
|
141
153
|
};
|
|
142
154
|
}
|
|
143
155
|
// Read a message, avoiding MessageType.fromBinary() to re-use the
|
|
144
156
|
// BinaryReadOptions and the IBinaryReader.
|
|
145
|
-
function readMessageField(reader, message, options) {
|
|
157
|
+
function readMessageField(reader, message, options, field) {
|
|
146
158
|
const format = message.getType().runtime.bin;
|
|
147
|
-
|
|
159
|
+
const delimited = field === null || field === void 0 ? void 0 : field.delimited;
|
|
160
|
+
format.readMessage(message, reader, delimited ? field === null || field === void 0 ? void 0 : field.no : reader.uint32(), // eslint-disable-line @typescript-eslint/strict-boolean-expressions
|
|
161
|
+
options, delimited);
|
|
148
162
|
return message;
|
|
149
163
|
}
|
|
150
164
|
// Read a map field, expecting key field = 1, value field = 2
|
|
@@ -166,7 +180,7 @@ function readMapEntry(field, reader, options) {
|
|
|
166
180
|
val = reader.int32();
|
|
167
181
|
break;
|
|
168
182
|
case "message":
|
|
169
|
-
val = readMessageField(reader, new field.V.T(), options);
|
|
183
|
+
val = readMessageField(reader, new field.V.T(), options, undefined);
|
|
170
184
|
break;
|
|
171
185
|
}
|
|
172
186
|
break;
|
|
@@ -269,17 +283,24 @@ export function writeMapEntry(writer, options, field, key, value) {
|
|
|
269
283
|
writeScalar(writer, ScalarType.INT32, 2, value, true);
|
|
270
284
|
break;
|
|
271
285
|
case "message":
|
|
272
|
-
|
|
286
|
+
writer.tag(2, WireType.LengthDelimited).bytes(value.toBinary(options));
|
|
273
287
|
break;
|
|
274
288
|
}
|
|
275
289
|
writer.join();
|
|
276
290
|
}
|
|
277
|
-
export function writeMessageField(writer, options,
|
|
291
|
+
export function writeMessageField(writer, options, field, value) {
|
|
278
292
|
if (value !== undefined) {
|
|
279
|
-
const message = wrapField(
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
293
|
+
const message = wrapField(field.T, value);
|
|
294
|
+
// eslint-disable-next-line @typescript-eslint/strict-boolean-expressions
|
|
295
|
+
if (field === null || field === void 0 ? void 0 : field.delimited)
|
|
296
|
+
writer
|
|
297
|
+
.tag(field.no, WireType.StartGroup)
|
|
298
|
+
.raw(message.toBinary(options))
|
|
299
|
+
.tag(field.no, WireType.EndGroup);
|
|
300
|
+
else
|
|
301
|
+
writer
|
|
302
|
+
.tag(field.no, WireType.LengthDelimited)
|
|
303
|
+
.bytes(message.toBinary(options));
|
|
283
304
|
}
|
|
284
305
|
}
|
|
285
306
|
export function writeScalar(writer, type, fieldNo, value, emitIntrinsicDefault) {
|
|
@@ -62,11 +62,11 @@ export function makeBinaryFormatProto2() {
|
|
|
62
62
|
case "message":
|
|
63
63
|
if (repeated) {
|
|
64
64
|
for (const item of value) {
|
|
65
|
-
writeMessageField(writer, options, field
|
|
65
|
+
writeMessageField(writer, options, field, item);
|
|
66
66
|
}
|
|
67
67
|
}
|
|
68
68
|
else {
|
|
69
|
-
writeMessageField(writer, options, field
|
|
69
|
+
writeMessageField(writer, options, field, value);
|
|
70
70
|
}
|
|
71
71
|
break;
|
|
72
72
|
case "map":
|
|
@@ -53,11 +53,11 @@ export function makeBinaryFormatProto3() {
|
|
|
53
53
|
case "message":
|
|
54
54
|
if (repeated) {
|
|
55
55
|
for (const item of value) {
|
|
56
|
-
writeMessageField(writer, options, field
|
|
56
|
+
writeMessageField(writer, options, field, item);
|
|
57
57
|
}
|
|
58
58
|
}
|
|
59
59
|
else {
|
|
60
|
-
writeMessageField(writer, options, field
|
|
60
|
+
writeMessageField(writer, options, field, value);
|
|
61
61
|
}
|
|
62
62
|
break;
|
|
63
63
|
case "map":
|
|
@@ -22,8 +22,9 @@ var __await = (this && this.__await) || function (v) { return this instanceof __
|
|
|
22
22
|
var __asyncGenerator = (this && this.__asyncGenerator) || function (thisArg, _arguments, generator) {
|
|
23
23
|
if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined.");
|
|
24
24
|
var g = generator.apply(thisArg, _arguments || []), i, q = [];
|
|
25
|
-
return i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () { return this; }, i;
|
|
26
|
-
function
|
|
25
|
+
return i = {}, verb("next"), verb("throw"), verb("return", awaitReturn), i[Symbol.asyncIterator] = function () { return this; }, i;
|
|
26
|
+
function awaitReturn(f) { return function (v) { return Promise.resolve(v).then(f, reject); }; }
|
|
27
|
+
function verb(n, f) { if (g[n]) { i[n] = function (v) { return new Promise(function (a, b) { q.push([n, v, a, b]) > 1 || resume(n, v); }); }; if (f) i[n] = f(i[n]); } }
|
|
27
28
|
function resume(n, v) { try { step(g[n](v)); } catch (e) { settle(q[0][3], e); } }
|
|
28
29
|
function step(r) { r.value instanceof __await ? Promise.resolve(r.value.v).then(fulfill, reject) : settle(q[0][2], r); }
|
|
29
30
|
function fulfill(value) { resume("next", value); }
|
package/dist/esm/proto2.js
CHANGED
|
@@ -54,7 +54,7 @@ export const proto2 = makeProtoRuntime("proto2", makeJsonFormatProto2(), makeBin
|
|
|
54
54
|
} }));
|
|
55
55
|
/* eslint-disable @typescript-eslint/no-explicit-any,@typescript-eslint/no-unsafe-assignment,@typescript-eslint/no-unsafe-member-access,@typescript-eslint/no-unsafe-argument */
|
|
56
56
|
function normalizeFieldInfosProto2(fieldInfos) {
|
|
57
|
-
var _a, _b, _c, _d;
|
|
57
|
+
var _a, _b, _c, _d, _e;
|
|
58
58
|
const r = [];
|
|
59
59
|
let o;
|
|
60
60
|
for (const field of typeof fieldInfos == "function"
|
|
@@ -67,8 +67,6 @@ function normalizeFieldInfosProto2(fieldInfos) {
|
|
|
67
67
|
if (field.kind == "scalar") {
|
|
68
68
|
f.L = (_c = field.L) !== null && _c !== void 0 ? _c : LongType.BIGINT;
|
|
69
69
|
}
|
|
70
|
-
// In contrast to proto3, repeated fields are unpacked except when explicitly specified.
|
|
71
|
-
f.packed = (_d = field.packed) !== null && _d !== void 0 ? _d : false;
|
|
72
70
|
// We do not surface options at this time
|
|
73
71
|
// f.options = field.options ?? emptyReadonlyObject;
|
|
74
72
|
if (field.oneof !== undefined) {
|
|
@@ -79,6 +77,12 @@ function normalizeFieldInfosProto2(fieldInfos) {
|
|
|
79
77
|
f.oneof = o;
|
|
80
78
|
o.addField(f);
|
|
81
79
|
}
|
|
80
|
+
// proto2 specific:
|
|
81
|
+
if (field.kind == "message") {
|
|
82
|
+
f.delimited = (_d = field.delimited) !== null && _d !== void 0 ? _d : false;
|
|
83
|
+
}
|
|
84
|
+
// In contrast to proto3, repeated fields are unpacked except when explicitly specified.
|
|
85
|
+
f.packed = (_e = field.packed) !== null && _e !== void 0 ? _e : false;
|
|
82
86
|
r.push(f);
|
|
83
87
|
}
|
|
84
88
|
return r;
|
package/dist/esm/proto3.js
CHANGED
|
@@ -70,16 +70,6 @@ function normalizeFieldInfosProto3(fieldInfos) {
|
|
|
70
70
|
if (field.kind == "scalar") {
|
|
71
71
|
f.L = (_c = field.L) !== null && _c !== void 0 ? _c : LongType.BIGINT;
|
|
72
72
|
}
|
|
73
|
-
// From the proto3 language guide:
|
|
74
|
-
// > In proto3, repeated fields of scalar numeric types are packed by default.
|
|
75
|
-
// This information is incomplete - according to the conformance tests, BOOL
|
|
76
|
-
// and ENUM are packed by default as well. This means only STRING and BYTES
|
|
77
|
-
// are not packed by default, which makes sense because they are length-delimited.
|
|
78
|
-
f.packed =
|
|
79
|
-
(_d = field.packed) !== null && _d !== void 0 ? _d : (field.kind == "enum" ||
|
|
80
|
-
(field.kind == "scalar" &&
|
|
81
|
-
field.T != ScalarType.BYTES &&
|
|
82
|
-
field.T != ScalarType.STRING));
|
|
83
73
|
// We do not surface options at this time
|
|
84
74
|
// f.options = field.options ?? emptyReadonlyObject;
|
|
85
75
|
if (field.oneof !== undefined) {
|
|
@@ -90,6 +80,20 @@ function normalizeFieldInfosProto3(fieldInfos) {
|
|
|
90
80
|
f.oneof = o;
|
|
91
81
|
o.addField(f);
|
|
92
82
|
}
|
|
83
|
+
// proto3 specific:
|
|
84
|
+
if (field.kind == "message") {
|
|
85
|
+
f.delimited = false;
|
|
86
|
+
}
|
|
87
|
+
// From the proto3 language guide:
|
|
88
|
+
// > In proto3, repeated fields of scalar numeric types are packed by default.
|
|
89
|
+
// This information is incomplete - according to the conformance tests, BOOL
|
|
90
|
+
// and ENUM are packed by default as well. This means only STRING and BYTES
|
|
91
|
+
// are not packed by default, which makes sense because they are length-delimited.
|
|
92
|
+
f.packed =
|
|
93
|
+
(_d = field.packed) !== null && _d !== void 0 ? _d : (field.kind == "enum" ||
|
|
94
|
+
(field.kind == "scalar" &&
|
|
95
|
+
field.T != ScalarType.BYTES &&
|
|
96
|
+
field.T != ScalarType.STRING));
|
|
93
97
|
r.push(f);
|
|
94
98
|
}
|
|
95
99
|
return r;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@bufbuild/protobuf",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.6.0",
|
|
4
4
|
"license": "(Apache-2.0 AND BSD-3-Clause)",
|
|
5
5
|
"description": "A complete implementation of Protocol Buffers in TypeScript, suitable for web browsers and Node.js.",
|
|
6
6
|
"repository": {
|
|
@@ -25,9 +25,13 @@
|
|
|
25
25
|
"main": "./dist/cjs/index.js",
|
|
26
26
|
"exports": {
|
|
27
27
|
".": {
|
|
28
|
+
"node": {
|
|
29
|
+
"import": "./dist/proxy/index.js",
|
|
30
|
+
"require": "./dist/cjs/index.js"
|
|
31
|
+
},
|
|
28
32
|
"module": "./dist/esm/index.js",
|
|
29
|
-
"
|
|
30
|
-
"
|
|
33
|
+
"import": "./dist/esm/index.js",
|
|
34
|
+
"require": "./dist/cjs/index.js"
|
|
31
35
|
}
|
|
32
36
|
},
|
|
33
37
|
"devDependencies": {
|