proto: switch messageset_test to use makeMessages() injection point

This required renaming the extension fields to have distinct names, as
makeMessages() uses the protobuild package, which works with field names.

The makeMessages() function can be centrally extended with other variants of
testprotos (e.g. editions).

Change-Id: I68ef28baee674c6b53da8629c5ff7b2e1b92d4ff
Reviewed-on: https://go-review.googlesource.com/c/protobuf/+/624415
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Chressie Himpel <chressie@google.com>
This commit is contained in:
Michael Stapelberg 2024-11-01 13:48:19 +01:00
parent 29947bbd16
commit 76135f99d5
5 changed files with 186 additions and 156 deletions

View File

@ -18,11 +18,11 @@ func TestConcurrentInitialization(t *testing.T) {
wg.Add(2)
go func() {
defer wg.Done()
epb.E_Ext1_MessageSetExtension.ValueOf(&epb.Ext1{})
epb.E_Ext1_MessageSetExt1.ValueOf(&epb.Ext1{})
}()
go func() {
defer wg.Done()
epb.E_Ext1_MessageSetExtension.TypeDescriptor().Message()
epb.E_Ext1_MessageSetExt1.TypeDescriptor().Message()
}()
wg.Wait()
}

View File

@ -15,7 +15,7 @@ message MessageSet {
extensions 530000000 to max
[declaration = {
number: 536870912
full_name: ".goproto.proto.messageset.ExtLargeNumber.message_set_extension"
full_name: ".goproto.proto.messageset.ExtLargeNumber.message_set_extlarge"
type: ".goproto.proto.messageset.ExtLargeNumber"
}];
}

View File

