diff --git a/packages/protobuf-bench/README.md b/packages/protobuf-bench/README.md index 888a4dcae..7ac943b1d 100644 --- a/packages/protobuf-bench/README.md +++ b/packages/protobuf-bench/README.md @@ -10,5 +10,5 @@ server would usually do. | code generator | bundle size | minified | compressed | |---------------------|------------------------:|-----------------------:|-------------------:| -| protobuf-es | 90,449 b | 38,193 b | 9,801 b | +| protobuf-es | 91,410 b | 38,462 b | 9,870 b | | protobuf-javascript | 394,384 b | 288,654 b | 45,122 b | diff --git a/packages/protobuf-conformance/src/gen/google/protobuf/test_messages_proto2_pb.ts b/packages/protobuf-conformance/src/gen/google/protobuf/test_messages_proto2_pb.ts index a211f3f8f..e2d390ef2 100644 --- a/packages/protobuf-conformance/src/gen/google/protobuf/test_messages_proto2_pb.ts +++ b/packages/protobuf-conformance/src/gen/google/protobuf/test_messages_proto2_pb.ts @@ -860,7 +860,7 @@ export class TestAllTypesProto2 extends Message { { no: 117, name: "oneof_float", kind: "scalar", T: 2 /* ScalarType.FLOAT */, oneof: "oneof_field" }, { no: 118, name: "oneof_double", kind: "scalar", T: 1 /* ScalarType.DOUBLE */, oneof: "oneof_field" }, { no: 119, name: "oneof_enum", kind: "enum", T: proto2.getEnumType(TestAllTypesProto2_NestedEnum), oneof: "oneof_field" }, - { no: 201, name: "data", kind: "message", T: TestAllTypesProto2_Data, opt: true }, + { no: 201, name: "data", kind: "message", T: TestAllTypesProto2_Data, delimited: true, opt: true }, { no: 241, name: "default_int32", kind: "scalar", T: 5 /* ScalarType.INT32 */, opt: true, default: -123456789 }, { no: 242, name: "default_int64", kind: "scalar", T: 3 /* ScalarType.INT64 */, opt: true, default: protoInt64.parse("-9123456789123456789") }, { no: 243, name: "default_uint32", kind: "scalar", T: 13 /* ScalarType.UINT32 */, opt: true, default: 2123456789 }, @@ -1224,7 +1224,7 @@ export class UnknownToTestAllTypes extends Message { { no: 1001, name: "optional_int32", kind: "scalar", T: 5 /* ScalarType.INT32 */, opt: true }, { no: 1002, name: "optional_string", kind: "scalar", T: 9 /* ScalarType.STRING */, opt: true }, { no: 1003, name: "nested_message", kind: "message", T: ForeignMessageProto2, opt: true }, - { no: 1004, name: "optionalgroup", kind: "message", T: UnknownToTestAllTypes_OptionalGroup, opt: true }, + { no: 1004, name: "optionalgroup", kind: "message", T: UnknownToTestAllTypes_OptionalGroup, delimited: true, opt: true }, { no: 1006, name: "optional_bool", kind: "scalar", T: 8 /* ScalarType.BOOL */, opt: true }, { no: 1011, name: "repeated_int32", kind: "scalar", T: 5 /* ScalarType.INT32 */, repeated: true }, ]); @@ -1685,7 +1685,7 @@ export class TestAllRequiredTypesProto2 extends Message { static equals(a: Proto2ChildMessage | PlainMessage | undefined, b: Proto2ChildMessage | PlainMessage | undefined): boolean; } +/** + * @generated from message spec.Proto2GroupsMessage + */ +export declare class Proto2GroupsMessage extends Message { + /** + * @generated from field: optional spec.Proto2GroupsMessage.Group group = 1; + */ + group?: Proto2GroupsMessage_Group; + + /** + * @generated from field: repeated spec.Proto2GroupsMessage.RepeatedGroup repeatedgroup = 2; + */ + repeatedgroup: Proto2GroupsMessage_RepeatedGroup[]; + + /** + * @generated from oneof spec.Proto2GroupsMessage.oneof_with_group + */ + oneofWithGroup: { + /** + * @generated from field: spec.Proto2GroupsMessage.OneofGroup oneofgroup = 3; + */ + value: Proto2GroupsMessage_OneofGroup; + case: "oneofgroup"; + } | { case: undefined; value?: undefined }; + + /** + * @generated from field: optional spec.Proto2GroupsMessage.Group message_field_using_group = 4; + */ + messageFieldUsingGroup?: Proto2GroupsMessage_Group; + + /** + * @generated from field: optional spec.Proto2GroupsMessage.Group.NestedGroup message_field_using_nested_group = 5; + */ + messageFieldUsingNestedGroup?: Proto2GroupsMessage_Group_NestedGroup; + + constructor(data?: PartialMessage); + + static readonly runtime: typeof proto2; + static readonly typeName = "spec.Proto2GroupsMessage"; + static readonly fields: FieldList; + + static fromBinary(bytes: Uint8Array, options?: Partial): Proto2GroupsMessage; + + static fromJson(jsonValue: JsonValue, options?: Partial): Proto2GroupsMessage; + + static fromJsonString(jsonString: string, options?: Partial): Proto2GroupsMessage; + + static equals(a: Proto2GroupsMessage | PlainMessage | undefined, b: Proto2GroupsMessage | PlainMessage | undefined): boolean; +} + +/** + * @generated from message spec.Proto2GroupsMessage.Group + */ +export declare class Proto2GroupsMessage_Group extends Message { + /** + * @generated from field: optional int32 int32_field = 1; + */ + int32Field?: number; + + /** + * @generated from field: optional spec.Proto2GroupsMessage.Group.NestedGroup nestedgroup = 2; + */ + nestedgroup?: Proto2GroupsMessage_Group_NestedGroup; + + constructor(data?: PartialMessage); + + static readonly runtime: typeof proto2; + static readonly typeName = "spec.Proto2GroupsMessage.Group"; + static readonly fields: FieldList; + + static fromBinary(bytes: Uint8Array, options?: Partial): Proto2GroupsMessage_Group; + + static fromJson(jsonValue: JsonValue, options?: Partial): Proto2GroupsMessage_Group; + + static fromJsonString(jsonString: string, options?: Partial): Proto2GroupsMessage_Group; + + static equals(a: Proto2GroupsMessage_Group | PlainMessage | undefined, b: Proto2GroupsMessage_Group | PlainMessage | undefined): boolean; +} + +/** + * @generated from message spec.Proto2GroupsMessage.Group.NestedGroup + */ +export declare class Proto2GroupsMessage_Group_NestedGroup extends Message { + /** + * @generated from field: optional string string_field = 1; + */ + stringField?: string; + + constructor(data?: PartialMessage); + + static readonly runtime: typeof proto2; + static readonly typeName = "spec.Proto2GroupsMessage.Group.NestedGroup"; + static readonly fields: FieldList; + + static fromBinary(bytes: Uint8Array, options?: Partial): Proto2GroupsMessage_Group_NestedGroup; + + static fromJson(jsonValue: JsonValue, options?: Partial): Proto2GroupsMessage_Group_NestedGroup; + + static fromJsonString(jsonString: string, options?: Partial): Proto2GroupsMessage_Group_NestedGroup; + + static equals(a: Proto2GroupsMessage_Group_NestedGroup | PlainMessage | undefined, b: Proto2GroupsMessage_Group_NestedGroup | PlainMessage | undefined): boolean; +} + +/** + * @generated from message spec.Proto2GroupsMessage.RepeatedGroup + */ +export declare class Proto2GroupsMessage_RepeatedGroup extends Message { + /** + * @generated from field: optional int32 int32_field = 1; + */ + int32Field?: number; + + constructor(data?: PartialMessage); + + static readonly runtime: typeof proto2; + static readonly typeName = "spec.Proto2GroupsMessage.RepeatedGroup"; + static readonly fields: FieldList; + + static fromBinary(bytes: Uint8Array, options?: Partial): Proto2GroupsMessage_RepeatedGroup; + + static fromJson(jsonValue: JsonValue, options?: Partial): Proto2GroupsMessage_RepeatedGroup; + + static fromJsonString(jsonString: string, options?: Partial): Proto2GroupsMessage_RepeatedGroup; + + static equals(a: Proto2GroupsMessage_RepeatedGroup | PlainMessage | undefined, b: Proto2GroupsMessage_RepeatedGroup | PlainMessage | undefined): boolean; +} + +/** + * @generated from message spec.Proto2GroupsMessage.OneofGroup + */ +export declare class Proto2GroupsMessage_OneofGroup extends Message { + /** + * @generated from field: optional bool bool_field = 1; + */ + boolField?: boolean; + + constructor(data?: PartialMessage); + + static readonly runtime: typeof proto2; + static readonly typeName = "spec.Proto2GroupsMessage.OneofGroup"; + static readonly fields: FieldList; + + static fromBinary(bytes: Uint8Array, options?: Partial): Proto2GroupsMessage_OneofGroup; + + static fromJson(jsonValue: JsonValue, options?: Partial): Proto2GroupsMessage_OneofGroup; + + static fromJsonString(jsonString: string, options?: Partial): Proto2GroupsMessage_OneofGroup; + + static equals(a: Proto2GroupsMessage_OneofGroup | PlainMessage | undefined, b: Proto2GroupsMessage_OneofGroup | PlainMessage | undefined): boolean; +} + diff --git a/packages/protobuf-test/src/gen/js/extra/proto2_pb.js b/packages/protobuf-test/src/gen/js/extra/proto2_pb.js index 2644c6f38..30ce86c54 100644 --- a/packages/protobuf-test/src/gen/js/extra/proto2_pb.js +++ b/packages/protobuf-test/src/gen/js/extra/proto2_pb.js @@ -131,3 +131,62 @@ export const Proto2ChildMessage = proto2.makeMessageType( ], ); +/** + * @generated from message spec.Proto2GroupsMessage + */ +export const Proto2GroupsMessage = proto2.makeMessageType( + "spec.Proto2GroupsMessage", + () => [ + { no: 1, name: "group", kind: "message", T: Proto2GroupsMessage_Group, delimited: true, opt: true }, + { no: 2, name: "repeatedgroup", kind: "message", T: Proto2GroupsMessage_RepeatedGroup, delimited: true, repeated: true }, + { no: 3, name: "oneofgroup", kind: "message", T: Proto2GroupsMessage_OneofGroup, delimited: true, oneof: "oneof_with_group" }, + { no: 4, name: "message_field_using_group", kind: "message", T: Proto2GroupsMessage_Group, opt: true }, + { no: 5, name: "message_field_using_nested_group", kind: "message", T: Proto2GroupsMessage_Group_NestedGroup, opt: true }, + ], +); + +/** + * @generated from message spec.Proto2GroupsMessage.Group + */ +export const Proto2GroupsMessage_Group = proto2.makeMessageType( + "spec.Proto2GroupsMessage.Group", + () => [ + { no: 1, name: "int32_field", kind: "scalar", T: 5 /* ScalarType.INT32 */, opt: true }, + { no: 2, name: "nestedgroup", kind: "message", T: Proto2GroupsMessage_Group_NestedGroup, delimited: true, opt: true }, + ], + {localName: "Proto2GroupsMessage_Group"}, +); + +/** + * @generated from message spec.Proto2GroupsMessage.Group.NestedGroup + */ +export const Proto2GroupsMessage_Group_NestedGroup = proto2.makeMessageType( + "spec.Proto2GroupsMessage.Group.NestedGroup", + () => [ + { no: 1, name: "string_field", kind: "scalar", T: 9 /* ScalarType.STRING */, opt: true }, + ], + {localName: "Proto2GroupsMessage_Group_NestedGroup"}, +); + +/** + * @generated from message spec.Proto2GroupsMessage.RepeatedGroup + */ +export const Proto2GroupsMessage_RepeatedGroup = proto2.makeMessageType( + "spec.Proto2GroupsMessage.RepeatedGroup", + () => [ + { no: 1, name: "int32_field", kind: "scalar", T: 5 /* ScalarType.INT32 */, opt: true }, + ], + {localName: "Proto2GroupsMessage_RepeatedGroup"}, +); + +/** + * @generated from message spec.Proto2GroupsMessage.OneofGroup + */ +export const Proto2GroupsMessage_OneofGroup = proto2.makeMessageType( + "spec.Proto2GroupsMessage.OneofGroup", + () => [ + { no: 1, name: "bool_field", kind: "scalar", T: 8 /* ScalarType.BOOL */, opt: true }, + ], + {localName: "Proto2GroupsMessage_OneofGroup"}, +); + diff --git a/packages/protobuf-test/src/gen/js/google/protobuf/test_messages_proto2_pb.js b/packages/protobuf-test/src/gen/js/google/protobuf/test_messages_proto2_pb.js index 9af0bb892..b518ae193 100644 --- a/packages/protobuf-test/src/gen/js/google/protobuf/test_messages_proto2_pb.js +++ b/packages/protobuf-test/src/gen/js/google/protobuf/test_messages_proto2_pb.js @@ -145,7 +145,7 @@ export const TestAllTypesProto2 = proto2.makeMessageType( { no: 117, name: "oneof_float", kind: "scalar", T: 2 /* ScalarType.FLOAT */, oneof: "oneof_field" }, { no: 118, name: "oneof_double", kind: "scalar", T: 1 /* ScalarType.DOUBLE */, oneof: "oneof_field" }, { no: 119, name: "oneof_enum", kind: "enum", T: proto2.getEnumType(TestAllTypesProto2_NestedEnum), oneof: "oneof_field" }, - { no: 201, name: "data", kind: "message", T: TestAllTypesProto2_Data, opt: true }, + { no: 201, name: "data", kind: "message", T: TestAllTypesProto2_Data, delimited: true, opt: true }, { no: 241, name: "default_int32", kind: "scalar", T: 5 /* ScalarType.INT32 */, opt: true, default: -123456789 }, { no: 242, name: "default_int64", kind: "scalar", T: 3 /* ScalarType.INT64 */, opt: true, default: protoInt64.parse("-9123456789123456789") }, { no: 243, name: "default_uint32", kind: "scalar", T: 13 /* ScalarType.UINT32 */, opt: true, default: 2123456789 }, @@ -273,7 +273,7 @@ export const UnknownToTestAllTypes = proto2.makeMessageType( { no: 1001, name: "optional_int32", kind: "scalar", T: 5 /* ScalarType.INT32 */, opt: true }, { no: 1002, name: "optional_string", kind: "scalar", T: 9 /* ScalarType.STRING */, opt: true }, { no: 1003, name: "nested_message", kind: "message", T: ForeignMessageProto2, opt: true }, - { no: 1004, name: "optionalgroup", kind: "message", T: UnknownToTestAllTypes_OptionalGroup, opt: true }, + { no: 1004, name: "optionalgroup", kind: "message", T: UnknownToTestAllTypes_OptionalGroup, delimited: true, opt: true }, { no: 1006, name: "optional_bool", kind: "scalar", T: 8 /* ScalarType.BOOL */, opt: true }, { no: 1011, name: "repeated_int32", kind: "scalar", T: 5 /* ScalarType.INT32 */, repeated: true }, ], @@ -368,7 +368,7 @@ export const TestAllRequiredTypesProto2 = proto2.makeMessageType( { no: 25, name: "required_cord", kind: "scalar", T: 9 /* ScalarType.STRING */ }, { no: 27, name: "recursive_message", kind: "message", T: TestAllRequiredTypesProto2 }, { no: 28, name: "optional_recursive_message", kind: "message", T: TestAllRequiredTypesProto2, opt: true }, - { no: 201, name: "data", kind: "message", T: TestAllRequiredTypesProto2_Data }, + { no: 201, name: "data", kind: "message", T: TestAllRequiredTypesProto2_Data, delimited: true }, { no: 241, name: "default_int32", kind: "scalar", T: 5 /* ScalarType.INT32 */, default: -123456789 }, { no: 242, name: "default_int64", kind: "scalar", T: 3 /* ScalarType.INT64 */, default: protoInt64.parse("-9123456789123456789") }, { no: 243, name: "default_uint32", kind: "scalar", T: 13 /* ScalarType.UINT32 */, default: 2123456789 }, diff --git a/packages/protobuf-test/src/gen/js/google/protobuf/unittest_custom_options_pb.js b/packages/protobuf-test/src/gen/js/google/protobuf/unittest_custom_options_pb.js index 938127e09..ec6f84db1 100644 --- a/packages/protobuf-test/src/gen/js/google/protobuf/unittest_custom_options_pb.js +++ b/packages/protobuf-test/src/gen/js/google/protobuf/unittest_custom_options_pb.js @@ -220,7 +220,7 @@ export const ComplexOptionType3 = proto2.makeMessageType( "protobuf_unittest.ComplexOptionType3", () => [ { no: 1, name: "moo", kind: "scalar", T: 5 /* ScalarType.INT32 */, opt: true }, - { no: 2, name: "complexoptiontype5", kind: "message", T: ComplexOptionType3_ComplexOptionType5, opt: true }, + { no: 2, name: "complexoptiontype5", kind: "message", T: ComplexOptionType3_ComplexOptionType5, delimited: true, opt: true }, ], ); diff --git a/packages/protobuf-test/src/gen/js/google/protobuf/unittest_lite_pb.js b/packages/protobuf-test/src/gen/js/google/protobuf/unittest_lite_pb.js index 0aa25250f..e41948066 100644 --- a/packages/protobuf-test/src/gen/js/google/protobuf/unittest_lite_pb.js +++ b/packages/protobuf-test/src/gen/js/google/protobuf/unittest_lite_pb.js @@ -80,7 +80,7 @@ export const TestAllTypesLite = proto2.makeMessageType( { no: 13, name: "optional_bool", kind: "scalar", T: 8 /* ScalarType.BOOL */, opt: true }, { no: 14, name: "optional_string", kind: "scalar", T: 9 /* ScalarType.STRING */, opt: true }, { no: 15, name: "optional_bytes", kind: "scalar", T: 12 /* ScalarType.BYTES */, opt: true }, - { no: 16, name: "optionalgroup", kind: "message", T: TestAllTypesLite_OptionalGroup, opt: true }, + { no: 16, name: "optionalgroup", kind: "message", T: TestAllTypesLite_OptionalGroup, delimited: true, opt: true }, { no: 18, name: "optional_nested_message", kind: "message", T: TestAllTypesLite_NestedMessage, opt: true }, { no: 19, name: "optional_foreign_message", kind: "message", T: ForeignMessageLite, opt: true }, { no: 20, name: "optional_import_message", kind: "message", T: ImportMessageLite, opt: true }, @@ -107,7 +107,7 @@ export const TestAllTypesLite = proto2.makeMessageType( { no: 43, name: "repeated_bool", kind: "scalar", T: 8 /* ScalarType.BOOL */, repeated: true }, { no: 44, name: "repeated_string", kind: "scalar", T: 9 /* ScalarType.STRING */, repeated: true }, { no: 45, name: "repeated_bytes", kind: "scalar", T: 12 /* ScalarType.BYTES */, repeated: true }, - { no: 46, name: "repeatedgroup", kind: "message", T: TestAllTypesLite_RepeatedGroup, repeated: true }, + { no: 46, name: "repeatedgroup", kind: "message", T: TestAllTypesLite_RepeatedGroup, delimited: true, repeated: true }, { no: 48, name: "repeated_nested_message", kind: "message", T: TestAllTypesLite_NestedMessage, repeated: true }, { no: 49, name: "repeated_foreign_message", kind: "message", T: ForeignMessageLite, repeated: true }, { no: 50, name: "repeated_import_message", kind: "message", T: ImportMessageLite, repeated: true }, @@ -309,8 +309,8 @@ export const TestParsingMergeLite = proto2.makeMessageType( { no: 1, name: "required_all_types", kind: "message", T: TestAllTypesLite }, { no: 2, name: "optional_all_types", kind: "message", T: TestAllTypesLite, opt: true }, { no: 3, name: "repeated_all_types", kind: "message", T: TestAllTypesLite, repeated: true }, - { no: 10, name: "optionalgroup", kind: "message", T: TestParsingMergeLite_OptionalGroup, opt: true }, - { no: 20, name: "repeatedgroup", kind: "message", T: TestParsingMergeLite_RepeatedGroup, repeated: true }, + { no: 10, name: "optionalgroup", kind: "message", T: TestParsingMergeLite_OptionalGroup, delimited: true, opt: true }, + { no: 20, name: "repeatedgroup", kind: "message", T: TestParsingMergeLite_RepeatedGroup, delimited: true, repeated: true }, ], ); @@ -323,8 +323,8 @@ export const TestParsingMergeLite_RepeatedFieldsGenerator = proto2.makeMessageTy { no: 1, name: "field1", kind: "message", T: TestAllTypesLite, repeated: true }, { no: 2, name: "field2", kind: "message", T: TestAllTypesLite, repeated: true }, { no: 3, name: "field3", kind: "message", T: TestAllTypesLite, repeated: true }, - { no: 10, name: "group1", kind: "message", T: TestParsingMergeLite_RepeatedFieldsGenerator_Group1, repeated: true }, - { no: 20, name: "group2", kind: "message", T: TestParsingMergeLite_RepeatedFieldsGenerator_Group2, repeated: true }, + { no: 10, name: "group1", kind: "message", T: TestParsingMergeLite_RepeatedFieldsGenerator_Group1, delimited: true, repeated: true }, + { no: 20, name: "group2", kind: "message", T: TestParsingMergeLite_RepeatedFieldsGenerator_Group2, delimited: true, repeated: true }, { no: 1000, name: "ext1", kind: "message", T: TestAllTypesLite, repeated: true }, { no: 1001, name: "ext2", kind: "message", T: TestAllTypesLite, repeated: true }, ], @@ -445,7 +445,7 @@ export const TestHugeFieldNumbersLite = proto2.makeMessageType( { no: 536870005, name: "optional_string", kind: "scalar", T: 9 /* ScalarType.STRING */, opt: true }, { no: 536870006, name: "optional_bytes", kind: "scalar", T: 12 /* ScalarType.BYTES */, opt: true }, { no: 536870007, name: "optional_message", kind: "message", T: ForeignMessageLite, opt: true }, - { no: 536870008, name: "optionalgroup", kind: "message", T: TestHugeFieldNumbersLite_OptionalGroup, opt: true }, + { no: 536870008, name: "optionalgroup", kind: "message", T: TestHugeFieldNumbersLite_OptionalGroup, delimited: true, opt: true }, { no: 536870010, name: "string_string_map", kind: "map", K: 9 /* ScalarType.STRING */, V: {kind: "scalar", T: 9 /* ScalarType.STRING */} }, { no: 536870011, name: "oneof_uint32", kind: "scalar", T: 13 /* ScalarType.UINT32 */, oneof: "oneof_field" }, { no: 536870012, name: "oneof_test_all_types", kind: "message", T: TestAllTypesLite, oneof: "oneof_field" }, diff --git a/packages/protobuf-test/src/gen/js/google/protobuf/unittest_mset_pb.js b/packages/protobuf-test/src/gen/js/google/protobuf/unittest_mset_pb.js index 7a50079ed..1dd0d3792 100644 --- a/packages/protobuf-test/src/gen/js/google/protobuf/unittest_mset_pb.js +++ b/packages/protobuf-test/src/gen/js/google/protobuf/unittest_mset_pb.js @@ -101,7 +101,7 @@ export const TestMessageSetExtension3 = proto2.makeMessageType( export const RawMessageSet = proto2.makeMessageType( "protobuf_unittest.RawMessageSet", () => [ - { no: 1, name: "item", kind: "message", T: RawMessageSet_Item, repeated: true }, + { no: 1, name: "item", kind: "message", T: RawMessageSet_Item, delimited: true, repeated: true }, ], ); diff --git a/packages/protobuf-test/src/gen/js/google/protobuf/unittest_pb.js b/packages/protobuf-test/src/gen/js/google/protobuf/unittest_pb.js index f7779f271..7cfcdfa58 100644 --- a/packages/protobuf-test/src/gen/js/google/protobuf/unittest_pb.js +++ b/packages/protobuf-test/src/gen/js/google/protobuf/unittest_pb.js @@ -223,7 +223,7 @@ export const TestAllTypes = proto2.makeMessageType( { no: 13, name: "optional_bool", kind: "scalar", T: 8 /* ScalarType.BOOL */, opt: true }, { no: 14, name: "optional_string", kind: "scalar", T: 9 /* ScalarType.STRING */, opt: true }, { no: 15, name: "optional_bytes", kind: "scalar", T: 12 /* ScalarType.BYTES */, opt: true }, - { no: 16, name: "optionalgroup", kind: "message", T: TestAllTypes_OptionalGroup, opt: true }, + { no: 16, name: "optionalgroup", kind: "message", T: TestAllTypes_OptionalGroup, delimited: true, opt: true }, { no: 18, name: "optional_nested_message", kind: "message", T: TestAllTypes_NestedMessage, opt: true }, { no: 19, name: "optional_foreign_message", kind: "message", T: ForeignMessage, opt: true }, { no: 20, name: "optional_import_message", kind: "message", T: ImportMessage, opt: true }, @@ -250,7 +250,7 @@ export const TestAllTypes = proto2.makeMessageType( { no: 43, name: "repeated_bool", kind: "scalar", T: 8 /* ScalarType.BOOL */, repeated: true }, { no: 44, name: "repeated_string", kind: "scalar", T: 9 /* ScalarType.STRING */, repeated: true }, { no: 45, name: "repeated_bytes", kind: "scalar", T: 12 /* ScalarType.BYTES */, repeated: true }, - { no: 46, name: "repeatedgroup", kind: "message", T: TestAllTypes_RepeatedGroup, repeated: true }, + { no: 46, name: "repeatedgroup", kind: "message", T: TestAllTypes_RepeatedGroup, delimited: true, repeated: true }, { no: 48, name: "repeated_nested_message", kind: "message", T: TestAllTypes_NestedMessage, repeated: true }, { no: 49, name: "repeated_foreign_message", kind: "message", T: ForeignMessage, repeated: true }, { no: 50, name: "repeated_import_message", kind: "message", T: ImportMessage, repeated: true }, @@ -442,7 +442,7 @@ export const TestMixedFieldsAndExtensions = proto2.makeMessageType( export const TestGroup = proto2.makeMessageType( "protobuf_unittest.TestGroup", () => [ - { no: 16, name: "optionalgroup", kind: "message", T: TestGroup_OptionalGroup, opt: true }, + { no: 16, name: "optionalgroup", kind: "message", T: TestGroup_OptionalGroup, delimited: true, opt: true }, { no: 22, name: "optional_foreign_enum", kind: "enum", T: proto2.getEnumType(ForeignEnum), opt: true }, ], ); @@ -852,8 +852,8 @@ export const TestMutualRecursionA = proto2.makeMessageType( "protobuf_unittest.TestMutualRecursionA", () => [ { no: 1, name: "bb", kind: "message", T: TestMutualRecursionB, opt: true }, - { no: 2, name: "subgroup", kind: "message", T: TestMutualRecursionA_SubGroup, opt: true }, - { no: 5, name: "subgroupr", kind: "message", T: TestMutualRecursionA_SubGroupR, repeated: true }, + { no: 2, name: "subgroup", kind: "message", T: TestMutualRecursionA_SubGroup, delimited: true, opt: true }, + { no: 5, name: "subgroupr", kind: "message", T: TestMutualRecursionA_SubGroupR, delimited: true, repeated: true }, ], ); @@ -918,7 +918,7 @@ export const TestIsInitialized = proto2.makeMessageType( export const TestIsInitialized_SubMessage = proto2.makeMessageType( "protobuf_unittest.TestIsInitialized.SubMessage", () => [ - { no: 1, name: "subgroup", kind: "message", T: TestIsInitialized_SubMessage_SubGroup, opt: true }, + { no: 1, name: "subgroup", kind: "message", T: TestIsInitialized_SubMessage_SubGroup, delimited: true, opt: true }, ], {localName: "TestIsInitialized_SubMessage"}, ); @@ -948,8 +948,8 @@ export const TestDupFieldNumber = proto2.makeMessageType( "protobuf_unittest.TestDupFieldNumber", () => [ { no: 1, name: "a", kind: "scalar", T: 5 /* ScalarType.INT32 */, opt: true }, - { no: 2, name: "foo", kind: "message", T: TestDupFieldNumber_Foo, opt: true }, - { no: 3, name: "bar", kind: "message", T: TestDupFieldNumber_Bar, opt: true }, + { no: 2, name: "foo", kind: "message", T: TestDupFieldNumber_Foo, delimited: true, opt: true }, + { no: 3, name: "bar", kind: "message", T: TestDupFieldNumber_Bar, delimited: true, opt: true }, ], ); @@ -1329,7 +1329,7 @@ export const TestOneof = proto2.makeMessageType( { no: 1, name: "foo_int", kind: "scalar", T: 5 /* ScalarType.INT32 */, oneof: "foo" }, { no: 2, name: "foo_string", kind: "scalar", T: 9 /* ScalarType.STRING */, oneof: "foo" }, { no: 3, name: "foo_message", kind: "message", T: TestAllTypes, oneof: "foo" }, - { no: 4, name: "foogroup", kind: "message", T: TestOneof_FooGroup, oneof: "foo" }, + { no: 4, name: "foogroup", kind: "message", T: TestOneof_FooGroup, delimited: true, oneof: "foo" }, ], ); @@ -1354,7 +1354,7 @@ export const TestOneofBackwardsCompatible = proto2.makeMessageType( { no: 1, name: "foo_int", kind: "scalar", T: 5 /* ScalarType.INT32 */, opt: true }, { no: 2, name: "foo_string", kind: "scalar", T: 9 /* ScalarType.STRING */, opt: true }, { no: 3, name: "foo_message", kind: "message", T: TestAllTypes, opt: true }, - { no: 4, name: "foogroup", kind: "message", T: TestOneofBackwardsCompatible_FooGroup, opt: true }, + { no: 4, name: "foogroup", kind: "message", T: TestOneofBackwardsCompatible_FooGroup, delimited: true, opt: true }, ], ); @@ -1383,7 +1383,7 @@ export const TestOneof2 = proto2.makeMessageType( { no: 5, name: "foo_bytes", kind: "scalar", T: 12 /* ScalarType.BYTES */, oneof: "foo" }, { no: 6, name: "foo_enum", kind: "enum", T: proto2.getEnumType(TestOneof2_NestedEnum), oneof: "foo" }, { no: 7, name: "foo_message", kind: "message", T: TestOneof2_NestedMessage, oneof: "foo" }, - { no: 8, name: "foogroup", kind: "message", T: TestOneof2_FooGroup, oneof: "foo" }, + { no: 8, name: "foogroup", kind: "message", T: TestOneof2_FooGroup, delimited: true, oneof: "foo" }, { no: 11, name: "foo_lazy_message", kind: "message", T: TestOneof2_NestedMessage, oneof: "foo" }, { no: 30, name: "foo_bytes_cord", kind: "scalar", T: 12 /* ScalarType.BYTES */, oneof: "foo" }, { no: 12, name: "bar_int", kind: "scalar", T: 5 /* ScalarType.INT32 */, default: 5, oneof: "bar" }, @@ -1609,8 +1609,8 @@ export const TestParsingMerge = proto2.makeMessageType( { no: 1, name: "required_all_types", kind: "message", T: TestAllTypes }, { no: 2, name: "optional_all_types", kind: "message", T: TestAllTypes, opt: true }, { no: 3, name: "repeated_all_types", kind: "message", T: TestAllTypes, repeated: true }, - { no: 10, name: "optionalgroup", kind: "message", T: TestParsingMerge_OptionalGroup, opt: true }, - { no: 20, name: "repeatedgroup", kind: "message", T: TestParsingMerge_RepeatedGroup, repeated: true }, + { no: 10, name: "optionalgroup", kind: "message", T: TestParsingMerge_OptionalGroup, delimited: true, opt: true }, + { no: 20, name: "repeatedgroup", kind: "message", T: TestParsingMerge_RepeatedGroup, delimited: true, repeated: true }, ], ); @@ -1629,8 +1629,8 @@ export const TestParsingMerge_RepeatedFieldsGenerator = proto2.makeMessageType( { no: 1, name: "field1", kind: "message", T: TestAllTypes, repeated: true }, { no: 2, name: "field2", kind: "message", T: TestAllTypes, repeated: true }, { no: 3, name: "field3", kind: "message", T: TestAllTypes, repeated: true }, - { no: 10, name: "group1", kind: "message", T: TestParsingMerge_RepeatedFieldsGenerator_Group1, repeated: true }, - { no: 20, name: "group2", kind: "message", T: TestParsingMerge_RepeatedFieldsGenerator_Group2, repeated: true }, + { no: 10, name: "group1", kind: "message", T: TestParsingMerge_RepeatedFieldsGenerator_Group1, delimited: true, repeated: true }, + { no: 20, name: "group2", kind: "message", T: TestParsingMerge_RepeatedFieldsGenerator_Group2, delimited: true, repeated: true }, { no: 1000, name: "ext1", kind: "message", T: TestAllTypes, repeated: true }, { no: 1001, name: "ext2", kind: "message", T: TestAllTypes, repeated: true }, ], @@ -1802,7 +1802,7 @@ export const TestHugeFieldNumbers = proto2.makeMessageType( { no: 536870005, name: "optional_string", kind: "scalar", T: 9 /* ScalarType.STRING */, opt: true }, { no: 536870006, name: "optional_bytes", kind: "scalar", T: 12 /* ScalarType.BYTES */, opt: true }, { no: 536870007, name: "optional_message", kind: "message", T: ForeignMessage, opt: true }, - { no: 536870008, name: "optionalgroup", kind: "message", T: TestHugeFieldNumbers_OptionalGroup, opt: true }, + { no: 536870008, name: "optionalgroup", kind: "message", T: TestHugeFieldNumbers_OptionalGroup, delimited: true, opt: true }, { no: 536870010, name: "string_string_map", kind: "map", K: 9 /* ScalarType.STRING */, V: {kind: "scalar", T: 9 /* ScalarType.STRING */} }, { no: 536870011, name: "oneof_uint32", kind: "scalar", T: 13 /* ScalarType.UINT32 */, oneof: "oneof_field" }, { no: 536870012, name: "oneof_test_all_types", kind: "message", T: TestAllTypes, oneof: "oneof_field" }, @@ -1848,7 +1848,7 @@ export const TestExtensionInsideTable = proto2.makeMessageType( export const TestNestedGroupExtensionOuter = proto2.makeMessageType( "protobuf_unittest.TestNestedGroupExtensionOuter", () => [ - { no: 1, name: "layer1optionalgroup", kind: "message", T: TestNestedGroupExtensionOuter_Layer1OptionalGroup, opt: true }, + { no: 1, name: "layer1optionalgroup", kind: "message", T: TestNestedGroupExtensionOuter_Layer1OptionalGroup, delimited: true, opt: true }, ], ); @@ -1858,8 +1858,8 @@ export const TestNestedGroupExtensionOuter = proto2.makeMessageType( export const TestNestedGroupExtensionOuter_Layer1OptionalGroup = proto2.makeMessageType( "protobuf_unittest.TestNestedGroupExtensionOuter.Layer1OptionalGroup", () => [ - { no: 2, name: "layer2repeatedgroup", kind: "message", T: TestNestedGroupExtensionOuter_Layer1OptionalGroup_Layer2RepeatedGroup, repeated: true }, - { no: 4, name: "layer2anotheroptionalrepeatedgroup", kind: "message", T: TestNestedGroupExtensionOuter_Layer1OptionalGroup_Layer2AnotherOptionalRepeatedGroup, repeated: true }, + { no: 2, name: "layer2repeatedgroup", kind: "message", T: TestNestedGroupExtensionOuter_Layer1OptionalGroup_Layer2RepeatedGroup, delimited: true, repeated: true }, + { no: 4, name: "layer2anotheroptionalrepeatedgroup", kind: "message", T: TestNestedGroupExtensionOuter_Layer1OptionalGroup_Layer2AnotherOptionalRepeatedGroup, delimited: true, repeated: true }, ], {localName: "TestNestedGroupExtensionOuter_Layer1OptionalGroup"}, ); diff --git a/packages/protobuf-test/src/gen/ts/extra/proto2_pb.ts b/packages/protobuf-test/src/gen/ts/extra/proto2_pb.ts index f6868f741..c3ec781bf 100644 --- a/packages/protobuf-test/src/gen/ts/extra/proto2_pb.ts +++ b/packages/protobuf-test/src/gen/ts/extra/proto2_pb.ts @@ -467,3 +467,224 @@ export class Proto2ChildMessage extends Message { } } +/** + * @generated from message spec.Proto2GroupsMessage + */ +export class Proto2GroupsMessage extends Message { + /** + * @generated from field: optional spec.Proto2GroupsMessage.Group group = 1; + */ + group?: Proto2GroupsMessage_Group; + + /** + * @generated from field: repeated spec.Proto2GroupsMessage.RepeatedGroup repeatedgroup = 2; + */ + repeatedgroup: Proto2GroupsMessage_RepeatedGroup[] = []; + + /** + * @generated from oneof spec.Proto2GroupsMessage.oneof_with_group + */ + oneofWithGroup: { + /** + * @generated from field: spec.Proto2GroupsMessage.OneofGroup oneofgroup = 3; + */ + value: Proto2GroupsMessage_OneofGroup; + case: "oneofgroup"; + } | { case: undefined; value?: undefined } = { case: undefined }; + + /** + * @generated from field: optional spec.Proto2GroupsMessage.Group message_field_using_group = 4; + */ + messageFieldUsingGroup?: Proto2GroupsMessage_Group; + + /** + * @generated from field: optional spec.Proto2GroupsMessage.Group.NestedGroup message_field_using_nested_group = 5; + */ + messageFieldUsingNestedGroup?: Proto2GroupsMessage_Group_NestedGroup; + + constructor(data?: PartialMessage) { + super(); + proto2.util.initPartial(data, this); + } + + static readonly runtime: typeof proto2 = proto2; + static readonly typeName = "spec.Proto2GroupsMessage"; + static readonly fields: FieldList = proto2.util.newFieldList(() => [ + { no: 1, name: "group", kind: "message", T: Proto2GroupsMessage_Group, delimited: true, opt: true }, + { no: 2, name: "repeatedgroup", kind: "message", T: Proto2GroupsMessage_RepeatedGroup, delimited: true, repeated: true }, + { no: 3, name: "oneofgroup", kind: "message", T: Proto2GroupsMessage_OneofGroup, delimited: true, oneof: "oneof_with_group" }, + { no: 4, name: "message_field_using_group", kind: "message", T: Proto2GroupsMessage_Group, opt: true }, + { no: 5, name: "message_field_using_nested_group", kind: "message", T: Proto2GroupsMessage_Group_NestedGroup, opt: true }, + ]); + + static fromBinary(bytes: Uint8Array, options?: Partial): Proto2GroupsMessage { + return new Proto2GroupsMessage().fromBinary(bytes, options); + } + + static fromJson(jsonValue: JsonValue, options?: Partial): Proto2GroupsMessage { + return new Proto2GroupsMessage().fromJson(jsonValue, options); + } + + static fromJsonString(jsonString: string, options?: Partial): Proto2GroupsMessage { + return new Proto2GroupsMessage().fromJsonString(jsonString, options); + } + + static equals(a: Proto2GroupsMessage | PlainMessage | undefined, b: Proto2GroupsMessage | PlainMessage | undefined): boolean { + return proto2.util.equals(Proto2GroupsMessage, a, b); + } +} + +/** + * @generated from message spec.Proto2GroupsMessage.Group + */ +export class Proto2GroupsMessage_Group extends Message { + /** + * @generated from field: optional int32 int32_field = 1; + */ + int32Field?: number; + + /** + * @generated from field: optional spec.Proto2GroupsMessage.Group.NestedGroup nestedgroup = 2; + */ + nestedgroup?: Proto2GroupsMessage_Group_NestedGroup; + + constructor(data?: PartialMessage) { + super(); + proto2.util.initPartial(data, this); + } + + static readonly runtime: typeof proto2 = proto2; + static readonly typeName = "spec.Proto2GroupsMessage.Group"; + static readonly fields: FieldList = proto2.util.newFieldList(() => [ + { no: 1, name: "int32_field", kind: "scalar", T: 5 /* ScalarType.INT32 */, opt: true }, + { no: 2, name: "nestedgroup", kind: "message", T: Proto2GroupsMessage_Group_NestedGroup, delimited: true, opt: true }, + ]); + + static fromBinary(bytes: Uint8Array, options?: Partial): Proto2GroupsMessage_Group { + return new Proto2GroupsMessage_Group().fromBinary(bytes, options); + } + + static fromJson(jsonValue: JsonValue, options?: Partial): Proto2GroupsMessage_Group { + return new Proto2GroupsMessage_Group().fromJson(jsonValue, options); + } + + static fromJsonString(jsonString: string, options?: Partial): Proto2GroupsMessage_Group { + return new Proto2GroupsMessage_Group().fromJsonString(jsonString, options); + } + + static equals(a: Proto2GroupsMessage_Group | PlainMessage | undefined, b: Proto2GroupsMessage_Group | PlainMessage | undefined): boolean { + return proto2.util.equals(Proto2GroupsMessage_Group, a, b); + } +} + +/** + * @generated from message spec.Proto2GroupsMessage.Group.NestedGroup + */ +export class Proto2GroupsMessage_Group_NestedGroup extends Message { + /** + * @generated from field: optional string string_field = 1; + */ + stringField?: string; + + constructor(data?: PartialMessage) { + super(); + proto2.util.initPartial(data, this); + } + + static readonly runtime: typeof proto2 = proto2; + static readonly typeName = "spec.Proto2GroupsMessage.Group.NestedGroup"; + static readonly fields: FieldList = proto2.util.newFieldList(() => [ + { no: 1, name: "string_field", kind: "scalar", T: 9 /* ScalarType.STRING */, opt: true }, + ]); + + static fromBinary(bytes: Uint8Array, options?: Partial): Proto2GroupsMessage_Group_NestedGroup { + return new Proto2GroupsMessage_Group_NestedGroup().fromBinary(bytes, options); + } + + static fromJson(jsonValue: JsonValue, options?: Partial): Proto2GroupsMessage_Group_NestedGroup { + return new Proto2GroupsMessage_Group_NestedGroup().fromJson(jsonValue, options); + } + + static fromJsonString(jsonString: string, options?: Partial): Proto2GroupsMessage_Group_NestedGroup { + return new Proto2GroupsMessage_Group_NestedGroup().fromJsonString(jsonString, options); + } + + static equals(a: Proto2GroupsMessage_Group_NestedGroup | PlainMessage | undefined, b: Proto2GroupsMessage_Group_NestedGroup | PlainMessage | undefined): boolean { + return proto2.util.equals(Proto2GroupsMessage_Group_NestedGroup, a, b); + } +} + +/** + * @generated from message spec.Proto2GroupsMessage.RepeatedGroup + */ +export class Proto2GroupsMessage_RepeatedGroup extends Message { + /** + * @generated from field: optional int32 int32_field = 1; + */ + int32Field?: number; + + constructor(data?: PartialMessage) { + super(); + proto2.util.initPartial(data, this); + } + + static readonly runtime: typeof proto2 = proto2; + static readonly typeName = "spec.Proto2GroupsMessage.RepeatedGroup"; + static readonly fields: FieldList = proto2.util.newFieldList(() => [ + { no: 1, name: "int32_field", kind: "scalar", T: 5 /* ScalarType.INT32 */, opt: true }, + ]); + + static fromBinary(bytes: Uint8Array, options?: Partial): Proto2GroupsMessage_RepeatedGroup { + return new Proto2GroupsMessage_RepeatedGroup().fromBinary(bytes, options); + } + + static fromJson(jsonValue: JsonValue, options?: Partial): Proto2GroupsMessage_RepeatedGroup { + return new Proto2GroupsMessage_RepeatedGroup().fromJson(jsonValue, options); + } + + static fromJsonString(jsonString: string, options?: Partial): Proto2GroupsMessage_RepeatedGroup { + return new Proto2GroupsMessage_RepeatedGroup().fromJsonString(jsonString, options); + } + + static equals(a: Proto2GroupsMessage_RepeatedGroup | PlainMessage | undefined, b: Proto2GroupsMessage_RepeatedGroup | PlainMessage | undefined): boolean { + return proto2.util.equals(Proto2GroupsMessage_RepeatedGroup, a, b); + } +} + +/** + * @generated from message spec.Proto2GroupsMessage.OneofGroup + */ +export class Proto2GroupsMessage_OneofGroup extends Message { + /** + * @generated from field: optional bool bool_field = 1; + */ + boolField?: boolean; + + constructor(data?: PartialMessage) { + super(); + proto2.util.initPartial(data, this); + } + + static readonly runtime: typeof proto2 = proto2; + static readonly typeName = "spec.Proto2GroupsMessage.OneofGroup"; + static readonly fields: FieldList = proto2.util.newFieldList(() => [ + { no: 1, name: "bool_field", kind: "scalar", T: 8 /* ScalarType.BOOL */, opt: true }, + ]); + + static fromBinary(bytes: Uint8Array, options?: Partial): Proto2GroupsMessage_OneofGroup { + return new Proto2GroupsMessage_OneofGroup().fromBinary(bytes, options); + } + + static fromJson(jsonValue: JsonValue, options?: Partial): Proto2GroupsMessage_OneofGroup { + return new Proto2GroupsMessage_OneofGroup().fromJson(jsonValue, options); + } + + static fromJsonString(jsonString: string, options?: Partial): Proto2GroupsMessage_OneofGroup { + return new Proto2GroupsMessage_OneofGroup().fromJsonString(jsonString, options); + } + + static equals(a: Proto2GroupsMessage_OneofGroup | PlainMessage | undefined, b: Proto2GroupsMessage_OneofGroup | PlainMessage | undefined): boolean { + return proto2.util.equals(Proto2GroupsMessage_OneofGroup, a, b); + } +} + diff --git a/packages/protobuf-test/src/gen/ts/google/protobuf/test_messages_proto2_pb.ts b/packages/protobuf-test/src/gen/ts/google/protobuf/test_messages_proto2_pb.ts index a211f3f8f..e2d390ef2 100644 --- a/packages/protobuf-test/src/gen/ts/google/protobuf/test_messages_proto2_pb.ts +++ b/packages/protobuf-test/src/gen/ts/google/protobuf/test_messages_proto2_pb.ts @@ -860,7 +860,7 @@ export class TestAllTypesProto2 extends Message { { no: 117, name: "oneof_float", kind: "scalar", T: 2 /* ScalarType.FLOAT */, oneof: "oneof_field" }, { no: 118, name: "oneof_double", kind: "scalar", T: 1 /* ScalarType.DOUBLE */, oneof: "oneof_field" }, { no: 119, name: "oneof_enum", kind: "enum", T: proto2.getEnumType(TestAllTypesProto2_NestedEnum), oneof: "oneof_field" }, - { no: 201, name: "data", kind: "message", T: TestAllTypesProto2_Data, opt: true }, + { no: 201, name: "data", kind: "message", T: TestAllTypesProto2_Data, delimited: true, opt: true }, { no: 241, name: "default_int32", kind: "scalar", T: 5 /* ScalarType.INT32 */, opt: true, default: -123456789 }, { no: 242, name: "default_int64", kind: "scalar", T: 3 /* ScalarType.INT64 */, opt: true, default: protoInt64.parse("-9123456789123456789") }, { no: 243, name: "default_uint32", kind: "scalar", T: 13 /* ScalarType.UINT32 */, opt: true, default: 2123456789 }, @@ -1224,7 +1224,7 @@ export class UnknownToTestAllTypes extends Message { { no: 1001, name: "optional_int32", kind: "scalar", T: 5 /* ScalarType.INT32 */, opt: true }, { no: 1002, name: "optional_string", kind: "scalar", T: 9 /* ScalarType.STRING */, opt: true }, { no: 1003, name: "nested_message", kind: "message", T: ForeignMessageProto2, opt: true }, - { no: 1004, name: "optionalgroup", kind: "message", T: UnknownToTestAllTypes_OptionalGroup, opt: true }, + { no: 1004, name: "optionalgroup", kind: "message", T: UnknownToTestAllTypes_OptionalGroup, delimited: true, opt: true }, { no: 1006, name: "optional_bool", kind: "scalar", T: 8 /* ScalarType.BOOL */, opt: true }, { no: 1011, name: "repeated_int32", kind: "scalar", T: 5 /* ScalarType.INT32 */, repeated: true }, ]); @@ -1685,7 +1685,7 @@ export class TestAllRequiredTypesProto2 extends Message { static readonly typeName = "protobuf_unittest.ComplexOptionType3"; static readonly fields: FieldList = proto2.util.newFieldList(() => [ { no: 1, name: "moo", kind: "scalar", T: 5 /* ScalarType.INT32 */, opt: true }, - { no: 2, name: "complexoptiontype5", kind: "message", T: ComplexOptionType3_ComplexOptionType5, opt: true }, + { no: 2, name: "complexoptiontype5", kind: "message", T: ComplexOptionType3_ComplexOptionType5, delimited: true, opt: true }, ]); static fromBinary(bytes: Uint8Array, options?: Partial): ComplexOptionType3 { diff --git a/packages/protobuf-test/src/gen/ts/google/protobuf/unittest_lite_pb.ts b/packages/protobuf-test/src/gen/ts/google/protobuf/unittest_lite_pb.ts index ae8d52ce9..89a8aa818 100644 --- a/packages/protobuf-test/src/gen/ts/google/protobuf/unittest_lite_pb.ts +++ b/packages/protobuf-test/src/gen/ts/google/protobuf/unittest_lite_pb.ts @@ -532,7 +532,7 @@ export class TestAllTypesLite extends Message { { no: 13, name: "optional_bool", kind: "scalar", T: 8 /* ScalarType.BOOL */, opt: true }, { no: 14, name: "optional_string", kind: "scalar", T: 9 /* ScalarType.STRING */, opt: true }, { no: 15, name: "optional_bytes", kind: "scalar", T: 12 /* ScalarType.BYTES */, opt: true }, - { no: 16, name: "optionalgroup", kind: "message", T: TestAllTypesLite_OptionalGroup, opt: true }, + { no: 16, name: "optionalgroup", kind: "message", T: TestAllTypesLite_OptionalGroup, delimited: true, opt: true }, { no: 18, name: "optional_nested_message", kind: "message", T: TestAllTypesLite_NestedMessage, opt: true }, { no: 19, name: "optional_foreign_message", kind: "message", T: ForeignMessageLite, opt: true }, { no: 20, name: "optional_import_message", kind: "message", T: ImportMessageLite, opt: true }, @@ -559,7 +559,7 @@ export class TestAllTypesLite extends Message { { no: 43, name: "repeated_bool", kind: "scalar", T: 8 /* ScalarType.BOOL */, repeated: true }, { no: 44, name: "repeated_string", kind: "scalar", T: 9 /* ScalarType.STRING */, repeated: true }, { no: 45, name: "repeated_bytes", kind: "scalar", T: 12 /* ScalarType.BYTES */, repeated: true }, - { no: 46, name: "repeatedgroup", kind: "message", T: TestAllTypesLite_RepeatedGroup, repeated: true }, + { no: 46, name: "repeatedgroup", kind: "message", T: TestAllTypesLite_RepeatedGroup, delimited: true, repeated: true }, { no: 48, name: "repeated_nested_message", kind: "message", T: TestAllTypesLite_NestedMessage, repeated: true }, { no: 49, name: "repeated_foreign_message", kind: "message", T: ForeignMessageLite, repeated: true }, { no: 50, name: "repeated_import_message", kind: "message", T: ImportMessageLite, repeated: true }, @@ -1224,8 +1224,8 @@ export class TestParsingMergeLite extends Message { { no: 1, name: "required_all_types", kind: "message", T: TestAllTypesLite }, { no: 2, name: "optional_all_types", kind: "message", T: TestAllTypesLite, opt: true }, { no: 3, name: "repeated_all_types", kind: "message", T: TestAllTypesLite, repeated: true }, - { no: 10, name: "optionalgroup", kind: "message", T: TestParsingMergeLite_OptionalGroup, opt: true }, - { no: 20, name: "repeatedgroup", kind: "message", T: TestParsingMergeLite_RepeatedGroup, repeated: true }, + { no: 10, name: "optionalgroup", kind: "message", T: TestParsingMergeLite_OptionalGroup, delimited: true, opt: true }, + { no: 20, name: "repeatedgroup", kind: "message", T: TestParsingMergeLite_RepeatedGroup, delimited: true, repeated: true }, ]); static fromBinary(bytes: Uint8Array, options?: Partial): TestParsingMergeLite { @@ -1295,8 +1295,8 @@ export class TestParsingMergeLite_RepeatedFieldsGenerator extends Message { no: 536870005, name: "optional_string", kind: "scalar", T: 9 /* ScalarType.STRING */, opt: true }, { no: 536870006, name: "optional_bytes", kind: "scalar", T: 12 /* ScalarType.BYTES */, opt: true }, { no: 536870007, name: "optional_message", kind: "message", T: ForeignMessageLite, opt: true }, - { no: 536870008, name: "optionalgroup", kind: "message", T: TestHugeFieldNumbersLite_OptionalGroup, opt: true }, + { no: 536870008, name: "optionalgroup", kind: "message", T: TestHugeFieldNumbersLite_OptionalGroup, delimited: true, opt: true }, { no: 536870010, name: "string_string_map", kind: "map", K: 9 /* ScalarType.STRING */, V: {kind: "scalar", T: 9 /* ScalarType.STRING */} }, { no: 536870011, name: "oneof_uint32", kind: "scalar", T: 13 /* ScalarType.UINT32 */, oneof: "oneof_field" }, { no: 536870012, name: "oneof_test_all_types", kind: "message", T: TestAllTypesLite, oneof: "oneof_field" }, diff --git a/packages/protobuf-test/src/gen/ts/google/protobuf/unittest_mset_pb.ts b/packages/protobuf-test/src/gen/ts/google/protobuf/unittest_mset_pb.ts index 7e9aebe1c..fae27a681 100644 --- a/packages/protobuf-test/src/gen/ts/google/protobuf/unittest_mset_pb.ts +++ b/packages/protobuf-test/src/gen/ts/google/protobuf/unittest_mset_pb.ts @@ -310,7 +310,7 @@ export class RawMessageSet extends Message { static readonly runtime: typeof proto2 = proto2; static readonly typeName = "protobuf_unittest.RawMessageSet"; static readonly fields: FieldList = proto2.util.newFieldList(() => [ - { no: 1, name: "item", kind: "message", T: RawMessageSet_Item, repeated: true }, + { no: 1, name: "item", kind: "message", T: RawMessageSet_Item, delimited: true, repeated: true }, ]); static fromBinary(bytes: Uint8Array, options?: Partial): RawMessageSet { diff --git a/packages/protobuf-test/src/gen/ts/google/protobuf/unittest_pb.ts b/packages/protobuf-test/src/gen/ts/google/protobuf/unittest_pb.ts index 3a4c12fc1..8f19dc36d 100644 --- a/packages/protobuf-test/src/gen/ts/google/protobuf/unittest_pb.ts +++ b/packages/protobuf-test/src/gen/ts/google/protobuf/unittest_pb.ts @@ -1234,7 +1234,7 @@ export class TestAllTypes extends Message { { no: 13, name: "optional_bool", kind: "scalar", T: 8 /* ScalarType.BOOL */, opt: true }, { no: 14, name: "optional_string", kind: "scalar", T: 9 /* ScalarType.STRING */, opt: true }, { no: 15, name: "optional_bytes", kind: "scalar", T: 12 /* ScalarType.BYTES */, opt: true }, - { no: 16, name: "optionalgroup", kind: "message", T: TestAllTypes_OptionalGroup, opt: true }, + { no: 16, name: "optionalgroup", kind: "message", T: TestAllTypes_OptionalGroup, delimited: true, opt: true }, { no: 18, name: "optional_nested_message", kind: "message", T: TestAllTypes_NestedMessage, opt: true }, { no: 19, name: "optional_foreign_message", kind: "message", T: ForeignMessage, opt: true }, { no: 20, name: "optional_import_message", kind: "message", T: ImportMessage, opt: true }, @@ -1261,7 +1261,7 @@ export class TestAllTypes extends Message { { no: 43, name: "repeated_bool", kind: "scalar", T: 8 /* ScalarType.BOOL */, repeated: true }, { no: 44, name: "repeated_string", kind: "scalar", T: 9 /* ScalarType.STRING */, repeated: true }, { no: 45, name: "repeated_bytes", kind: "scalar", T: 12 /* ScalarType.BYTES */, repeated: true }, - { no: 46, name: "repeatedgroup", kind: "message", T: TestAllTypes_RepeatedGroup, repeated: true }, + { no: 46, name: "repeatedgroup", kind: "message", T: TestAllTypes_RepeatedGroup, delimited: true, repeated: true }, { no: 48, name: "repeated_nested_message", kind: "message", T: TestAllTypes_NestedMessage, repeated: true }, { no: 49, name: "repeated_foreign_message", kind: "message", T: ForeignMessage, repeated: true }, { no: 50, name: "repeated_import_message", kind: "message", T: ImportMessage, repeated: true }, @@ -1879,7 +1879,7 @@ export class TestGroup extends Message { static readonly runtime: typeof proto2 = proto2; static readonly typeName = "protobuf_unittest.TestGroup"; static readonly fields: FieldList = proto2.util.newFieldList(() => [ - { no: 16, name: "optionalgroup", kind: "message", T: TestGroup_OptionalGroup, opt: true }, + { no: 16, name: "optionalgroup", kind: "message", T: TestGroup_OptionalGroup, delimited: true, opt: true }, { no: 22, name: "optional_foreign_enum", kind: "enum", T: proto2.getEnumType(ForeignEnum), opt: true }, ]); @@ -3434,8 +3434,8 @@ export class TestMutualRecursionA extends Message { static readonly typeName = "protobuf_unittest.TestMutualRecursionA"; static readonly fields: FieldList = proto2.util.newFieldList(() => [ { no: 1, name: "bb", kind: "message", T: TestMutualRecursionB, opt: true }, - { no: 2, name: "subgroup", kind: "message", T: TestMutualRecursionA_SubGroup, opt: true }, - { no: 5, name: "subgroupr", kind: "message", T: TestMutualRecursionA_SubGroupR, repeated: true }, + { no: 2, name: "subgroup", kind: "message", T: TestMutualRecursionA_SubGroup, delimited: true, opt: true }, + { no: 5, name: "subgroupr", kind: "message", T: TestMutualRecursionA_SubGroupR, delimited: true, repeated: true }, ]); static fromBinary(bytes: Uint8Array, options?: Partial): TestMutualRecursionA { @@ -3671,7 +3671,7 @@ export class TestIsInitialized_SubMessage extends Message [ - { no: 1, name: "subgroup", kind: "message", T: TestIsInitialized_SubMessage_SubGroup, opt: true }, + { no: 1, name: "subgroup", kind: "message", T: TestIsInitialized_SubMessage_SubGroup, delimited: true, opt: true }, ]); static fromBinary(bytes: Uint8Array, options?: Partial): TestIsInitialized_SubMessage { @@ -3765,8 +3765,8 @@ export class TestDupFieldNumber extends Message { static readonly typeName = "protobuf_unittest.TestDupFieldNumber"; static readonly fields: FieldList = proto2.util.newFieldList(() => [ { no: 1, name: "a", kind: "scalar", T: 5 /* ScalarType.INT32 */, opt: true }, - { no: 2, name: "foo", kind: "message", T: TestDupFieldNumber_Foo, opt: true }, - { no: 3, name: "bar", kind: "message", T: TestDupFieldNumber_Bar, opt: true }, + { no: 2, name: "foo", kind: "message", T: TestDupFieldNumber_Foo, delimited: true, opt: true }, + { no: 3, name: "bar", kind: "message", T: TestDupFieldNumber_Bar, delimited: true, opt: true }, ]); static fromBinary(bytes: Uint8Array, options?: Partial): TestDupFieldNumber { @@ -5317,7 +5317,7 @@ export class TestOneof extends Message { { no: 1, name: "foo_int", kind: "scalar", T: 5 /* ScalarType.INT32 */, oneof: "foo" }, { no: 2, name: "foo_string", kind: "scalar", T: 9 /* ScalarType.STRING */, oneof: "foo" }, { no: 3, name: "foo_message", kind: "message", T: TestAllTypes, oneof: "foo" }, - { no: 4, name: "foogroup", kind: "message", T: TestOneof_FooGroup, oneof: "foo" }, + { no: 4, name: "foogroup", kind: "message", T: TestOneof_FooGroup, delimited: true, oneof: "foo" }, ]); static fromBinary(bytes: Uint8Array, options?: Partial): TestOneof { @@ -5415,7 +5415,7 @@ export class TestOneofBackwardsCompatible extends Message): TestOneofBackwardsCompatible { @@ -5637,7 +5637,7 @@ export class TestOneof2 extends Message { { no: 5, name: "foo_bytes", kind: "scalar", T: 12 /* ScalarType.BYTES */, oneof: "foo" }, { no: 6, name: "foo_enum", kind: "enum", T: proto2.getEnumType(TestOneof2_NestedEnum), oneof: "foo" }, { no: 7, name: "foo_message", kind: "message", T: TestOneof2_NestedMessage, oneof: "foo" }, - { no: 8, name: "foogroup", kind: "message", T: TestOneof2_FooGroup, oneof: "foo" }, + { no: 8, name: "foogroup", kind: "message", T: TestOneof2_FooGroup, delimited: true, oneof: "foo" }, { no: 11, name: "foo_lazy_message", kind: "message", T: TestOneof2_NestedMessage, oneof: "foo" }, { no: 30, name: "foo_bytes_cord", kind: "scalar", T: 12 /* ScalarType.BYTES */, oneof: "foo" }, { no: 12, name: "bar_int", kind: "scalar", T: 5 /* ScalarType.INT32 */, default: 5, oneof: "bar" }, @@ -6494,8 +6494,8 @@ export class TestParsingMerge extends Message { { no: 1, name: "required_all_types", kind: "message", T: TestAllTypes }, { no: 2, name: "optional_all_types", kind: "message", T: TestAllTypes, opt: true }, { no: 3, name: "repeated_all_types", kind: "message", T: TestAllTypes, repeated: true }, - { no: 10, name: "optionalgroup", kind: "message", T: TestParsingMerge_OptionalGroup, opt: true }, - { no: 20, name: "repeatedgroup", kind: "message", T: TestParsingMerge_RepeatedGroup, repeated: true }, + { no: 10, name: "optionalgroup", kind: "message", T: TestParsingMerge_OptionalGroup, delimited: true, opt: true }, + { no: 20, name: "repeatedgroup", kind: "message", T: TestParsingMerge_RepeatedGroup, delimited: true, repeated: true }, ]); static fromBinary(bytes: Uint8Array, options?: Partial): TestParsingMerge { @@ -6571,8 +6571,8 @@ export class TestParsingMerge_RepeatedFieldsGenerator extends Message { { no: 536870005, name: "optional_string", kind: "scalar", T: 9 /* ScalarType.STRING */, opt: true }, { no: 536870006, name: "optional_bytes", kind: "scalar", T: 12 /* ScalarType.BYTES */, opt: true }, { no: 536870007, name: "optional_message", kind: "message", T: ForeignMessage, opt: true }, - { no: 536870008, name: "optionalgroup", kind: "message", T: TestHugeFieldNumbers_OptionalGroup, opt: true }, + { no: 536870008, name: "optionalgroup", kind: "message", T: TestHugeFieldNumbers_OptionalGroup, delimited: true, opt: true }, { no: 536870010, name: "string_string_map", kind: "map", K: 9 /* ScalarType.STRING */, V: {kind: "scalar", T: 9 /* ScalarType.STRING */} }, { no: 536870011, name: "oneof_uint32", kind: "scalar", T: 13 /* ScalarType.UINT32 */, oneof: "oneof_field" }, { no: 536870012, name: "oneof_test_all_types", kind: "message", T: TestAllTypes, oneof: "oneof_field" }, @@ -7417,7 +7417,7 @@ export class TestNestedGroupExtensionOuter extends Message [ - { no: 1, name: "layer1optionalgroup", kind: "message", T: TestNestedGroupExtensionOuter_Layer1OptionalGroup, opt: true }, + { no: 1, name: "layer1optionalgroup", kind: "message", T: TestNestedGroupExtensionOuter_Layer1OptionalGroup, delimited: true, opt: true }, ]); static fromBinary(bytes: Uint8Array, options?: Partial): TestNestedGroupExtensionOuter { @@ -7459,8 +7459,8 @@ export class TestNestedGroupExtensionOuter_Layer1OptionalGroup extends Message [ - { no: 2, name: "layer2repeatedgroup", kind: "message", T: TestNestedGroupExtensionOuter_Layer1OptionalGroup_Layer2RepeatedGroup, repeated: true }, - { no: 4, name: "layer2anotheroptionalrepeatedgroup", kind: "message", T: TestNestedGroupExtensionOuter_Layer1OptionalGroup_Layer2AnotherOptionalRepeatedGroup, repeated: true }, + { no: 2, name: "layer2repeatedgroup", kind: "message", T: TestNestedGroupExtensionOuter_Layer1OptionalGroup_Layer2RepeatedGroup, delimited: true, repeated: true }, + { no: 4, name: "layer2anotheroptionalrepeatedgroup", kind: "message", T: TestNestedGroupExtensionOuter_Layer1OptionalGroup_Layer2AnotherOptionalRepeatedGroup, delimited: true, repeated: true }, ]); static fromBinary(bytes: Uint8Array, options?: Partial): TestNestedGroupExtensionOuter_Layer1OptionalGroup { diff --git a/packages/protobuf-test/src/proto2.test.ts b/packages/protobuf-test/src/proto2.test.ts index 546d11ba6..07bc09b58 100644 --- a/packages/protobuf-test/src/proto2.test.ts +++ b/packages/protobuf-test/src/proto2.test.ts @@ -13,20 +13,16 @@ // limitations under the License. import { describe, expect, test } from "@jest/globals"; -import { - Proto2DefaultsMessage as TS_Proto2DefaultsMessage, - Proto2Enum as TS_Proto2Enum, - Proto2RequiredDefaultsMessage as TS_Proto2RequiredDefaultsMessage, - Proto2RequiredMessage as TS_Proto2RequiredMessage, -} from "./gen/ts/extra/proto2_pb.js"; -import { - Proto2DefaultsMessage as JS_Proto2DefaultsMessage, - Proto2RequiredDefaultsMessage as JS_Proto2RequiredDefaultsMessage, - Proto2RequiredMessage as JS_Proto2RequiredMessage, -} from "./gen/js/extra/proto2_pb.js"; +import * as TS from "./gen/ts/extra/proto2_pb.js"; +import * as JS from "./gen/js/extra/proto2_pb.js"; import { describeMT, testMT } from "./helpers.js"; import type { AnyMessage, Message } from "@bufbuild/protobuf"; -import { protoInt64 } from "@bufbuild/protobuf"; +import { + BinaryReader, + BinaryWriter, + protoInt64, + WireType, +} from "@bufbuild/protobuf"; function setDefaults(m: AnyMessage): void { for (const f of m.getType().fields.list()) { @@ -44,8 +40,8 @@ function verify(m: T): boolean { } describe("setDefaults", () => { - testMT( - { ts: TS_Proto2DefaultsMessage, js: JS_Proto2DefaultsMessage }, + testMT( + { ts: TS.Proto2DefaultsMessage, js: JS.Proto2DefaultsMessage }, (messageType) => { const msg = new messageType(); setDefaults(msg); @@ -59,17 +55,17 @@ describe("setDefaults", () => { expect(msg.int32Field).toBe(128); expect(msg.int46Field).toBe(protoInt64.parse("-256")); expect(msg.floatField).toBe(-512.13); - expect(msg.enumField).toBe(TS_Proto2Enum.YES); + expect(msg.enumField).toBe(TS.Proto2Enum.YES); expect(msg.messageField).toBe(undefined); }, ); }); describe("verify", () => { - testMT( + testMT( { - ts: TS_Proto2RequiredDefaultsMessage, - js: JS_Proto2RequiredDefaultsMessage, + ts: TS.Proto2RequiredDefaultsMessage, + js: JS.Proto2RequiredDefaultsMessage, }, (messageType) => { const msg = new messageType({ @@ -82,8 +78,8 @@ describe("verify", () => { ); }); -describeMT( - { ts: TS_Proto2RequiredMessage, js: JS_Proto2RequiredMessage }, +describeMT( + { ts: TS.Proto2RequiredMessage, js: JS.Proto2RequiredMessage }, (messageType) => { test("has expected defaults", () => { const got = { ...new messageType() }; @@ -117,7 +113,7 @@ describeMT( ); describeMT( - { ts: TS_Proto2DefaultsMessage, js: JS_Proto2DefaultsMessage }, + { ts: TS.Proto2DefaultsMessage, js: JS.Proto2DefaultsMessage }, (messageType) => { test("has no default values", () => { const got = { ...new messageType() }; @@ -125,3 +121,240 @@ describeMT( }); }, ); + +describe("proto2 group", () => { + const fieldNumbers = { + "Proto2GroupsMessage.group": 1, + "Proto2GroupsMessage.repeatedgroup": 2, + "Proto2GroupsMessage.oneofgroup": 3, + "Proto2GroupsMessage.message_field_using_group": 4, + "Proto2GroupsMessage.message_field_using_nested_group": 5, + "Proto2GroupsMessage.Group.int32_field": 1, + "Proto2GroupsMessage.Group.nestedgroup": 2, + "Proto2GroupsMessage.Group.NestedGroup.string_field": 1, + "Proto2GroupsMessage.RepeatedGroup.int32_field": 1, + "Proto2GroupsMessage.OneofGroup.bool_field": 1, + }; + describe("field info", () => { + describeMT( + { ts: TS.Proto2GroupsMessage, js: JS.Proto2GroupsMessage }, + (messageType) => { + test("field group", () => { + const f = messageType.fields.find( + fieldNumbers["Proto2GroupsMessage.group"], + ); + expect(f?.name).toBe("group"); + expect(f?.kind).toBe("message"); + expect(f?.delimited).toBe(true); + const mt = f?.kind == "message" ? f.T : null; + expect(mt?.typeName).toBe("spec.Proto2GroupsMessage.Group"); + }); + test("field repeatedgroup", () => { + const f = messageType.fields.find( + fieldNumbers["Proto2GroupsMessage.repeatedgroup"], + ); + expect(f?.name).toBe("repeatedgroup"); + expect(f?.repeated).toBe(true); + expect(f?.kind).toBe("message"); + expect(f?.delimited).toBe(true); + const mt = f?.kind == "message" ? f.T : null; + expect(mt?.typeName).toBe("spec.Proto2GroupsMessage.RepeatedGroup"); + }); + test("field oneofgroup", () => { + const f = messageType.fields.find( + fieldNumbers["Proto2GroupsMessage.oneofgroup"], + ); + expect(f?.name).toBe("oneofgroup"); + expect(f?.oneof).toBeDefined(); + expect(f?.kind).toBe("message"); + expect(f?.delimited).toBe(true); + const mt = f?.kind == "message" ? f.T : null; + expect(mt?.typeName).toBe("spec.Proto2GroupsMessage.OneofGroup"); + }); + test("field message_field_using_group", () => { + const f = messageType.fields.find( + fieldNumbers["Proto2GroupsMessage.message_field_using_group"], + ); + expect(f?.name).toBe("message_field_using_group"); + expect(f?.kind).toBe("message"); + expect(f?.delimited).toBe(false); + const mt = f?.kind == "message" ? f.T : null; + expect(mt?.typeName).toBe("spec.Proto2GroupsMessage.Group"); + }); + test("field message_field_using_nested_group", () => { + const f = messageType.fields.find( + fieldNumbers[ + "Proto2GroupsMessage.message_field_using_nested_group" + ], + ); + expect(f?.name).toBe("message_field_using_nested_group"); + expect(f?.kind).toBe("message"); + expect(f?.delimited).toBe(false); + const mt = f?.kind == "message" ? f.T : null; + expect(mt?.typeName).toBe( + "spec.Proto2GroupsMessage.Group.NestedGroup", + ); + }); + }, + ); + describeMT( + { ts: TS.Proto2GroupsMessage_Group, js: JS.Proto2GroupsMessage_Group }, + (messageType) => { + test("field int32_field", () => { + const f = messageType.fields.find( + fieldNumbers["Proto2GroupsMessage.Group.int32_field"], + ); + expect(f?.name).toBe("int32_field"); + expect(f?.kind).toBe("scalar"); + }); + test("field nestedgroup", () => { + const f = messageType.fields.find( + fieldNumbers["Proto2GroupsMessage.Group.nestedgroup"], + ); + expect(f?.name).toBe("nestedgroup"); + expect(f?.kind).toBe("message"); + expect(f?.delimited).toBe(true); + const mt = f?.kind == "message" ? f.T : null; + expect(mt?.typeName).toBe( + "spec.Proto2GroupsMessage.Group.NestedGroup", + ); + }); + }, + ); + describeMT( + { + ts: TS.Proto2GroupsMessage_Group_NestedGroup, + js: JS.Proto2GroupsMessage_Group_NestedGroup, + }, + (messageType) => { + test("field string_field", () => { + const f = messageType.fields.find( + fieldNumbers["Proto2GroupsMessage.Group.NestedGroup.string_field"], + ); + expect(f?.name).toBe("string_field"); + expect(f?.kind).toBe("scalar"); + }); + }, + ); + describeMT( + { + ts: TS.Proto2GroupsMessage_RepeatedGroup, + js: JS.Proto2GroupsMessage_RepeatedGroup, + }, + (messageType) => { + test("field int32_field", () => { + const f = messageType.fields.find( + fieldNumbers["Proto2GroupsMessage.RepeatedGroup.int32_field"], + ); + expect(f?.name).toBe("int32_field"); + expect(f?.kind).toBe("scalar"); + }); + }, + ); + }); + describeMT( + { ts: TS.Proto2GroupsMessage, js: JS.Proto2GroupsMessage }, + (messageType) => { + test("parse", () => { + const bytes = new BinaryWriter() + .tag(fieldNumbers["Proto2GroupsMessage.group"], WireType.StartGroup) + .tag( + fieldNumbers["Proto2GroupsMessage.Group.int32_field"], + WireType.Varint, + ) + .int32(123) + .tag(fieldNumbers["Proto2GroupsMessage.group"], WireType.EndGroup) + .finish(); + const m = messageType.fromBinary(bytes); + expect(m.messageFieldUsingGroup).toBeUndefined(); + expect(m.messageFieldUsingNestedGroup).toBeUndefined(); + expect(m.group).toBeDefined(); + expect(m.group?.int32Field).toBe(123); + }); + test("parse wrong end group field no", () => { + const bytes = new BinaryWriter() + .tag(fieldNumbers["Proto2GroupsMessage.group"], WireType.StartGroup) + .tag( + fieldNumbers["Proto2GroupsMessage.group"] + 99, + WireType.EndGroup, + ) + .finish(); + expect(() => messageType.fromBinary(bytes)).toThrow( + /invalid end group tag/, + ); + }); + test("parse missing end group tag", () => { + const bytes = new BinaryWriter() + .tag(fieldNumbers["Proto2GroupsMessage.group"], WireType.StartGroup) + .finish(); + expect(() => messageType.fromBinary(bytes)).toThrow( + /invalid end group tag/, + ); + }); + test("serialize", () => { + const bytes = new messageType({ + group: { + int32Field: 123, + }, + }).toBinary(); + const r = new BinaryReader(bytes); + // expect group start + let [fieldNo, wireType] = r.tag(); + expect(fieldNo).toBe(fieldNumbers["Proto2GroupsMessage.group"]); + expect(wireType).toBe(WireType.StartGroup); + [fieldNo, wireType] = r.tag(); + // expect field in group + expect(fieldNo).toBe( + fieldNumbers["Proto2GroupsMessage.Group.int32_field"], + ); + expect(wireType).toBe(WireType.Varint); + expect(r.int32()).toBe(123); + // expect group end + [fieldNo, wireType] = r.tag(); + expect(fieldNo).toBe(fieldNumbers["Proto2GroupsMessage.group"]); + expect(wireType).toBe(WireType.EndGroup); + }); + test("simple roundtrip", () => { + const a = new messageType({ + group: { + int32Field: 123, + }, + }); + const bytes = a.toBinary(); + const b = messageType.fromBinary(bytes); + expect(a.equals(b)).toBe(true); + }); + test("full round trip", () => { + const a = new messageType({ + group: { + int32Field: 123, + nestedgroup: { + stringField: "abc", + }, + }, + repeatedgroup: [ + { int32Field: 1 }, + { int32Field: 2 }, + { int32Field: 3 }, + ], + oneofWithGroup: { + case: "oneofgroup", + value: { boolField: true }, + }, + messageFieldUsingGroup: { + int32Field: 456, + nestedgroup: { + stringField: "def", + }, + }, + messageFieldUsingNestedGroup: { + stringField: "ghi", + }, + }); + const bytes = a.toBinary(); + const b = messageType.fromBinary(bytes); + expect(a.equals(b)).toBe(true); + }); + }, + ); +}); diff --git a/packages/protobuf/src/binary-encoding.ts b/packages/protobuf/src/binary-encoding.ts index 54d086da5..26c0c0c6f 100644 --- a/packages/protobuf/src/binary-encoding.ts +++ b/packages/protobuf/src/binary-encoding.ts @@ -53,14 +53,13 @@ export enum WireType { LengthDelimited = 2, /** - * Used for groups - * @deprecated + * Start of a tag-delimited aggregate, such as a proto2 group, or a message + * in editions with message_encoding = DELIMITED. */ StartGroup = 3, /** - * Used for groups - * @deprecated + * End of a tag-delimited aggregate. */ EndGroup = 4, diff --git a/packages/protobuf/src/binary-format.ts b/packages/protobuf/src/binary-format.ts index da3bfd2ed..26215be25 100644 --- a/packages/protobuf/src/binary-format.ts +++ b/packages/protobuf/src/binary-format.ts @@ -41,12 +41,22 @@ export interface BinaryFormat { /** * Parse a message from binary data, merging fields. + * + * Supports two message encodings: + * - length-prefixed: delimitedMessageEncoding is false or omitted, and + * lengthOrEndTagFieldNo is the expected length of the message in the reader. + * - delimited: delimitedMessageEncoding is true, and lengthOrEndTagFieldNo is + * the field number in a tag with wire type end-group signalling the end of + * the message in the reader. + * + * delimitedMessageEncoding is optional for backwards compatibility. */ readMessage( message: Message, reader: IBinaryReader, - length: number, + lengthOrEndTagFieldNo: number, options: BinaryReadOptions, + delimitedMessageEncoding?: boolean, ): void; /** diff --git a/packages/protobuf/src/create-registry-from-desc.ts b/packages/protobuf/src/create-registry-from-desc.ts index 388df2e9a..450630c10 100644 --- a/packages/protobuf/src/create-registry-from-desc.ts +++ b/packages/protobuf/src/create-registry-from-desc.ts @@ -49,7 +49,10 @@ import { UInt32Value, UInt64Value, } from "./google/protobuf/wrappers_pb.js"; -import { FileDescriptorSet } from "./google/protobuf/descriptor_pb.js"; +import { + FieldDescriptorProto_Type, + FileDescriptorSet, +} from "./google/protobuf/descriptor_pb.js"; import type { DescField, DescriptorSet } from "./descriptor-set.js"; import { createDescriptorSet } from "./create-descriptor-set.js"; @@ -337,6 +340,7 @@ function makeMessageFieldInfo( name: field.name, jsonName: field.jsonName, T: messageType, + delimited: field.proto.type == FieldDescriptorProto_Type.GROUP, } as const; if (field.repeated) { return { diff --git a/packages/protobuf/src/field.ts b/packages/protobuf/src/field.ts index 80fe1ac5d..5cad47149 100644 --- a/packages/protobuf/src/field.ts +++ b/packages/protobuf/src/field.ts @@ -40,6 +40,7 @@ import type { MessageType } from "./message-type.js"; * * - "oneof": If the field is member of a oneof group. * - "default": Only proto2: An explicit default value. + * - "delimited": Only proto2: Use the tag-delimited group encoding. */ export type FieldInfo = | fiRules @@ -73,6 +74,7 @@ export interface OneofInfo { readonly packed: false; readonly opt: false; readonly default: undefined; + readonly delimited?: undefined; readonly fields: readonly FieldInfo[]; /** @@ -162,6 +164,14 @@ interface fiScalar extends fiShared { * Only proto2: An explicit default value. */ readonly default: number | boolean | string | bigint | Uint8Array | undefined; + + /** + * Serialize this message with the delimited format, also known as group + * encoding, as opposed to the standard length prefix. + * + * Only valid for message fields. + */ + readonly delimited?: undefined; } interface fiMessage extends fiShared { @@ -186,6 +196,14 @@ interface fiMessage extends fiShared { * An explicit default value (only proto2). Never set for messages. */ readonly default: undefined; + + /** + * Serialize this message with the delimited format, also known as group + * encoding, as opposed to the standard length prefix. + * + * Only valid for message fields. + */ + readonly delimited?: boolean; } interface fiEnum extends fiShared { @@ -217,6 +235,14 @@ interface fiEnum extends fiShared { * Only proto2: An explicit default value. */ readonly default: number | undefined; + + /** + * Serialize this message with the delimited format, also known as group + * encoding, as opposed to the standard length prefix. + * + * Only valid for message fields. + */ + readonly delimited?: undefined; } interface fiMap extends fiShared { @@ -256,6 +282,14 @@ interface fiMap extends fiShared { * An explicit default value (only proto2). Never set for maps. */ readonly default: undefined; + + /** + * Serialize this message with the delimited format, also known as group + * encoding, as opposed to the standard length prefix. + * + * Only valid for message fields. + */ + readonly delimited?: undefined; } // prettier-ignore @@ -266,11 +300,11 @@ type fiRules = Omit & | { readonly repeated: false, readonly packed: false, readonly opt: false; readonly oneof: OneofInfo; }); // prettier-ignore -type fiPartialRules = Omit & ( - | { readonly jsonName?: string; readonly repeated?: false; readonly packed?: false; readonly opt?: false; readonly oneof?: undefined; default?: T["default"]; L?: LongType; } - | { readonly jsonName?: string; readonly repeated?: false; readonly packed?: false; readonly opt: true; readonly oneof?: undefined; default?: T["default"]; L?: LongType; } - | { readonly jsonName?: string; readonly repeated?: boolean; readonly packed?: boolean; readonly opt?: false; readonly oneof?: undefined; default?: T["default"]; L?: LongType; } - | { readonly jsonName?: string; readonly repeated?: false; readonly packed?: false; readonly opt?: false; readonly oneof: string; default?: T["default"]; L?: LongType; }); +type fiPartialRules = Omit & ( + | { readonly jsonName?: string; readonly repeated?: false; readonly packed?: false; readonly opt?: false; readonly oneof?: undefined; default?: T["default"]; L?: LongType; delimited?: boolean; } + | { readonly jsonName?: string; readonly repeated?: false; readonly packed?: false; readonly opt: true; readonly oneof?: undefined; default?: T["default"]; L?: LongType; delimited?: boolean; } + | { readonly jsonName?: string; readonly repeated?: boolean; readonly packed?: boolean; readonly opt?: false; readonly oneof?: undefined; default?: T["default"]; L?: LongType; delimited?: boolean; } + | { readonly jsonName?: string; readonly repeated?: false; readonly packed?: false; readonly opt?: false; readonly oneof: string; default?: T["default"]; L?: LongType; delimited?: boolean; }); /** * Scalar value types. This is a subset of field types declared by protobuf diff --git a/packages/protobuf/src/private/binary-format-common.ts b/packages/protobuf/src/private/binary-format-common.ts index e58b5014c..61e1c5bcb 100644 --- a/packages/protobuf/src/private/binary-format-common.ts +++ b/packages/protobuf/src/private/binary-format-common.ts @@ -25,7 +25,6 @@ import { LongType, ScalarType } from "../field.js"; import { wrapField } from "./field-wrapper.js"; import { scalarDefaultValue, scalarTypeInfo } from "./scalars.js"; import { assert } from "./assert.js"; -import type { MessageType } from "../message-type.js"; /* eslint-disable @typescript-eslint/no-unsafe-return, @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-explicit-any, @typescript-eslint/no-unsafe-argument, @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-call, @typescript-eslint/no-unnecessary-condition, no-case-declarations, prefer-const */ @@ -91,14 +90,22 @@ export function makeBinaryFormatCommon(): Omit { readMessage>( message: T, reader: IBinaryReader, - length: number, + lengthOrEndTagFieldNo: number, options: BinaryReadOptions, + delimitedMessageEncoding?: boolean, ): void { const type = message.getType(); - const end = length === undefined ? reader.len : reader.pos + length; + // eslint-disable-next-line @typescript-eslint/strict-boolean-expressions + const end = delimitedMessageEncoding + ? reader.len + : reader.pos + lengthOrEndTagFieldNo; + let fieldNo: number | undefined, wireType: WireType | undefined; while (reader.pos < end) { - const [fieldNo, wireType] = reader.tag(), - field = type.fields.find(fieldNo); + [fieldNo, wireType] = reader.tag(); + if (wireType == WireType.EndGroup) { + break; + } + const field = type.fields.find(fieldNo); if (!field) { const data = reader.skip(wireType); if (options.readUnknownFields) { @@ -150,16 +157,17 @@ export function makeBinaryFormatCommon(): Omit { if (repeated) { // safe to assume presence of array, oneof cannot contain repeated values (target[localName] as any[]).push( - readMessageField(reader, new messageType(), options), + readMessageField(reader, new messageType(), options, field), ); } else { if (target[localName] instanceof Message) { - readMessageField(reader, target[localName], options); + readMessageField(reader, target[localName], options, field); } else { target[localName] = readMessageField( reader, new messageType(), options, + field, ); if ( messageType.fieldWrapper && @@ -180,6 +188,12 @@ export function makeBinaryFormatCommon(): Omit { break; } } + if ( + delimitedMessageEncoding && // eslint-disable-line @typescript-eslint/strict-boolean-expressions + (wireType != WireType.EndGroup || fieldNo !== lengthOrEndTagFieldNo) + ) { + throw new Error(`invalid end group tag`); + } }, }; } @@ -190,9 +204,17 @@ function readMessageField( reader: IBinaryReader, message: T, options: BinaryReadOptions, + field: { kind: "message"; no: number; delimited?: boolean } | undefined, ): T { const format = message.getType().runtime.bin; - format.readMessage(message, reader, reader.uint32(), options); + const delimited = field?.delimited; + format.readMessage( + message, + reader, + delimited ? field?.no : reader.uint32(), // eslint-disable-line @typescript-eslint/strict-boolean-expressions + options, + delimited, + ); return message; } @@ -220,7 +242,7 @@ function readMapEntry( val = reader.int32(); break; case "message": - val = readMessageField(reader, new field.V.T(), options); + val = readMessageField(reader, new field.V.T(), options, undefined); break; } break; @@ -335,7 +357,7 @@ export function writeMapEntry( writeScalar(writer, ScalarType.INT32, 2, value, true); break; case "message": - writeMessageField(writer, options, field.V.T, 2, value); + writer.tag(2, WireType.LengthDelimited).bytes(value.toBinary(options)); break; } @@ -345,15 +367,21 @@ export function writeMapEntry( export function writeMessageField( writer: IBinaryWriter, options: BinaryWriteOptions, - type: MessageType, - fieldNo: number, + field: FieldInfo & { kind: "message" }, value: any, ): void { if (value !== undefined) { - const message = wrapField(type, value); - writer - .tag(fieldNo, WireType.LengthDelimited) - .bytes(message.toBinary(options)); + const message = wrapField(field.T, value); + // eslint-disable-next-line @typescript-eslint/strict-boolean-expressions + if (field?.delimited) + writer + .tag(field.no, WireType.StartGroup) + .raw(message.toBinary(options)) + .tag(field.no, WireType.EndGroup); + else + writer + .tag(field.no, WireType.LengthDelimited) + .bytes(message.toBinary(options)); } } diff --git a/packages/protobuf/src/private/binary-format-proto2.ts b/packages/protobuf/src/private/binary-format-proto2.ts index 0f6971928..61186b0b2 100644 --- a/packages/protobuf/src/private/binary-format-proto2.ts +++ b/packages/protobuf/src/private/binary-format-proto2.ts @@ -82,10 +82,10 @@ export function makeBinaryFormatProto2(): BinaryFormat { case "message": if (repeated) { for (const item of value) { - writeMessageField(writer, options, field.T, field.no, item); + writeMessageField(writer, options, field, item); } } else { - writeMessageField(writer, options, field.T, field.no, value); + writeMessageField(writer, options, field, value); } break; case "map": diff --git a/packages/protobuf/src/private/binary-format-proto3.ts b/packages/protobuf/src/private/binary-format-proto3.ts index 2f0adb512..acacb6aac 100644 --- a/packages/protobuf/src/private/binary-format-proto3.ts +++ b/packages/protobuf/src/private/binary-format-proto3.ts @@ -77,10 +77,10 @@ export function makeBinaryFormatProto3(): BinaryFormat { case "message": if (repeated) { for (const item of value) { - writeMessageField(writer, options, field.T, field.no, item); + writeMessageField(writer, options, field, item); } } else { - writeMessageField(writer, options, field.T, field.no, value); + writeMessageField(writer, options, field, value); } break; case "map": diff --git a/packages/protobuf/src/proto2.ts b/packages/protobuf/src/proto2.ts index 08acc38c9..ed61bd0f7 100644 --- a/packages/protobuf/src/proto2.ts +++ b/packages/protobuf/src/proto2.ts @@ -83,8 +83,6 @@ function normalizeFieldInfosProto2(fieldInfos: FieldListSource): FieldInfo[] { if (field.kind == "scalar") { f.L = field.L ?? LongType.BIGINT; } - // In contrast to proto3, repeated fields are unpacked except when explicitly specified. - f.packed = field.packed ?? false; // We do not surface options at this time // f.options = field.options ?? emptyReadonlyObject; if (field.oneof !== undefined) { @@ -96,6 +94,12 @@ function normalizeFieldInfosProto2(fieldInfos: FieldListSource): FieldInfo[] { f.oneof = o; o.addField(f); } + // proto2 specific: + if (field.kind == "message") { + f.delimited = field.delimited ?? false; + } + // In contrast to proto3, repeated fields are unpacked except when explicitly specified. + f.packed = field.packed ?? false; r.push(f); } return r; diff --git a/packages/protobuf/src/proto3.ts b/packages/protobuf/src/proto3.ts index b4a77606b..157d8fff8 100644 --- a/packages/protobuf/src/proto3.ts +++ b/packages/protobuf/src/proto3.ts @@ -86,17 +86,6 @@ function normalizeFieldInfosProto3(fieldInfos: FieldListSource): FieldInfo[] { if (field.kind == "scalar") { f.L = field.L ?? LongType.BIGINT; } - // From the proto3 language guide: - // > In proto3, repeated fields of scalar numeric types are packed by default. - // This information is incomplete - according to the conformance tests, BOOL - // and ENUM are packed by default as well. This means only STRING and BYTES - // are not packed by default, which makes sense because they are length-delimited. - f.packed = - field.packed ?? - (field.kind == "enum" || - (field.kind == "scalar" && - field.T != ScalarType.BYTES && - field.T != ScalarType.STRING)); // We do not surface options at this time // f.options = field.options ?? emptyReadonlyObject; if (field.oneof !== undefined) { @@ -108,6 +97,22 @@ function normalizeFieldInfosProto3(fieldInfos: FieldListSource): FieldInfo[] { f.oneof = o; o.addField(f); } + // proto3 specific: + if (field.kind == "message") { + f.delimited = false; + } + // From the proto3 language guide: + // > In proto3, repeated fields of scalar numeric types are packed by default. + // This information is incomplete - according to the conformance tests, BOOL + // and ENUM are packed by default as well. This means only STRING and BYTES + // are not packed by default, which makes sense because they are length-delimited. + f.packed = + field.packed ?? + (field.kind == "enum" || + (field.kind == "scalar" && + field.T != ScalarType.BYTES && + field.T != ScalarType.STRING)); + r.push(f); } return r; diff --git a/packages/protoc-gen-es/src/javascript.ts b/packages/protoc-gen-es/src/javascript.ts index f1cec013e..1a9bdcb60 100644 --- a/packages/protoc-gen-es/src/javascript.ts +++ b/packages/protoc-gen-es/src/javascript.ts @@ -13,7 +13,13 @@ // limitations under the License. import type { DescEnum, DescField, DescMessage } from "@bufbuild/protobuf"; -import { LongType, proto2, proto3, ScalarType } from "@bufbuild/protobuf"; +import { + FieldDescriptorProto_Type, + LongType, + proto2, + proto3, + ScalarType, +} from "@bufbuild/protobuf"; import type { GeneratedFile, Printable, @@ -130,6 +136,9 @@ export function generateFieldInfo(schema: Schema, f: GeneratedFile, field: DescF break; case "message": e.push(`kind: "message", T: `, field.message, `, `); + if (field.proto.type === FieldDescriptorProto_Type.GROUP) { + e.push(`delimited: true, `); + } break; case "enum": e.push(`kind: "enum", T: `, protoN, `.getEnumType(`, field.enum, `), `);