@ -199,46 +199,46 @@ var file_internal_testprotos_messageset_msetextpb_msetextpb_proto_extTypes = []p
ExtendedType: (*messagesetpb.MessageSet)(nil),
ExtensionType: (*Ext1)(nil),
Field: 1000,
Name: "goproto.proto.messageset.Ext1.message_set_extension",
Tag: "bytes,1000,opt,name=message_set_extension",
Name: "goproto.proto.messageset.Ext1.message_set_ext1",
Tag: "bytes,1000,opt,name=message_set_ext1",
Filename: "internal/testprotos/messageset/msetextpb/msetextpb.proto",
},
{
ExtendedType: (*messagesetpb.MessageSet)(nil),
ExtensionType: (*Ext2)(nil),
Field: 1001,
Name: "goproto.proto.messageset.Ext2.message_set_extension",
Tag: "bytes,1001,opt,name=message_set_extension",
Name: "goproto.proto.messageset.Ext2.message_set_ext2",
Tag: "bytes,1001,opt,name=message_set_ext2",
Filename: "internal/testprotos/messageset/msetextpb/msetextpb.proto",
},
{
ExtendedType: (*messagesetpb.MessageSet)(nil),
ExtensionType: (*ExtRequired)(nil),
Field: 1002,
Name: "goproto.proto.messageset.ExtRequired.message_set_extension",
Tag: "bytes,1002,opt,name=message_set_extension",
Name: "goproto.proto.messageset.ExtRequired.message_set_extrequired",
Tag: "bytes,1002,opt,name=message_set_extrequired",
Filename: "internal/testprotos/messageset/msetextpb/msetextpb.proto",
},
{
ExtendedType: (*messagesetpb.MessageSet)(nil),
ExtensionType: (*ExtLargeNumber)(nil),
Field: 536870912,
Name: "goproto.proto.messageset.ExtLargeNumber.message_set_extension",
Tag: "bytes,536870912,opt,name=message_set_extension",
Name: "goproto.proto.messageset.ExtLargeNumber.message_set_extlarge",
Tag: "bytes,536870912,opt,name=message_set_extlarge",
Filename: "internal/testprotos/messageset/msetextpb/msetextpb.proto",
},
}
// Extension fields to messagesetpb.MessageSet.
var (
// optional goproto.proto.messageset.Ext1 message_set_extension = 1000;
E_Ext1_MessageSetExtension = &file_internal_testprotos_messageset_msetextpb_msetextpb_proto_extTypes[0]
// optional goproto.proto.messageset.Ext2 message_set_extension = 1001;
E_Ext2_MessageSetExtension = &file_internal_testprotos_messageset_msetextpb_msetextpb_proto_extTypes[1]
// optional goproto.proto.messageset.ExtRequired message_set_extension = 1002;
E_ExtRequired_MessageSetExtension = &file_internal_testprotos_messageset_msetextpb_msetextpb_proto_extTypes[2]
// optional goproto.proto.messageset.ExtLargeNumber message_set_extension = 536870912;
E_ExtLargeNumber_MessageSetExtension = &file_internal_testprotos_messageset_msetextpb_msetextpb_proto_extTypes[3] // 1<<29
// optional goproto.proto.messageset.Ext1 message_set_ext1 = 1000;
E_Ext1_MessageSetExt1 = &file_internal_testprotos_messageset_msetextpb_msetextpb_proto_extTypes[0]
// optional goproto.proto.messageset.Ext2 message_set_ext2 = 1001;
E_Ext2_MessageSetExt2 = &file_internal_testprotos_messageset_msetextpb_msetextpb_proto_extTypes[1]
// optional goproto.proto.messageset.ExtRequired message_set_extrequired = 1002;
E_ExtRequired_MessageSetExtrequired = &file_internal_testprotos_messageset_msetextpb_msetextpb_proto_extTypes[2]
// optional goproto.proto.messageset.ExtLargeNumber message_set_extlarge = 536870912;
E_ExtLargeNumber_MessageSetExtlarge = &file_internal_testprotos_messageset_msetextpb_msetextpb_proto_extTypes[3] // 1<<29
)
var File_internal_testprotos_messageset_msetextpb_msetextpb_proto protoreflect.FileDescriptor
@ -253,55 +253,54 @@ var file_internal_testprotos_messageset_msetextpb_msetextpb_proto_rawDesc = []by
0x65, 0x73, 0x74, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x73, 0x2f, 0x6d, 0x65, 0x73, 0x73, 0x61, 0x67,
0x65, 0x73, 0x65, 0x74, 0x2f, 0x6d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x73, 0x65, 0x74, 0x70,
0x62, 0x2f, 0x6d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x5f, 0x73, 0x65, 0x74, 0x2e, 0x70, 0x72,
0x6f, 0x74, 0x6f, 0x22, 0xc3, 0x01, 0x0a, 0x04, 0x45, 0x78, 0x74, 0x31, 0x12, 0x1f, 0x0a, 0x0b,
0x6f, 0x74, 0x6f, 0x22, 0xb9, 0x01, 0x0a, 0x04, 0x45, 0x78, 0x74, 0x31, 0x12, 0x1f, 0x0a, 0x0b,
0x65, 0x78, 0x74, 0x31, 0x5f, 0x66, 0x69, 0x65, 0x6c, 0x64, 0x31, 0x18, 0x01, 0x20, 0x01, 0x28,
0x05, 0x52, 0x0a, 0x65, 0x78, 0x74, 0x31, 0x46, 0x69, 0x65, 0x6c, 0x64, 0x31, 0x12, 0x1f, 0x0a,
0x0b, 0x65, 0x78, 0x74, 0x31, 0x5f, 0x66, 0x69, 0x65, 0x6c, 0x64, 0x32, 0x18, 0x02, 0x20, 0x01,
0x28, 0x05, 0x52, 0x0a, 0x65, 0x78, 0x74, 0x31, 0x46, 0x69, 0x65, 0x6c, 0x64, 0x32, 0x32, 0x79,
0x0a, 0x15, 0x6d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x5f, 0x73, 0x65, 0x74, 0x5f, 0x65, 0x78,
0x74, 0x65, 0x6e, 0x73, 0x69, 0x6f, 0x6e, 0x12, 0x24, 0x2e, 0x67, 0x6f, 0x70, 0x72, 0x6f, 0x74,
0x6f, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2e, 0x6d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x73,
0x65, 0x74, 0x2e, 0x4d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x53, 0x65, 0x74, 0x18, 0xe8, 0x07,
0x20, 0x01, 0x28, 0x0b, 0x32, 0x1e, 0x2e, 0x67, 0x6f, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2e, 0x70,
0x72, 0x6f, 0x74, 0x6f, 0x2e, 0x6d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x73, 0x65, 0x74, 0x2e,
0x45, 0x78, 0x74, 0x31, 0x52, 0x13, 0x6d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x53, 0x65, 0x74,
0x45, 0x78, 0x74, 0x65, 0x6e, 0x73, 0x69, 0x6f, 0x6e, 0x22, 0xa2, 0x01, 0x0a, 0x04, 0x45, 0x78,
0x74, 0x32, 0x12, 0x1f, 0x0a, 0x0b, 0x65, 0x78, 0x74, 0x32, 0x5f, 0x66, 0x69, 0x65, 0x6c, 0x64,
0x31, 0x18, 0x01, 0x20, 0x01, 0x28, 0x05, 0x52, 0x0a, 0x65, 0x78, 0x74, 0x32, 0x46, 0x69, 0x65,
0x6c, 0x64, 0x31, 0x32, 0x79, 0x0a, 0x15, 0x6d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x5f, 0x73,
0x65, 0x74, 0x5f, 0x65, 0x78, 0x74, 0x65, 0x6e, 0x73, 0x69, 0x6f, 0x6e, 0x12, 0x24, 0x2e, 0x67,
0x28, 0x05, 0x52, 0x0a, 0x65, 0x78, 0x74, 0x31, 0x46, 0x69, 0x65, 0x6c, 0x64, 0x32, 0x32, 0x6f,
0x0a, 0x10, 0x6d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x5f, 0x73, 0x65, 0x74, 0x5f, 0x65, 0x78,
0x74, 0x31, 0x12, 0x24, 0x2e, 0x67, 0x6f, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2e, 0x70, 0x72, 0x6f,
0x74, 0x6f, 0x2e, 0x6d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x73, 0x65, 0x74, 0x2e, 0x4d, 0x65,
0x73, 0x73, 0x61, 0x67, 0x65, 0x53, 0x65, 0x74, 0x18, 0xe8, 0x07, 0x20, 0x01, 0x28, 0x0b, 0x32,
0x1e, 0x2e, 0x67, 0x6f, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2e,
0x6d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x73, 0x65, 0x74, 0x2e, 0x45, 0x78, 0x74, 0x31, 0x52,
0x0e, 0x6d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x53, 0x65, 0x74, 0x45, 0x78, 0x74, 0x31, 0x22,
0x98, 0x01, 0x0a, 0x04, 0x45, 0x78, 0x74, 0x32, 0x12, 0x1f, 0x0a, 0x0b, 0x65, 0x78, 0x74, 0x32,
0x5f, 0x66, 0x69, 0x65, 0x6c, 0x64, 0x31, 0x18, 0x01, 0x20, 0x01, 0x28, 0x05, 0x52, 0x0a, 0x65,
0x78, 0x74, 0x32, 0x46, 0x69, 0x65, 0x6c, 0x64, 0x31, 0x32, 0x6f, 0x0a, 0x10, 0x6d, 0x65, 0x73,
0x73, 0x61, 0x67, 0x65, 0x5f, 0x73, 0x65, 0x74, 0x5f, 0x65, 0x78, 0x74, 0x32, 0x12, 0x24, 0x2e,
0x67, 0x6f, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2e, 0x6d, 0x65,
0x73, 0x73, 0x61, 0x67, 0x65, 0x73, 0x65, 0x74, 0x2e, 0x4d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65,
0x53, 0x65, 0x74, 0x18, 0xe9, 0x07, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x1e, 0x2e, 0x67, 0x6f, 0x70,
0x72, 0x6f, 0x74, 0x6f, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2e, 0x6d, 0x65, 0x73, 0x73, 0x61,
0x67, 0x65, 0x73, 0x65, 0x74, 0x2e, 0x45, 0x78, 0x74, 0x32, 0x52, 0x0e, 0x6d, 0x65, 0x73, 0x73,
0x61, 0x67, 0x65, 0x53, 0x65, 0x74, 0x45, 0x78, 0x74, 0x32, 0x22, 0xbd, 0x01, 0x0a, 0x0b, 0x45,
0x78, 0x74, 0x52, 0x65, 0x71, 0x75, 0x69, 0x72, 0x65, 0x64, 0x12, 0x27, 0x0a, 0x0f, 0x72, 0x65,
0x71, 0x75, 0x69, 0x72, 0x65, 0x64, 0x5f, 0x66, 0x69, 0x65, 0x6c, 0x64, 0x31, 0x18, 0x01, 0x20,
0x02, 0x28, 0x05, 0x52, 0x0e, 0x72, 0x65, 0x71, 0x75, 0x69, 0x72, 0x65, 0x64, 0x46, 0x69, 0x65,
0x6c, 0x64, 0x31, 0x32, 0x84, 0x01, 0x0a, 0x17, 0x6d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x5f,
0x73, 0x65, 0x74, 0x5f, 0x65, 0x78, 0x74, 0x72, 0x65, 0x71, 0x75, 0x69, 0x72, 0x65, 0x64, 0x12,
0x24, 0x2e, 0x67, 0x6f, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2e,
0x6d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x73, 0x65, 0x74, 0x2e, 0x4d, 0x65, 0x73, 0x73, 0x61,
0x67, 0x65, 0x53, 0x65, 0x74, 0x18, 0xea, 0x07, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x25, 0x2e, 0x67,
0x6f, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2e, 0x6d, 0x65, 0x73,
0x73, 0x61, 0x67, 0x65, 0x73, 0x65, 0x74, 0x2e, 0x4d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x53,
0x65, 0x74, 0x18, 0xe9, 0x07, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x1e, 0x2e, 0x67, 0x6f, 0x70, 0x72,
0x6f, 0x74, 0x6f, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2e, 0x6d, 0x65, 0x73, 0x73, 0x61, 0x67,
0x65, 0x73, 0x65, 0x74, 0x2e, 0x45, 0x78, 0x74, 0x32, 0x52, 0x13, 0x6d, 0x65, 0x73, 0x73, 0x61,
0x67, 0x65, 0x53, 0x65, 0x74, 0x45, 0x78, 0x74, 0x65, 0x6e, 0x73, 0x69, 0x6f, 0x6e, 0x22, 0xb9,
0x01, 0x0a, 0x0b, 0x45, 0x78, 0x74, 0x52, 0x65, 0x71, 0x75, 0x69, 0x72, 0x65, 0x64, 0x12, 0x27,
0x0a, 0x0f, 0x72, 0x65, 0x71, 0x75, 0x69, 0x72, 0x65, 0x64, 0x5f, 0x66, 0x69, 0x65, 0x6c, 0x64,
0x31, 0x18, 0x01, 0x20, 0x02, 0x28, 0x05, 0x52, 0x0e, 0x72, 0x65, 0x71, 0x75, 0x69, 0x72, 0x65,
0x64, 0x46, 0x69, 0x65, 0x6c, 0x64, 0x31, 0x32, 0x80, 0x01, 0x0a, 0x15, 0x6d, 0x65, 0x73, 0x73,
0x61, 0x67, 0x65, 0x5f, 0x73, 0x65, 0x74, 0x5f, 0x65, 0x78, 0x74, 0x65, 0x6e, 0x73, 0x69, 0x6f,
0x6e, 0x12, 0x24, 0x2e, 0x67, 0x6f, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2e, 0x70, 0x72, 0x6f, 0x74,
0x6f, 0x2e, 0x6d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x73, 0x65, 0x74, 0x2e, 0x4d, 0x65, 0x73,
0x73, 0x61, 0x67, 0x65, 0x53, 0x65, 0x74, 0x18, 0xea, 0x07, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x25,
0x2e, 0x67, 0x6f, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2e, 0x6d,
0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x73, 0x65, 0x74, 0x2e, 0x45, 0x78, 0x74, 0x52, 0x65, 0x71,
0x75, 0x69, 0x72, 0x65, 0x64, 0x52, 0x13, 0x6d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x53, 0x65,
0x74, 0x45, 0x78, 0x74, 0x65, 0x6e, 0x73, 0x69, 0x6f, 0x6e, 0x22, 0x99, 0x01, 0x0a, 0x0e, 0x45,
0x78, 0x74, 0x4c, 0x61, 0x72, 0x67, 0x65, 0x4e, 0x75, 0x6d, 0x62, 0x65, 0x72, 0x32, 0x86, 0x01,
0x0a, 0x15, 0x6d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x5f, 0x73, 0x65, 0x74, 0x5f, 0x65, 0x78,
0x74, 0x65, 0x6e, 0x73, 0x69, 0x6f, 0x6e, 0x12, 0x24, 0x2e, 0x67, 0x6f, 0x70, 0x72, 0x6f, 0x74,
0x6f, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2e, 0x6d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x73,
0x65, 0x74, 0x2e, 0x4d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x53, 0x65, 0x74, 0x18, 0x80, 0x80,
0x80, 0x80, 0x02, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x28, 0x2e, 0x67, 0x6f, 0x70, 0x72, 0x6f, 0x74,
0x6f, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2e, 0x6d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x73,
0x65, 0x74, 0x2e, 0x45, 0x78, 0x74, 0x4c, 0x61, 0x72, 0x67, 0x65, 0x4e, 0x75, 0x6d, 0x62, 0x65,
0x72, 0x52, 0x13, 0x6d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x53, 0x65, 0x74, 0x45, 0x78, 0x74,
0x65, 0x6e, 0x73, 0x69, 0x6f, 0x6e, 0x42, 0x45, 0x5a, 0x43, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65,
0x2e, 0x67, 0x6f, 0x6c, 0x61, 0x6e, 0x67, 0x2e, 0x6f, 0x72, 0x67, 0x2f, 0x70, 0x72, 0x6f, 0x74,
0x6f, 0x62, 0x75, 0x66, 0x2f, 0x69, 0x6e, 0x74, 0x65, 0x72, 0x6e, 0x61, 0x6c, 0x2f, 0x74, 0x65,
0x73, 0x74, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x73, 0x2f, 0x6d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65,
0x73, 0x65, 0x74, 0x2f, 0x6d, 0x73, 0x65, 0x74, 0x65, 0x78, 0x74, 0x70, 0x62,
0x73, 0x61, 0x67, 0x65, 0x73, 0x65, 0x74, 0x2e, 0x45, 0x78, 0x74, 0x52, 0x65, 0x71, 0x75, 0x69,
0x72, 0x65, 0x64, 0x52, 0x15, 0x6d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x53, 0x65, 0x74, 0x45,
0x78, 0x74, 0x72, 0x65, 0x71, 0x75, 0x69, 0x72, 0x65, 0x64, 0x22, 0x97, 0x01, 0x0a, 0x0e, 0x45,
0x78, 0x74, 0x4c, 0x61, 0x72, 0x67, 0x65, 0x4e, 0x75, 0x6d, 0x62, 0x65, 0x72, 0x32, 0x84, 0x01,
0x0a, 0x14, 0x6d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x5f, 0x73, 0x65, 0x74, 0x5f, 0x65, 0x78,
0x74, 0x6c, 0x61, 0x72, 0x67, 0x65, 0x12, 0x24, 0x2e, 0x67, 0x6f, 0x70, 0x72, 0x6f, 0x74, 0x6f,
0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2e, 0x6d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x73, 0x65,
0x74, 0x2e, 0x4d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x53, 0x65, 0x74, 0x18, 0x80, 0x80, 0x80,
0x80, 0x02, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x28, 0x2e, 0x67, 0x6f, 0x70, 0x72, 0x6f, 0x74, 0x6f,
0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2e, 0x6d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x73, 0x65,
0x74, 0x2e, 0x45, 0x78, 0x74, 0x4c, 0x61, 0x72, 0x67, 0x65, 0x4e, 0x75, 0x6d, 0x62, 0x65, 0x72,
0x52, 0x12, 0x6d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x53, 0x65, 0x74, 0x45, 0x78, 0x74, 0x6c,
0x61, 0x72, 0x67, 0x65, 0x42, 0x45, 0x5a, 0x43, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x67,
0x6f, 0x6c, 0x61, 0x6e, 0x67, 0x2e, 0x6f, 0x72, 0x67, 0x2f, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62,
0x75, 0x66, 0x2f, 0x69, 0x6e, 0x74, 0x65, 0x72, 0x6e, 0x61, 0x6c, 0x2f, 0x74, 0x65, 0x73, 0x74,
0x70, 0x72, 0x6f, 0x74, 0x6f, 0x73, 0x2f, 0x6d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x73, 0x65,
0x74, 0x2f, 0x6d, 0x73, 0x65, 0x74, 0x65, 0x78, 0x74, 0x70, 0x62,
}
var (
@ -325,14 +324,14 @@ var file_internal_testprotos_messageset_msetextpb_msetextpb_proto_goTypes = []an
(*messagesetpb.MessageSet)(nil), // 4: goproto.proto.messageset.MessageSet
}
var file_internal_testprotos_messageset_msetextpb_msetextpb_proto_depIdxs = []int32{
4, // 0: goproto.proto.messageset.Ext1.message_set_extension:extendee -> goproto.proto.messageset.MessageSet
4, // 1: goproto.proto.messageset.Ext2.message_set_extension:extendee -> goproto.proto.messageset.MessageSet
4, // 2: goproto.proto.messageset.ExtRequired.message_set_extension:extendee -> goproto.proto.messageset.MessageSet
4, // 3: goproto.proto.messageset.ExtLargeNumber.message_set_extension:extendee -> goproto.proto.messageset.MessageSet
0, // 4: goproto.proto.messageset.Ext1.message_set_extension:type_name -> goproto.proto.messageset.Ext1
1, // 5: goproto.proto.messageset.Ext2.message_set_extension:type_name -> goproto.proto.messageset.Ext2
2, // 6: goproto.proto.messageset.ExtRequired.message_set_extension:type_name -> goproto.proto.messageset.ExtRequired
3, // 7: goproto.proto.messageset.ExtLargeNumber.message_set_extension:type_name -> goproto.proto.messageset.ExtLargeNumber
4, // 0: goproto.proto.messageset.Ext1.message_set_ext1:extendee -> goproto.proto.messageset.MessageSet
4, // 1: goproto.proto.messageset.Ext2.message_set_ext2:extendee -> goproto.proto.messageset.MessageSet
4, // 2: goproto.proto.messageset.ExtRequired.message_set_extrequired:extendee -> goproto.proto.messageset.MessageSet
4, // 3: goproto.proto.messageset.ExtLargeNumber.message_set_extlarge:extendee -> goproto.proto.messageset.MessageSet
0, // 4: goproto.proto.messageset.Ext1.message_set_ext1:type_name -> goproto.proto.messageset.Ext1
1, // 5: goproto.proto.messageset.Ext2.message_set_ext2:type_name -> goproto.proto.messageset.Ext2
2, // 6: goproto.proto.messageset.ExtRequired.message_set_extrequired:type_name -> goproto.proto.messageset.ExtRequired
3, // 7: goproto.proto.messageset.ExtLargeNumber.message_set_extlarge:type_name -> goproto.proto.messageset.ExtLargeNumber
8, // [8:8] is the sub-list for method output_type
8, // [8:8] is the sub-list for method input_type
4, // [4:8] is the sub-list for extension type_name

View File

@ -12,7 +12,7 @@ option go_package = "google.golang.org/protobuf/internal/testprotos/messageset/m
message Ext1 {
extend MessageSet {
optional Ext1 message_set_extension = 1000;
optional Ext1 message_set_ext1 = 1000;
}
optional int32 ext1_field1 = 1;
optional int32 ext1_field2 = 2;
@ -20,20 +20,20 @@ message Ext1 {
message Ext2 {
extend MessageSet {
optional Ext2 message_set_extension = 1001;
optional Ext2 message_set_ext2 = 1001;
}
optional int32 ext2_field1 = 1;
}
message ExtRequired {
extend MessageSet {
optional ExtRequired message_set_extension = 1002;
optional ExtRequired message_set_extrequired = 1002;
}
required int32 required_field1 = 1;
}
message ExtLargeNumber {
extend MessageSet {
optional ExtLargeNumber message_set_extension = 536870912; // 1<<29
optional ExtLargeNumber message_set_extlarge = 536870912; // 1<<29
}
}

View File

@ -7,11 +7,12 @@ package proto_test
import (
"google.golang.org/protobuf/encoding/protowire"
"google.golang.org/protobuf/internal/flags"
"google.golang.org/protobuf/internal/protobuild"
"google.golang.org/protobuf/proto"
"google.golang.org/protobuf/testing/protopack"
"google.golang.org/protobuf/internal/testprotos/messageset/messagesetpb"
"google.golang.org/protobuf/internal/testprotos/messageset/msetextpb"
_ "google.golang.org/protobuf/internal/testprotos/messageset/msetextpb"
)
func init() {
@ -24,13 +25,16 @@ func init() {
var messageSetTestProtos = []testProto{
{
desc: "MessageSet type_id before message content",
decodeTo: []proto.Message{func() proto.Message {
m := &messagesetpb.MessageSetContainer{MessageSet: &messagesetpb.MessageSet{}}
proto.SetExtension(m.MessageSet, msetextpb.E_Ext1_MessageSetExtension, &msetextpb.Ext1{
Ext1Field1: proto.Int32(10),
})
return m
}()},
decodeTo: makeMessages(
protobuild.Message{
"message_set": protobuild.Message{
"message_set_ext1": protobuild.Message{
"ext1_field1": 10,
},
},
},
&messagesetpb.MessageSetContainer{},
),
wire: protopack.Message{
protopack.Tag{1, protopack.BytesType}, protopack.LengthPrefix(protopack.Message{
protopack.Tag{1, protopack.StartGroupType},
@ -44,13 +48,16 @@ var messageSetTestProtos = []testProto{
},
{
desc: "MessageSet type_id after message content",
decodeTo: []proto.Message{func() proto.Message {
m := &messagesetpb.MessageSetContainer{MessageSet: &messagesetpb.MessageSet{}}
proto.SetExtension(m.MessageSet, msetextpb.E_Ext1_MessageSetExtension, &msetextpb.Ext1{
Ext1Field1: proto.Int32(10),
})
return m
}()},
decodeTo: makeMessages(
protobuild.Message{
"message_set": protobuild.Message{
"message_set_ext1": protobuild.Message{
"ext1_field1": 10,
},
},
},
&messagesetpb.MessageSetContainer{},
),
wire: protopack.Message{
protopack.Tag{1, protopack.BytesType}, protopack.LengthPrefix(protopack.Message{
protopack.Tag{1, protopack.StartGroupType},
@ -64,12 +71,14 @@ var messageSetTestProtos = []testProto{
},
{
desc: "MessageSet does not preserve unknown field",
decodeTo: []proto.Message{build(
decodeTo: makeMessages(
protobuild.Message{
"message_set_ext1": protobuild.Message{
"ext1_field1": 10,
},
},
&messagesetpb.MessageSet{},
extend(msetextpb.E_Ext1_MessageSetExtension, &msetextpb.Ext1{
Ext1Field1: proto.Int32(10),
}),
)},
),
wire: protopack.Message{
protopack.Tag{1, protopack.StartGroupType},
protopack.Tag{2, protopack.VarintType}, protopack.Varint(1000),
@ -83,14 +92,16 @@ var messageSetTestProtos = []testProto{
},
{
desc: "MessageSet with unknown type_id",
decodeTo: []proto.Message{build(
decodeTo: makeMessages(
protobuild.Message{
protobuild.Unknown: protopack.Message{
protopack.Tag{999, protopack.BytesType}, protopack.LengthPrefix(protopack.Message{
protopack.Tag{1, protopack.VarintType}, protopack.Varint(10),
}),
}.Marshal(),
},
&messagesetpb.MessageSet{},
unknown(protopack.Message{
protopack.Tag{999, protopack.BytesType}, protopack.LengthPrefix(protopack.Message{
protopack.Tag{1, protopack.VarintType}, protopack.Varint(10),
}),
}.Marshal()),
)},
),
wire: protopack.Message{
protopack.Tag{1, protopack.StartGroupType},
protopack.Tag{2, protopack.VarintType}, protopack.Varint(999),
@ -102,13 +113,15 @@ var messageSetTestProtos = []testProto{
},
{
desc: "MessageSet merges repeated message fields in item",
decodeTo: []proto.Message{build(
decodeTo: makeMessages(
protobuild.Message{
"message_set_ext1": protobuild.Message{
"ext1_field1": 10,
"ext1_field2": 20,
},
},
&messagesetpb.MessageSet{},
extend(msetextpb.E_Ext1_MessageSetExtension, &msetextpb.Ext1{
Ext1Field1: proto.Int32(10),
Ext1Field2: proto.Int32(20),
}),
)},
),
wire: protopack.Message{
protopack.Tag{1, protopack.StartGroupType},
protopack.Tag{2, protopack.VarintType}, protopack.Varint(1000),
@ -123,16 +136,18 @@ var messageSetTestProtos = []testProto{
},
{
desc: "MessageSet merges message fields in repeated items",
decodeTo: []proto.Message{build(
decodeTo: makeMessages(
protobuild.Message{
"message_set_ext1": protobuild.Message{
"ext1_field1": 10,
"ext1_field2": 20,
},
"message_set_ext2": protobuild.Message{
"ext2_field1": 30,
},
},
&messagesetpb.MessageSet{},
extend(msetextpb.E_Ext1_MessageSetExtension, &msetextpb.Ext1{
Ext1Field1: proto.Int32(10),
Ext1Field2: proto.Int32(20),
}),
extend(msetextpb.E_Ext2_MessageSetExtension, &msetextpb.Ext2{
Ext2Field1: proto.Int32(30),
}),
)},
),
wire: protopack.Message{
// Ext1, field1
protopack.Tag{1, protopack.StartGroupType},
@ -159,9 +174,10 @@ var messageSetTestProtos = []testProto{
},
{
desc: "MessageSet with missing type_id",
decodeTo: []proto.Message{build(
decodeTo: makeMessages(
protobuild.Message{},
&messagesetpb.MessageSet{},
)},
),
wire: protopack.Message{
protopack.Tag{1, protopack.StartGroupType},
protopack.Tag{3, protopack.BytesType}, protopack.LengthPrefix(protopack.Message{
@ -172,10 +188,12 @@ var messageSetTestProtos = []testProto{
},
{
desc: "MessageSet with missing message",
decodeTo: []proto.Message{build(
decodeTo: makeMessages(
protobuild.Message{
"message_set_ext1": protobuild.Message{},
},
&messagesetpb.MessageSet{},
extend(msetextpb.E_Ext1_MessageSetExtension, &msetextpb.Ext1{}),
)},
),
wire: protopack.Message{
protopack.Tag{1, protopack.StartGroupType},
protopack.Tag{2, protopack.VarintType}, protopack.Varint(1000),
@ -184,11 +202,14 @@ var messageSetTestProtos = []testProto{
},
{
desc: "MessageSet with type id out of valid field number range",
decodeTo: []proto.Message{func() proto.Message {
m := &messagesetpb.MessageSetContainer{MessageSet: &messagesetpb.MessageSet{}}
proto.SetExtension(m.MessageSet, msetextpb.E_ExtLargeNumber_MessageSetExtension, &msetextpb.ExtLargeNumber{})
return m
}()},
decodeTo: makeMessages(
protobuild.Message{
"message_set": protobuild.Message{
"message_set_extlarge": protobuild.Message{},
},
},
&messagesetpb.MessageSetContainer{},
),
wire: protopack.Message{
protopack.Tag{1, protopack.BytesType}, protopack.LengthPrefix(protopack.Message{
protopack.Tag{1, protopack.StartGroupType},
@ -200,15 +221,16 @@ var messageSetTestProtos = []testProto{
},
{
desc: "MessageSet with unknown type id out of valid field number range",
decodeTo: []proto.Message{func() proto.Message {
m := &messagesetpb.MessageSetContainer{MessageSet: &messagesetpb.MessageSet{}}
m.MessageSet.ProtoReflect().SetUnknown(
protopack.Message{
protopack.Tag{protowire.MaxValidNumber + 2, protopack.BytesType}, protopack.LengthPrefix{},
}.Marshal(),
)
return m
}()},
decodeTo: makeMessages(
protobuild.Message{
"message_set": protobuild.Message{
protobuild.Unknown: protopack.Message{
protopack.Tag{protowire.MaxValidNumber + 2, protopack.BytesType}, protopack.LengthPrefix{},
}.Marshal(),
},
},
&messagesetpb.MessageSetContainer{},
),
wire: protopack.Message{
protopack.Tag{1, protopack.BytesType}, protopack.LengthPrefix(protopack.Message{
protopack.Tag{1, protopack.StartGroupType},
@ -220,13 +242,16 @@ var messageSetTestProtos = []testProto{
},
{
desc: "MessageSet with unknown field",
decodeTo: []proto.Message{func() proto.Message {
m := &messagesetpb.MessageSetContainer{MessageSet: &messagesetpb.MessageSet{}}
proto.SetExtension(m.MessageSet, msetextpb.E_Ext1_MessageSetExtension, &msetextpb.Ext1{
Ext1Field1: proto.Int32(10),
})
return m
}()},
decodeTo: makeMessages(
protobuild.Message{
"message_set": protobuild.Message{
"message_set_ext1": protobuild.Message{
"ext1_field1": 10,
},
},
},
&messagesetpb.MessageSetContainer{},
),
wire: protopack.Message{
protopack.Tag{1, protopack.BytesType}, protopack.LengthPrefix(protopack.Message{
protopack.Tag{1, protopack.StartGroupType},
@ -242,13 +267,16 @@ var messageSetTestProtos = []testProto{
{
desc: "MessageSet with required field set",
checkFastInit: true,
decodeTo: []proto.Message{func() proto.Message {
m := &messagesetpb.MessageSetContainer{MessageSet: &messagesetpb.MessageSet{}}
proto.SetExtension(m.MessageSet, msetextpb.E_ExtRequired_MessageSetExtension, &msetextpb.ExtRequired{
RequiredField1: proto.Int32(1),
})
return m
}()},
decodeTo: makeMessages(
protobuild.Message{
"message_set": protobuild.Message{
"message_set_extrequired": protobuild.Message{
"required_field1": 1,
},
},
},
&messagesetpb.MessageSetContainer{},
),
wire: protopack.Message{
protopack.Tag{1, protopack.BytesType}, protopack.LengthPrefix(protopack.Message{
protopack.Tag{1, protopack.StartGroupType},
@ -264,11 +292,14 @@ var messageSetTestProtos = []testProto{
desc: "MessageSet with required field unset",
checkFastInit: true,
partial: true,
decodeTo: []proto.Message{func() proto.Message {
m := &messagesetpb.MessageSetContainer{MessageSet: &messagesetpb.MessageSet{}}
proto.SetExtension(m.MessageSet, msetextpb.E_ExtRequired_MessageSetExtension, &msetextpb.ExtRequired{})
return m
}()},
decodeTo: makeMessages(
protobuild.Message{
"message_set": protobuild.Message{
"message_set_extrequired": protobuild.Message{},
},
},
&messagesetpb.MessageSetContainer{},
),
wire: protopack.Message{
protopack.Tag{1, protopack.BytesType}, protopack.LengthPrefix(protopack.Message{
protopack.Tag{1, protopack.StartGroupType},