reflect/protoregistry: provide more informative errors for conflicts

The v2 implementation strictly enforces that there are no conflicts at
all in the protobuf namespace unlike the prior v1 implementation.
This change is almost certainly going to cause loud failures for users
that were unknowingly tolerating registration conflicts.

We modify internal/filedesc to be able to record the Go package path
that the file descriptor is declared within. This information is used
by reflect/protoregistry to print both the previous Go package that
registered some declaration, and current Go package that is attempting
to register some declaration.

Change-Id: Ib5eb21c1c98495afc51aa08bd4404bd9d64b5b57
Reviewed-on: https://go-review.googlesource.com/c/protobuf/+/186177
Reviewed-by: Damien Neil <dneil@google.com>
This commit is contained in:
Joe Tsai 2019-07-14 23:04:40 -07:00
parent c51e2e0293
commit af57087245
88 changed files with 304 additions and 16 deletions

View File

@ -6,6 +6,7 @@ package grpc
import (
protoreflect "google.golang.org/protobuf/reflect/protoreflect"
protoimpl "google.golang.org/protobuf/runtime/protoimpl"
reflect "reflect"
sync "sync"
)
@ -69,8 +70,10 @@ func file_grpc_deprecation_proto_init() {
return
}
file_grpc_grpc_proto_init()
type x struct{}
out := protoimpl.TypeBuilder{
File: protoimpl.DescBuilder{
GoPackagePath: reflect.TypeOf(x{}).PkgPath(),
RawDescriptor: file_grpc_deprecation_proto_rawDesc,
NumEnums: 0,
NumMessages: 0,

View File

@ -6,6 +6,7 @@ package grpc
import (
protoreflect "google.golang.org/protobuf/reflect/protoreflect"
protoimpl "google.golang.org/protobuf/runtime/protoimpl"
reflect "reflect"
sync "sync"
)
@ -180,8 +181,10 @@ func file_grpc_grpc_proto_init() {
}
}
}
type x struct{}
out := protoimpl.TypeBuilder{
File: protoimpl.DescBuilder{
GoPackagePath: reflect.TypeOf(x{}).PkgPath(),
RawDescriptor: file_grpc_grpc_proto_rawDesc,
NumEnums: 0,
NumMessages: 2,

View File

@ -74,8 +74,9 @@ const (
)
const (
syncPackage = protogen.GoImportPath("sync")
mathPackage = protogen.GoImportPath("math")
reflectPackage = protogen.GoImportPath("reflect")
syncPackage = protogen.GoImportPath("sync")
protoifacePackage = protogen.GoImportPath("google.golang.org/protobuf/runtime/protoiface")
protoimplPackage = protogen.GoImportPath("google.golang.org/protobuf/runtime/protoimpl")
protoreflectPackage = protogen.GoImportPath("google.golang.org/protobuf/reflect/protoreflect")

View File

@ -193,8 +193,10 @@ func genReflectFileDescriptor(gen *protogen.Plugin, g *protogen.GeneratedFile, f
}
}
g.P("type x struct{}")
g.P("out := ", protoimplPackage.Ident("TypeBuilder"), "{")
g.P("File: ", protoimplPackage.Ident("DescBuilder"), "{")
g.P("GoPackagePath: ", reflectPackage.Ident("TypeOf"), "(x{}).PkgPath(),")
g.P("RawDescriptor: ", rawDescVarName(f), ",")
g.P("NumEnums: ", len(f.allEnums), ",")
g.P("NumMessages: ", len(f.allMessages), ",")

View File

@ -7,6 +7,7 @@ import (
protoreflect "google.golang.org/protobuf/reflect/protoreflect"
prototype "google.golang.org/protobuf/reflect/prototype"
protoimpl "google.golang.org/protobuf/runtime/protoimpl"
reflect "reflect"
sync "sync"
)
@ -176,8 +177,10 @@ func file_annotations_annotations_proto_init() {
}
}
}
type x struct{}
out := protoimpl.TypeBuilder{
File: protoimpl.DescBuilder{
GoPackagePath: reflect.TypeOf(x{}).PkgPath(),
RawDescriptor: file_annotations_annotations_proto_rawDesc,
NumEnums: 1,
NumMessages: 1,

View File

@ -1 +1 @@
annotation:{path:5 path:0 source_file:"annotations/annotations.proto" begin:571 end:590} annotation:{path:5 path:0 path:2 path:0 source_file:"annotations/annotations.proto" begin:607 end:654} annotation:{path:4 path:0 source_file:"annotations/annotations.proto" begin:1879 end:1901} annotation:{path:4 path:0 path:2 path:0 source_file:"annotations/annotations.proto" begin:1957 end:1977} annotation:{path:4 path:0 path:2 path:0 source_file:"annotations/annotations.proto" begin:2953 end:2976}
annotation:{path:5 path:0 source_file:"annotations/annotations.proto" begin:590 end:609} annotation:{path:5 path:0 path:2 path:0 source_file:"annotations/annotations.proto" begin:626 end:673} annotation:{path:4 path:0 source_file:"annotations/annotations.proto" begin:1898 end:1920} annotation:{path:4 path:0 path:2 path:0 source_file:"annotations/annotations.proto" begin:1976 end:1996} annotation:{path:4 path:0 path:2 path:0 source_file:"annotations/annotations.proto" begin:2972 end:2995}

View File

@ -8,6 +8,7 @@ package comments
import (
protoreflect "google.golang.org/protobuf/reflect/protoreflect"
protoimpl "google.golang.org/protobuf/runtime/protoimpl"
reflect "reflect"
sync "sync"
)
@ -394,8 +395,10 @@ func file_comments_comments_proto_init() {
file_comments_comments_proto_msgTypes[0].OneofWrappers = []interface{}{
(*Message1_Oneof1AField1)(nil),
}
type x struct{}
out := protoimpl.TypeBuilder{
File: protoimpl.DescBuilder{
GoPackagePath: reflect.TypeOf(x{}).PkgPath(),
RawDescriptor: file_comments_comments_proto_rawDesc,
NumEnums: 0,
NumMessages: 6,

View File

@ -7,6 +7,7 @@ import (
protoreflect "google.golang.org/protobuf/reflect/protoreflect"
prototype "google.golang.org/protobuf/reflect/prototype"
protoimpl "google.golang.org/protobuf/runtime/protoimpl"
reflect "reflect"
sync "sync"
)
@ -166,8 +167,10 @@ func file_comments_deprecated_proto_init() {
}
}
}
type x struct{}
out := protoimpl.TypeBuilder{
File: protoimpl.DescBuilder{
GoPackagePath: reflect.TypeOf(x{}).PkgPath(),
RawDescriptor: file_comments_deprecated_proto_rawDesc,
NumEnums: 1,
NumMessages: 1,

View File

@ -7,6 +7,7 @@ import (
protoreflect "google.golang.org/protobuf/reflect/protoreflect"
protoiface "google.golang.org/protobuf/runtime/protoiface"
protoimpl "google.golang.org/protobuf/runtime/protoimpl"
reflect "reflect"
sync "sync"
)
@ -192,8 +193,10 @@ func file_extensions_base_base_proto_init() {
}
}
}
type x struct{}
out := protoimpl.TypeBuilder{
File: protoimpl.DescBuilder{
GoPackagePath: reflect.TypeOf(x{}).PkgPath(),
RawDescriptor: file_extensions_base_base_proto_rawDesc,
NumEnums: 0,
NumMessages: 2,

View File

@ -10,6 +10,7 @@ import (
prototype "google.golang.org/protobuf/reflect/prototype"
protoiface "google.golang.org/protobuf/runtime/protoiface"
protoimpl "google.golang.org/protobuf/runtime/protoimpl"
reflect "reflect"
sync "sync"
)
@ -1374,8 +1375,10 @@ func file_extensions_ext_ext_proto_init() {
}
}
}
type x struct{}
out := protoimpl.TypeBuilder{
File: protoimpl.DescBuilder{
GoPackagePath: reflect.TypeOf(x{}).PkgPath(),
RawDescriptor: file_extensions_ext_ext_proto_rawDesc,
NumEnums: 1,
NumMessages: 8,

View File

@ -6,6 +6,7 @@ package extra
import (
protoreflect "google.golang.org/protobuf/reflect/protoreflect"
protoimpl "google.golang.org/protobuf/runtime/protoimpl"
reflect "reflect"
sync "sync"
)
@ -116,8 +117,10 @@ func file_extensions_extra_extra_proto_init() {
}
}
}
type x struct{}
out := protoimpl.TypeBuilder{
File: protoimpl.DescBuilder{
GoPackagePath: reflect.TypeOf(x{}).PkgPath(),
RawDescriptor: file_extensions_extra_extra_proto_rawDesc,
NumEnums: 0,
NumMessages: 1,

View File

@ -9,6 +9,7 @@ import (
protoiface "google.golang.org/protobuf/runtime/protoiface"
protoimpl "google.golang.org/protobuf/runtime/protoimpl"
descriptorpb "google.golang.org/protobuf/types/descriptorpb"
reflect "reflect"
sync "sync"
)
@ -764,8 +765,10 @@ func file_extensions_proto3_ext3_proto_init() {
}
}
}
type x struct{}
out := protoimpl.TypeBuilder{
File: protoimpl.DescBuilder{
GoPackagePath: reflect.TypeOf(x{}).PkgPath(),
RawDescriptor: file_extensions_proto3_ext3_proto_rawDesc,
NumEnums: 1,
NumMessages: 1,

View File

@ -6,6 +6,7 @@ package fieldnames
import (
protoreflect "google.golang.org/protobuf/reflect/protoreflect"
protoimpl "google.golang.org/protobuf/runtime/protoimpl"
reflect "reflect"
sync "sync"
)
@ -423,8 +424,10 @@ func file_fieldnames_fieldnames_proto_init() {
(*Message_OneofConflictB_)(nil),
(*Message_OneofMessageConflict_)(nil),
}
type x struct{}
out := protoimpl.TypeBuilder{
File: protoimpl.DescBuilder{
GoPackagePath: reflect.TypeOf(x{}).PkgPath(),
RawDescriptor: file_fieldnames_fieldnames_proto_rawDesc,
NumEnums: 0,
NumMessages: 2,

View File

@ -7,6 +7,7 @@ import (
sub "google.golang.org/protobuf/cmd/protoc-gen-go/testdata/import_public/sub"
protoreflect "google.golang.org/protobuf/reflect/protoreflect"
protoimpl "google.golang.org/protobuf/runtime/protoimpl"
reflect "reflect"
sync "sync"
)
@ -189,8 +190,10 @@ func file_import_public_a_proto_init() {
}
}
}
type x struct{}
out := protoimpl.TypeBuilder{
File: protoimpl.DescBuilder{
GoPackagePath: reflect.TypeOf(x{}).PkgPath(),
RawDescriptor: file_import_public_a_proto_rawDesc,
NumEnums: 0,
NumMessages: 1,

View File

@ -7,6 +7,7 @@ import (
sub "google.golang.org/protobuf/cmd/protoc-gen-go/testdata/import_public/sub"
protoreflect "google.golang.org/protobuf/reflect/protoreflect"
protoimpl "google.golang.org/protobuf/runtime/protoimpl"
reflect "reflect"
sync "sync"
)
@ -135,8 +136,10 @@ func file_import_public_b_proto_init() {
}
}
}
type x struct{}
out := protoimpl.TypeBuilder{
File: protoimpl.DescBuilder{
GoPackagePath: reflect.TypeOf(x{}).PkgPath(),
RawDescriptor: file_import_public_b_proto_rawDesc,
NumEnums: 0,
NumMessages: 1,

View File

@ -7,6 +7,7 @@ import (
sub2 "google.golang.org/protobuf/cmd/protoc-gen-go/testdata/import_public/sub2"
protoreflect "google.golang.org/protobuf/reflect/protoreflect"
protoimpl "google.golang.org/protobuf/runtime/protoimpl"
reflect "reflect"
sync "sync"
)
@ -141,8 +142,10 @@ func file_import_public_c_proto_init() {
}
}
}
type x struct{}
out := protoimpl.TypeBuilder{
File: protoimpl.DescBuilder{
GoPackagePath: reflect.TypeOf(x{}).PkgPath(),
RawDescriptor: file_import_public_c_proto_rawDesc,
NumEnums: 0,
NumMessages: 1,

View File

@ -10,6 +10,7 @@ import (
protoiface "google.golang.org/protobuf/runtime/protoiface"
protoimpl "google.golang.org/protobuf/runtime/protoimpl"
math "math"
reflect "reflect"
sync "sync"
)
@ -512,8 +513,10 @@ func file_import_public_sub_a_proto_init() {
(*M_Submessage_SubmessageOneofInt32)(nil),
(*M_Submessage_SubmessageOneofInt64)(nil),
}
type x struct{}
out := protoimpl.TypeBuilder{
File: protoimpl.DescBuilder{
GoPackagePath: reflect.TypeOf(x{}).PkgPath(),
RawDescriptor: file_import_public_sub_a_proto_rawDesc,
NumEnums: 3,
NumMessages: 2,

View File

@ -6,6 +6,7 @@ package sub
import (
protoreflect "google.golang.org/protobuf/reflect/protoreflect"
protoimpl "google.golang.org/protobuf/runtime/protoimpl"
reflect "reflect"
sync "sync"
)
@ -106,8 +107,10 @@ func file_import_public_sub_b_proto_init() {
}
}
}
type x struct{}
out := protoimpl.TypeBuilder{
File: protoimpl.DescBuilder{
GoPackagePath: reflect.TypeOf(x{}).PkgPath(),
RawDescriptor: file_import_public_sub_b_proto_rawDesc,
NumEnums: 0,
NumMessages: 1,

View File

@ -6,6 +6,7 @@ package sub2
import (
protoreflect "google.golang.org/protobuf/reflect/protoreflect"
protoimpl "google.golang.org/protobuf/runtime/protoimpl"
reflect "reflect"
sync "sync"
)
@ -107,8 +108,10 @@ func file_import_public_sub2_a_proto_init() {
}
}
}
type x struct{}
out := protoimpl.TypeBuilder{
File: protoimpl.DescBuilder{
GoPackagePath: reflect.TypeOf(x{}).PkgPath(),
RawDescriptor: file_import_public_sub2_a_proto_rawDesc,
NumEnums: 0,
NumMessages: 1,

View File

@ -6,6 +6,7 @@ package fmt
import (
protoreflect "google.golang.org/protobuf/reflect/protoreflect"
protoimpl "google.golang.org/protobuf/runtime/protoimpl"
reflect "reflect"
sync "sync"
)
@ -104,8 +105,10 @@ func file_imports_fmt_m_proto_init() {
}
}
}
type x struct{}
out := protoimpl.TypeBuilder{
File: protoimpl.DescBuilder{
GoPackagePath: reflect.TypeOf(x{}).PkgPath(),
RawDescriptor: file_imports_fmt_m_proto_rawDesc,
NumEnums: 0,
NumMessages: 1,

View File

@ -7,6 +7,7 @@ import (
protoreflect "google.golang.org/protobuf/reflect/protoreflect"
prototype "google.golang.org/protobuf/reflect/prototype"
protoimpl "google.golang.org/protobuf/runtime/protoimpl"
reflect "reflect"
sync "sync"
)
@ -208,8 +209,10 @@ func file_imports_test_a_1_m1_proto_init() {
}
}
}
type x struct{}
out := protoimpl.TypeBuilder{
File: protoimpl.DescBuilder{
GoPackagePath: reflect.TypeOf(x{}).PkgPath(),
RawDescriptor: file_imports_test_a_1_m1_proto_rawDesc,
NumEnums: 1,
NumMessages: 2,

View File

@ -6,6 +6,7 @@ package test_a_1
import (
protoreflect "google.golang.org/protobuf/reflect/protoreflect"
protoimpl "google.golang.org/protobuf/runtime/protoimpl"
reflect "reflect"
sync "sync"
)
@ -105,8 +106,10 @@ func file_imports_test_a_1_m2_proto_init() {
}
}
}
type x struct{}
out := protoimpl.TypeBuilder{
File: protoimpl.DescBuilder{
GoPackagePath: reflect.TypeOf(x{}).PkgPath(),
RawDescriptor: file_imports_test_a_1_m2_proto_rawDesc,
NumEnums: 0,
NumMessages: 1,

View File

@ -6,6 +6,7 @@ package test_a_2
import (
protoreflect "google.golang.org/protobuf/reflect/protoreflect"
protoimpl "google.golang.org/protobuf/runtime/protoimpl"
reflect "reflect"
sync "sync"
)
@ -105,8 +106,10 @@ func file_imports_test_a_2_m3_proto_init() {
}
}
}
type x struct{}
out := protoimpl.TypeBuilder{
File: protoimpl.DescBuilder{
GoPackagePath: reflect.TypeOf(x{}).PkgPath(),
RawDescriptor: file_imports_test_a_2_m3_proto_rawDesc,
NumEnums: 0,
NumMessages: 1,

View File

@ -6,6 +6,7 @@ package test_a_2
import (
protoreflect "google.golang.org/protobuf/reflect/protoreflect"
protoimpl "google.golang.org/protobuf/runtime/protoimpl"
reflect "reflect"
sync "sync"
)
@ -105,8 +106,10 @@ func file_imports_test_a_2_m4_proto_init() {
}
}
}
type x struct{}
out := protoimpl.TypeBuilder{
File: protoimpl.DescBuilder{
GoPackagePath: reflect.TypeOf(x{}).PkgPath(),
RawDescriptor: file_imports_test_a_2_m4_proto_rawDesc,
NumEnums: 0,
NumMessages: 1,

View File

@ -6,6 +6,7 @@ package beta
import (
protoreflect "google.golang.org/protobuf/reflect/protoreflect"
protoimpl "google.golang.org/protobuf/runtime/protoimpl"
reflect "reflect"
sync "sync"
)
@ -106,8 +107,10 @@ func file_imports_test_b_1_m1_proto_init() {
}
}
}
type x struct{}
out := protoimpl.TypeBuilder{
File: protoimpl.DescBuilder{
GoPackagePath: reflect.TypeOf(x{}).PkgPath(),
RawDescriptor: file_imports_test_b_1_m1_proto_rawDesc,
NumEnums: 0,
NumMessages: 1,

View File

@ -6,6 +6,7 @@ package beta
import (
protoreflect "google.golang.org/protobuf/reflect/protoreflect"
protoimpl "google.golang.org/protobuf/runtime/protoimpl"
reflect "reflect"
sync "sync"
)
@ -106,8 +107,10 @@ func file_imports_test_b_1_m2_proto_init() {
}
}
}
type x struct{}
out := protoimpl.TypeBuilder{
File: protoimpl.DescBuilder{
GoPackagePath: reflect.TypeOf(x{}).PkgPath(),
RawDescriptor: file_imports_test_b_1_m2_proto_rawDesc,
NumEnums: 0,
NumMessages: 1,

View File

@ -7,6 +7,7 @@ import (
test_a_1 "google.golang.org/protobuf/cmd/protoc-gen-go/testdata/imports/test_a_1"
protoreflect "google.golang.org/protobuf/reflect/protoreflect"
protoimpl "google.golang.org/protobuf/runtime/protoimpl"
reflect "reflect"
sync "sync"
)
@ -119,8 +120,10 @@ func file_imports_test_import_a1m1_proto_init() {
}
}
}
type x struct{}
out := protoimpl.TypeBuilder{
File: protoimpl.DescBuilder{
GoPackagePath: reflect.TypeOf(x{}).PkgPath(),
RawDescriptor: file_imports_test_import_a1m1_proto_rawDesc,
NumEnums: 0,
NumMessages: 1,

View File

@ -7,6 +7,7 @@ import (
test_a_1 "google.golang.org/protobuf/cmd/protoc-gen-go/testdata/imports/test_a_1"
protoreflect "google.golang.org/protobuf/reflect/protoreflect"
protoimpl "google.golang.org/protobuf/runtime/protoimpl"
reflect "reflect"
sync "sync"
)
@ -119,8 +120,10 @@ func file_imports_test_import_a1m2_proto_init() {
}
}
}
type x struct{}
out := protoimpl.TypeBuilder{
File: protoimpl.DescBuilder{
GoPackagePath: reflect.TypeOf(x{}).PkgPath(),
RawDescriptor: file_imports_test_import_a1m2_proto_rawDesc,
NumEnums: 0,
NumMessages: 1,

View File

@ -10,6 +10,7 @@ import (
test_b_1 "google.golang.org/protobuf/cmd/protoc-gen-go/testdata/imports/test_b_1"
protoreflect "google.golang.org/protobuf/reflect/protoreflect"
protoimpl "google.golang.org/protobuf/runtime/protoimpl"
reflect "reflect"
sync "sync"
)
@ -180,8 +181,10 @@ func file_imports_test_import_all_proto_init() {
}
}
}
type x struct{}
out := protoimpl.TypeBuilder{
File: protoimpl.DescBuilder{
GoPackagePath: reflect.TypeOf(x{}).PkgPath(),
RawDescriptor: file_imports_test_import_all_proto_rawDesc,
NumEnums: 0,
NumMessages: 1,

View File

@ -6,6 +6,7 @@ package oneoftest
import (
protoreflect "google.golang.org/protobuf/reflect/protoreflect"
protoimpl "google.golang.org/protobuf/runtime/protoimpl"
reflect "reflect"
sync "sync"
)
@ -133,8 +134,10 @@ func file_issue780_oneof_conflict_test_proto_init() {
file_issue780_oneof_conflict_test_proto_msgTypes[0].OneofWrappers = []interface{}{
(*Foo_GetBar)(nil),
}
type x struct{}
out := protoimpl.TypeBuilder{
File: protoimpl.DescBuilder{
GoPackagePath: reflect.TypeOf(x{}).PkgPath(),
RawDescriptor: file_issue780_oneof_conflict_test_proto_rawDesc,
NumEnums: 0,
NumMessages: 1,

View File

@ -7,6 +7,7 @@ import (
protoreflect "google.golang.org/protobuf/reflect/protoreflect"
prototype "google.golang.org/protobuf/reflect/prototype"
protoimpl "google.golang.org/protobuf/runtime/protoimpl"
reflect "reflect"
sync "sync"
)
@ -179,8 +180,10 @@ func file_nopackage_nopackage_proto_init() {
}
}
}
type x struct{}
out := protoimpl.TypeBuilder{
File: protoimpl.DescBuilder{
GoPackagePath: reflect.TypeOf(x{}).PkgPath(),
RawDescriptor: file_nopackage_nopackage_proto_rawDesc,
NumEnums: 1,
NumMessages: 1,

View File

@ -7,6 +7,7 @@ import (
protoreflect "google.golang.org/protobuf/reflect/protoreflect"
prototype "google.golang.org/protobuf/reflect/prototype"
protoimpl "google.golang.org/protobuf/runtime/protoimpl"
reflect "reflect"
sync "sync"
)
@ -530,8 +531,10 @@ func file_proto2_enum_proto_init() {
}
}
}
type x struct{}
out := protoimpl.TypeBuilder{
File: protoimpl.DescBuilder{
GoPackagePath: reflect.TypeOf(x{}).PkgPath(),
RawDescriptor: file_proto2_enum_proto_rawDesc,
NumEnums: 6,
NumMessages: 2,

View File

@ -8,6 +8,7 @@ import (
prototype "google.golang.org/protobuf/reflect/prototype"
protoimpl "google.golang.org/protobuf/runtime/protoimpl"
math "math"
reflect "reflect"
sync "sync"
)
@ -1827,8 +1828,10 @@ func file_proto2_fields_proto_init() {
(*FieldTestMessage_OneofTwo_1)(nil),
(*FieldTestMessage_OneofTwo_2)(nil),
}
type x struct{}
out := protoimpl.TypeBuilder{
File: protoimpl.DescBuilder{
GoPackagePath: reflect.TypeOf(x{}).PkgPath(),
RawDescriptor: file_proto2_fields_proto_rawDesc,
NumEnums: 1,
NumMessages: 9,

View File

@ -6,6 +6,7 @@ package proto2
import (
protoreflect "google.golang.org/protobuf/reflect/protoreflect"
protoimpl "google.golang.org/protobuf/runtime/protoimpl"
reflect "reflect"
sync "sync"
)
@ -237,8 +238,10 @@ func file_proto2_nested_messages_proto_init() {
}
}
}
type x struct{}
out := protoimpl.TypeBuilder{
File: protoimpl.DescBuilder{
GoPackagePath: reflect.TypeOf(x{}).PkgPath(),
RawDescriptor: file_proto2_nested_messages_proto_rawDesc,
NumEnums: 0,
NumMessages: 3,

View File

@ -6,6 +6,7 @@ package proto2
import (
protoreflect "google.golang.org/protobuf/reflect/protoreflect"
protoimpl "google.golang.org/protobuf/runtime/protoimpl"
reflect "reflect"
sync "sync"
)
@ -126,8 +127,10 @@ func file_proto2_proto2_proto_init() {
}
}
}
type x struct{}
out := protoimpl.TypeBuilder{
File: protoimpl.DescBuilder{
GoPackagePath: reflect.TypeOf(x{}).PkgPath(),
RawDescriptor: file_proto2_proto2_proto_rawDesc,
NumEnums: 0,
NumMessages: 1,

View File

@ -7,6 +7,7 @@ import (
protoreflect "google.golang.org/protobuf/reflect/protoreflect"
prototype "google.golang.org/protobuf/reflect/prototype"
protoimpl "google.golang.org/protobuf/runtime/protoimpl"
reflect "reflect"
sync "sync"
)
@ -108,8 +109,10 @@ func file_proto3_enum_proto_init() {
if File_proto3_enum_proto != nil {
return
}
type x struct{}
out := protoimpl.TypeBuilder{
File: protoimpl.DescBuilder{
GoPackagePath: reflect.TypeOf(x{}).PkgPath(),
RawDescriptor: file_proto3_enum_proto_rawDesc,
NumEnums: 1,
NumMessages: 0,

View File

@ -7,6 +7,7 @@ import (
protoreflect "google.golang.org/protobuf/reflect/protoreflect"
prototype "google.golang.org/protobuf/reflect/prototype"
protoimpl "google.golang.org/protobuf/runtime/protoimpl"
reflect "reflect"
sync "sync"
)
@ -644,8 +645,10 @@ func file_proto3_fields_proto_init() {
}
}
}
type x struct{}
out := protoimpl.TypeBuilder{
File: protoimpl.DescBuilder{
GoPackagePath: reflect.TypeOf(x{}).PkgPath(),
RawDescriptor: file_proto3_fields_proto_rawDesc,
NumEnums: 1,
NumMessages: 5,

View File

@ -15,6 +15,7 @@ import (
structpb "google.golang.org/protobuf/types/known/structpb"
timestamppb "google.golang.org/protobuf/types/known/timestamppb"
wrapperspb "google.golang.org/protobuf/types/known/wrapperspb"
reflect "reflect"
sync "sync"
)
@ -2382,8 +2383,10 @@ func file_pb2_test_proto_init() {
file_pb2_test_proto_msgTypes[8].OneofWrappers = []interface{}{
(*IndirectRequired_OneofNested)(nil),
}
type x struct{}
out := protoimpl.TypeBuilder{
File: protoimpl.DescBuilder{
GoPackagePath: reflect.TypeOf(x{}).PkgPath(),
RawDescriptor: file_pb2_test_proto_rawDesc,
NumEnums: 2,
NumMessages: 20,

View File

@ -7,6 +7,7 @@ import (
protoreflect "google.golang.org/protobuf/reflect/protoreflect"
prototype "google.golang.org/protobuf/reflect/prototype"
protoimpl "google.golang.org/protobuf/runtime/protoimpl"
reflect "reflect"
sync "sync"
)
@ -878,8 +879,10 @@ func file_pb3_test_proto_init() {
(*Oneofs_OneofString)(nil),
(*Oneofs_OneofNested)(nil),
}
type x struct{}
out := protoimpl.TypeBuilder{
File: protoimpl.DescBuilder{
GoPackagePath: reflect.TypeOf(x{}).PkgPath(),
RawDescriptor: file_pb3_test_proto_rawDesc,
NumEnums: 2,
NumMessages: 12,

View File

@ -15,6 +15,9 @@ import (
// DescBuilder construct a protoreflect.FileDescriptor from the raw descriptor.
type DescBuilder struct {
// GoPackagePath is the Go package path that is invoking this builder.
GoPackagePath string
// RawDescriptor is the wire-encoded bytes of FileDescriptorProto
// and must be populated.
RawDescriptor []byte

View File

@ -106,6 +106,15 @@ func (fd *File) ProtoLegacyRawDesc() []byte {
return fd.builder.RawDescriptor
}
// GoPackagePath is a pseudo-internal API for determining the Go package path
// that this file descriptor is declared in.
//
// WARNING: This method is exempt from the compatibility promise and may be
// removed in the future without warning.
func (fd *File) GoPackagePath() string {
return fd.builder.GoPackagePath
}
type (
Enum struct {
Base

View File

@ -6,6 +6,7 @@ package benchmarks
import (
protoreflect "google.golang.org/protobuf/reflect/protoreflect"
protoimpl "google.golang.org/protobuf/runtime/protoimpl"
reflect "reflect"
sync "sync"
)
@ -158,8 +159,10 @@ func file_benchmarks_proto_init() {
}
}
}
type x struct{}
out := protoimpl.TypeBuilder{
File: protoimpl.DescBuilder{
GoPackagePath: reflect.TypeOf(x{}).PkgPath(),
RawDescriptor: file_benchmarks_proto_rawDesc,
NumEnums: 0,
NumMessages: 1,

View File

@ -6,6 +6,7 @@ package proto2
import (
protoreflect "google.golang.org/protobuf/reflect/protoreflect"
protoimpl "google.golang.org/protobuf/runtime/protoimpl"
reflect "reflect"
sync "sync"
)
@ -798,8 +799,10 @@ func file_datasets_google_message1_proto2_benchmark_message1_proto2_proto_init()
}
}
}
type x struct{}
out := protoimpl.TypeBuilder{
File: protoimpl.DescBuilder{
GoPackagePath: reflect.TypeOf(x{}).PkgPath(),
RawDescriptor: file_datasets_google_message1_proto2_benchmark_message1_proto2_proto_rawDesc,
NumEnums: 0,
NumMessages: 2,

View File

@ -6,6 +6,7 @@ package proto3
import (
protoreflect "google.golang.org/protobuf/reflect/protoreflect"
protoimpl "google.golang.org/protobuf/runtime/protoimpl"
reflect "reflect"
sync "sync"
)
@ -753,8 +754,10 @@ func file_datasets_google_message1_proto3_benchmark_message1_proto3_proto_init()
}
}
}
type x struct{}
out := protoimpl.TypeBuilder{
File: protoimpl.DescBuilder{
GoPackagePath: reflect.TypeOf(x{}).PkgPath(),
RawDescriptor: file_datasets_google_message1_proto3_benchmark_message1_proto3_proto_rawDesc,
NumEnums: 0,
NumMessages: 2,

View File

@ -6,6 +6,7 @@ package google_message2
import (
protoreflect "google.golang.org/protobuf/reflect/protoreflect"
protoimpl "google.golang.org/protobuf/runtime/protoimpl"
reflect "reflect"
sync "sync"
)
@ -790,8 +791,10 @@ func file_datasets_google_message2_benchmark_message2_proto_init() {
}
}
}
type x struct{}
out := protoimpl.TypeBuilder{
File: protoimpl.DescBuilder{
GoPackagePath: reflect.TypeOf(x{}).PkgPath(),
RawDescriptor: file_datasets_google_message2_benchmark_message2_proto_rawDesc,
NumEnums: 0,
NumMessages: 3,

View File

@ -7,6 +7,7 @@ import (
protoreflect "google.golang.org/protobuf/reflect/protoreflect"
protoiface "google.golang.org/protobuf/runtime/protoiface"
protoimpl "google.golang.org/protobuf/runtime/protoimpl"
reflect "reflect"
sync "sync"
)
@ -6569,8 +6570,10 @@ func file_datasets_google_message3_benchmark_message3_proto_init() {
}
}
}
type x struct{}
out := protoimpl.TypeBuilder{
File: protoimpl.DescBuilder{
GoPackagePath: reflect.TypeOf(x{}).PkgPath(),
RawDescriptor: file_datasets_google_message3_benchmark_message3_proto_rawDesc,
NumEnums: 0,
NumMessages: 33,

View File

@ -7,6 +7,7 @@ import (
protoreflect "google.golang.org/protobuf/reflect/protoreflect"
protoiface "google.golang.org/protobuf/runtime/protoiface"
protoimpl "google.golang.org/protobuf/runtime/protoimpl"
reflect "reflect"
sync "sync"
)
@ -8822,8 +8823,10 @@ func file_datasets_google_message3_benchmark_message3_1_proto_init() {
}
}
}
type x struct{}
out := protoimpl.TypeBuilder{
File: protoimpl.DescBuilder{
GoPackagePath: reflect.TypeOf(x{}).PkgPath(),
RawDescriptor: file_datasets_google_message3_benchmark_message3_1_proto_rawDesc,
NumEnums: 0,
NumMessages: 59,

View File

@ -7,6 +7,7 @@ import (
protoreflect "google.golang.org/protobuf/reflect/protoreflect"
protoiface "google.golang.org/protobuf/runtime/protoiface"
protoimpl "google.golang.org/protobuf/runtime/protoimpl"
reflect "reflect"
sync "sync"
)
@ -6107,8 +6108,10 @@ func file_datasets_google_message3_benchmark_message3_2_proto_init() {
}
}
}
type x struct{}
out := protoimpl.TypeBuilder{
File: protoimpl.DescBuilder{
GoPackagePath: reflect.TypeOf(x{}).PkgPath(),
RawDescriptor: file_datasets_google_message3_benchmark_message3_2_proto_rawDesc,
NumEnums: 0,
NumMessages: 34,

View File

@ -6,6 +6,7 @@ package google_message3
import (
protoreflect "google.golang.org/protobuf/reflect/protoreflect"
protoimpl "google.golang.org/protobuf/runtime/protoimpl"
reflect "reflect"
sync "sync"
)
@ -5789,8 +5790,10 @@ func file_datasets_google_message3_benchmark_message3_3_proto_init() {
}
}
}
type x struct{}
out := protoimpl.TypeBuilder{
File: protoimpl.DescBuilder{
GoPackagePath: reflect.TypeOf(x{}).PkgPath(),
RawDescriptor: file_datasets_google_message3_benchmark_message3_3_proto_rawDesc,
NumEnums: 0,
NumMessages: 37,

View File

@ -7,6 +7,7 @@ import (
protoreflect "google.golang.org/protobuf/reflect/protoreflect"
protoiface "google.golang.org/protobuf/runtime/protoiface"
protoimpl "google.golang.org/protobuf/runtime/protoimpl"
reflect "reflect"
sync "sync"
)
@ -6349,8 +6350,10 @@ func file_datasets_google_message3_benchmark_message3_4_proto_init() {
}
}
}
type x struct{}
out := protoimpl.TypeBuilder{
File: protoimpl.DescBuilder{
GoPackagePath: reflect.TypeOf(x{}).PkgPath(),
RawDescriptor: file_datasets_google_message3_benchmark_message3_4_proto_rawDesc,
NumEnums: 0,
NumMessages: 54,

View File

@ -7,6 +7,7 @@ import (
protoreflect "google.golang.org/protobuf/reflect/protoreflect"
protoiface "google.golang.org/protobuf/runtime/protoiface"
protoimpl "google.golang.org/protobuf/runtime/protoimpl"
reflect "reflect"
sync "sync"
)
@ -5809,8 +5810,10 @@ func file_datasets_google_message3_benchmark_message3_5_proto_init() {
}
}
}
type x struct{}
out := protoimpl.TypeBuilder{
File: protoimpl.DescBuilder{
GoPackagePath: reflect.TypeOf(x{}).PkgPath(),
RawDescriptor: file_datasets_google_message3_benchmark_message3_5_proto_rawDesc,
NumEnums: 0,
NumMessages: 49,

View File

@ -7,6 +7,7 @@ import (
protoreflect "google.golang.org/protobuf/reflect/protoreflect"
protoiface "google.golang.org/protobuf/runtime/protoiface"
protoimpl "google.golang.org/protobuf/runtime/protoimpl"
reflect "reflect"
sync "sync"
)
@ -5425,8 +5426,10 @@ func file_datasets_google_message3_benchmark_message3_6_proto_init() {
}
}
}
type x struct{}
out := protoimpl.TypeBuilder{
File: protoimpl.DescBuilder{
GoPackagePath: reflect.TypeOf(x{}).PkgPath(),
RawDescriptor: file_datasets_google_message3_benchmark_message3_6_proto_rawDesc,
NumEnums: 0,
NumMessages: 42,

View File

@ -6,6 +6,7 @@ package google_message3
import (
protoreflect "google.golang.org/protobuf/reflect/protoreflect"
protoimpl "google.golang.org/protobuf/runtime/protoimpl"
reflect "reflect"
sync "sync"
)
@ -726,8 +727,10 @@ func file_datasets_google_message3_benchmark_message3_7_proto_init() {
}
}
}
type x struct{}
out := protoimpl.TypeBuilder{
File: protoimpl.DescBuilder{
GoPackagePath: reflect.TypeOf(x{}).PkgPath(),
RawDescriptor: file_datasets_google_message3_benchmark_message3_7_proto_rawDesc,
NumEnums: 0,
NumMessages: 10,

View File

@ -7,6 +7,7 @@ import (
protoreflect "google.golang.org/protobuf/reflect/protoreflect"
prototype "google.golang.org/protobuf/reflect/prototype"
protoimpl "google.golang.org/protobuf/runtime/protoimpl"
reflect "reflect"
sync "sync"
)
@ -10435,8 +10436,10 @@ func file_datasets_google_message3_benchmark_message3_8_proto_init() {
if File_datasets_google_message3_benchmark_message3_8_proto != nil {
return
}
type x struct{}
out := protoimpl.TypeBuilder{
File: protoimpl.DescBuilder{
GoPackagePath: reflect.TypeOf(x{}).PkgPath(),
RawDescriptor: file_datasets_google_message3_benchmark_message3_8_proto_rawDesc,
NumEnums: 59,
NumMessages: 0,

View File

@ -7,6 +7,7 @@ import (
protoreflect "google.golang.org/protobuf/reflect/protoreflect"
protoiface "google.golang.org/protobuf/runtime/protoiface"
protoimpl "google.golang.org/protobuf/runtime/protoimpl"
reflect "reflect"
sync "sync"
)
@ -5888,8 +5889,10 @@ func file_datasets_google_message4_benchmark_message4_proto_init() {
}
}
}
type x struct{}
out := protoimpl.TypeBuilder{
File: protoimpl.DescBuilder{
GoPackagePath: reflect.TypeOf(x{}).PkgPath(),
RawDescriptor: file_datasets_google_message4_benchmark_message4_proto_rawDesc,
NumEnums: 0,
NumMessages: 45,

View File

@ -7,6 +7,7 @@ import (
protoreflect "google.golang.org/protobuf/reflect/protoreflect"
protoiface "google.golang.org/protobuf/runtime/protoiface"
protoimpl "google.golang.org/protobuf/runtime/protoimpl"
reflect "reflect"
sync "sync"
)
@ -5991,8 +5992,10 @@ func file_datasets_google_message4_benchmark_message4_1_proto_init() {
}
}
}
type x struct{}
out := protoimpl.TypeBuilder{
File: protoimpl.DescBuilder{
GoPackagePath: reflect.TypeOf(x{}).PkgPath(),
RawDescriptor: file_datasets_google_message4_benchmark_message4_1_proto_rawDesc,
NumEnums: 0,
NumMessages: 44,

View File

@ -6,6 +6,7 @@ package google_message4
import (
protoreflect "google.golang.org/protobuf/reflect/protoreflect"
protoimpl "google.golang.org/protobuf/runtime/protoimpl"
reflect "reflect"
sync "sync"
)
@ -3725,8 +3726,10 @@ func file_datasets_google_message4_benchmark_message4_2_proto_init() {
}
}
}
type x struct{}
out := protoimpl.TypeBuilder{
File: protoimpl.DescBuilder{
GoPackagePath: reflect.TypeOf(x{}).PkgPath(),
RawDescriptor: file_datasets_google_message4_benchmark_message4_2_proto_rawDesc,
NumEnums: 0,
NumMessages: 35,

View File

@ -7,6 +7,7 @@ import (
protoreflect "google.golang.org/protobuf/reflect/protoreflect"
prototype "google.golang.org/protobuf/reflect/prototype"
protoimpl "google.golang.org/protobuf/runtime/protoimpl"
reflect "reflect"
sync "sync"
)
@ -4782,8 +4783,10 @@ func file_datasets_google_message4_benchmark_message4_3_proto_init() {
if File_datasets_google_message4_benchmark_message4_3_proto != nil {
return
}
type x struct{}
out := protoimpl.TypeBuilder{
File: protoimpl.DescBuilder{
GoPackagePath: reflect.TypeOf(x{}).PkgPath(),
RawDescriptor: file_datasets_google_message4_benchmark_message4_3_proto_rawDesc,
NumEnums: 42,
NumMessages: 0,

View File

@ -7,6 +7,7 @@ import (
protoreflect "google.golang.org/protobuf/reflect/protoreflect"
prototype "google.golang.org/protobuf/reflect/prototype"
protoimpl "google.golang.org/protobuf/runtime/protoimpl"
reflect "reflect"
sync "sync"
)
@ -748,8 +749,10 @@ func file_conformance_conformance_proto_init() {
(*ConformanceResponse_JspbPayload)(nil),
(*ConformanceResponse_TextPayload)(nil),
}
type x struct{}
out := protoimpl.TypeBuilder{
File: protoimpl.DescBuilder{
GoPackagePath: reflect.TypeOf(x{}).PkgPath(),
RawDescriptor: file_conformance_conformance_proto_rawDesc,
NumEnums: 2,
NumMessages: 4,

View File

@ -8,6 +8,7 @@ import (
prototype "google.golang.org/protobuf/reflect/prototype"
protoiface "google.golang.org/protobuf/runtime/protoiface"
protoimpl "google.golang.org/protobuf/runtime/protoimpl"
reflect "reflect"
sync "sync"
)
@ -2024,8 +2025,10 @@ func file_google_protobuf_test_messages_proto2_proto_init() {
(*TestAllTypesProto2_OneofDouble)(nil),
(*TestAllTypesProto2_OneofEnum)(nil),
}
type x struct{}
out := protoimpl.TypeBuilder{
File: protoimpl.DescBuilder{
GoPackagePath: reflect.TypeOf(x{}).PkgPath(),
RawDescriptor: file_google_protobuf_test_messages_proto2_proto_rawDesc,
NumEnums: 2,
NumMessages: 26,

View File

@ -13,6 +13,7 @@ import (
structpb "google.golang.org/protobuf/types/known/structpb"
timestamppb "google.golang.org/protobuf/types/known/timestamppb"
wrapperspb "google.golang.org/protobuf/types/known/wrapperspb"
reflect "reflect"
sync "sync"
)
@ -2205,8 +2206,10 @@ func file_google_protobuf_test_messages_proto3_proto_init() {
(*TestAllTypesProto3_OneofDouble)(nil),
(*TestAllTypesProto3_OneofEnum)(nil),
}
type x struct{}
out := protoimpl.TypeBuilder{
File: protoimpl.DescBuilder{
GoPackagePath: reflect.TypeOf(x{}).PkgPath(),
RawDescriptor: file_google_protobuf_test_messages_proto3_proto_rawDesc,
NumEnums: 3,
NumMessages: 22,

View File

@ -6,6 +6,7 @@ package irregular
import (
protoreflect "google.golang.org/protobuf/reflect/protoreflect"
protoimpl "google.golang.org/protobuf/runtime/protoimpl"
reflect "reflect"
sync "sync"
)
@ -211,8 +212,10 @@ func file_irregular_test_proto_init() {
file_irregular_test_proto_msgTypes[0].OneofWrappers = []interface{}{
(*Message_OneofMessage)(nil),
}
type x struct{}
out := protoimpl.TypeBuilder{
File: protoimpl.DescBuilder{
GoPackagePath: reflect.TypeOf(x{}).PkgPath(),
RawDescriptor: file_irregular_test_proto_rawDesc,
NumEnums: 0,
NumMessages: 2,

View File

@ -18,6 +18,7 @@ import (
proto3_v1_21 "google.golang.org/protobuf/internal/testprotos/legacy/proto3.v1.2.1-20181126-8d0c54c1"
protoreflect "google.golang.org/protobuf/reflect/protoreflect"
protoimpl "google.golang.org/protobuf/runtime/protoimpl"
reflect "reflect"
sync "sync"
)
@ -320,8 +321,10 @@ func file_legacy_legacy_proto_init() {
}
}
}
type x struct{}
out := protoimpl.TypeBuilder{
File: protoimpl.DescBuilder{
GoPackagePath: reflect.TypeOf(x{}).PkgPath(),
RawDescriptor: file_legacy_legacy_proto_rawDesc,
NumEnums: 0,
NumMessages: 1,

View File

@ -7,6 +7,7 @@ import (
protoreflect "google.golang.org/protobuf/reflect/protoreflect"
protoiface "google.golang.org/protobuf/runtime/protoiface"
protoimpl "google.golang.org/protobuf/runtime/protoimpl"
reflect "reflect"
sync "sync"
)
@ -121,8 +122,10 @@ func file_messageset_messagesetpb_message_set_proto_init() {
}
}
}
type x struct{}
out := protoimpl.TypeBuilder{
File: protoimpl.DescBuilder{
GoPackagePath: reflect.TypeOf(x{}).PkgPath(),
RawDescriptor: file_messageset_messagesetpb_message_set_proto_rawDesc,
NumEnums: 0,
NumMessages: 1,

View File

@ -8,6 +8,7 @@ import (
protoreflect "google.golang.org/protobuf/reflect/protoreflect"
protoiface "google.golang.org/protobuf/runtime/protoiface"
protoimpl "google.golang.org/protobuf/runtime/protoimpl"
reflect "reflect"
sync "sync"
)
@ -233,8 +234,10 @@ func file_messageset_msetextpb_msetextpb_proto_init() {
}
}
}
type x struct{}
out := protoimpl.TypeBuilder{
File: protoimpl.DescBuilder{
GoPackagePath: reflect.TypeOf(x{}).PkgPath(),
RawDescriptor: file_messageset_msetextpb_msetextpb_proto_rawDesc,
NumEnums: 0,
NumMessages: 2,

View File

@ -7,6 +7,7 @@ import (
protoreflect "google.golang.org/protobuf/reflect/protoreflect"
protoiface "google.golang.org/protobuf/runtime/protoiface"
protoimpl "google.golang.org/protobuf/runtime/protoimpl"
reflect "reflect"
sync "sync"
)
@ -79,8 +80,10 @@ func file_test_ext_proto_init() {
return
}
file_test_test_proto_init()
type x struct{}
out := protoimpl.TypeBuilder{
File: protoimpl.DescBuilder{
GoPackagePath: reflect.TypeOf(x{}).PkgPath(),
RawDescriptor: file_test_ext_proto_rawDesc,
NumEnums: 0,
NumMessages: 0,

View File

@ -8,6 +8,7 @@ import (
prototype "google.golang.org/protobuf/reflect/prototype"
protoiface "google.golang.org/protobuf/runtime/protoiface"
protoimpl "google.golang.org/protobuf/runtime/protoimpl"
reflect "reflect"
sync "sync"
)
@ -4908,8 +4909,10 @@ func file_test_test_proto_init() {
file_test_test_proto_msgTypes[9].OneofWrappers = []interface{}{
(*TestRequiredForeign_OneofMessage)(nil),
}
type x struct{}
out := protoimpl.TypeBuilder{
File: protoimpl.DescBuilder{
GoPackagePath: reflect.TypeOf(x{}).PkgPath(),
RawDescriptor: file_test_test_proto_rawDesc,
NumEnums: 4,
NumMessages: 41,

View File

@ -7,6 +7,7 @@ import (
protoreflect "google.golang.org/protobuf/reflect/protoreflect"
prototype "google.golang.org/protobuf/reflect/prototype"
protoimpl "google.golang.org/protobuf/runtime/protoimpl"
reflect "reflect"
sync "sync"
)
@ -161,8 +162,10 @@ func file_test_test_import_proto_init() {
}
}
}
type x struct{}
out := protoimpl.TypeBuilder{
File: protoimpl.DescBuilder{
GoPackagePath: reflect.TypeOf(x{}).PkgPath(),
RawDescriptor: file_test_test_import_proto_rawDesc,
NumEnums: 1,
NumMessages: 1,

View File

@ -6,6 +6,7 @@ package test
import (
protoreflect "google.golang.org/protobuf/reflect/protoreflect"
protoimpl "google.golang.org/protobuf/runtime/protoimpl"
reflect "reflect"
sync "sync"
)
@ -105,8 +106,10 @@ func file_test_test_public_proto_init() {
}
}
}
type x struct{}
out := protoimpl.TypeBuilder{
File: protoimpl.DescBuilder{
GoPackagePath: reflect.TypeOf(x{}).PkgPath(),
RawDescriptor: file_test_test_public_proto_rawDesc,
NumEnums: 0,
NumMessages: 1,

View File

@ -6,6 +6,7 @@ package weak
import (
protoreflect "google.golang.org/protobuf/reflect/protoreflect"
protoimpl "google.golang.org/protobuf/runtime/protoimpl"
reflect "reflect"
sync "sync"
)
@ -115,8 +116,10 @@ func file_test_weak_test_weak_proto_init() {
}
}
}
type x struct{}
out := protoimpl.TypeBuilder{
File: protoimpl.DescBuilder{
GoPackagePath: reflect.TypeOf(x{}).PkgPath(),
RawDescriptor: file_test_weak_test_weak_proto_rawDesc,
NumEnums: 0,
NumMessages: 1,

View File

@ -6,6 +6,7 @@ package weak1
import (
protoreflect "google.golang.org/protobuf/reflect/protoreflect"
protoimpl "google.golang.org/protobuf/runtime/protoimpl"
reflect "reflect"
sync "sync"
)
@ -115,8 +116,10 @@ func file_test_weak1_test_weak_proto_init() {
}
}
}
type x struct{}
out := protoimpl.TypeBuilder{
File: protoimpl.DescBuilder{
GoPackagePath: reflect.TypeOf(x{}).PkgPath(),
RawDescriptor: file_test_weak1_test_weak_proto_rawDesc,
NumEnums: 0,
NumMessages: 1,

View File

@ -6,6 +6,7 @@ package weak2
import (
protoreflect "google.golang.org/protobuf/reflect/protoreflect"
protoimpl "google.golang.org/protobuf/runtime/protoimpl"
reflect "reflect"
sync "sync"
)
@ -115,8 +116,10 @@ func file_test_weak2_test_weak_proto_init() {
}
}
}
type x struct{}
out := protoimpl.TypeBuilder{
File: protoimpl.DescBuilder{
GoPackagePath: reflect.TypeOf(x{}).PkgPath(),
RawDescriptor: file_test_weak2_test_weak_proto_rawDesc,
NumEnums: 0,
NumMessages: 1,

View File

@ -7,6 +7,7 @@ import (
protoreflect "google.golang.org/protobuf/reflect/protoreflect"
prototype "google.golang.org/protobuf/reflect/prototype"
protoimpl "google.golang.org/protobuf/runtime/protoimpl"
reflect "reflect"
sync "sync"
)
@ -1390,8 +1391,10 @@ func file_test3_test_proto_init() {
(*TestAllTypes_OneofDouble)(nil),
(*TestAllTypes_OneofEnum)(nil),
}
type x struct{}
out := protoimpl.TypeBuilder{
File: protoimpl.DescBuilder{
GoPackagePath: reflect.TypeOf(x{}).PkgPath(),
RawDescriptor: file_test3_test_proto_rawDesc,
NumEnums: 2,
NumMessages: 20,

View File

@ -7,6 +7,7 @@ import (
protoreflect "google.golang.org/protobuf/reflect/protoreflect"
prototype "google.golang.org/protobuf/reflect/prototype"
protoimpl "google.golang.org/protobuf/runtime/protoimpl"
reflect "reflect"
sync "sync"
)
@ -151,8 +152,10 @@ func file_test3_test_import_proto_init() {
}
}
}
type x struct{}
out := protoimpl.TypeBuilder{
File: protoimpl.DescBuilder{
GoPackagePath: reflect.TypeOf(x{}).PkgPath(),
RawDescriptor: file_test3_test_import_proto_rawDesc,
NumEnums: 1,
NumMessages: 1,

View File

@ -24,11 +24,6 @@ import (
"google.golang.org/protobuf/reflect/protoreflect"
)
// TODO: Perhaps Register should record the frame of where the function was
// called and surface that in the error? That would help users debug duplicate
// registration issues. This presumes that we provide a way to disable automatic
// registration in generated code.
// GlobalFiles is a global registry of file descriptors.
var GlobalFiles *Files = new(Files)
@ -95,21 +90,24 @@ func (r *Files) Register(files ...protoreflect.FileDescriptor) error {
}
func (r *Files) registerFile(fd protoreflect.FileDescriptor) error {
path := fd.Path()
if r.filesByPath[path] != nil {
return errors.New("file %q is already registered", fd.Path())
if prev := r.filesByPath[path]; prev != nil {
err := errors.New("file %q is already registered", fd.Path())
return amendErrorWithCaller(err, prev, fd)
}
for name := fd.Package(); name != ""; name = name.Parent() {
switch r.descsByName[name].(type) {
switch prev := r.descsByName[name]; prev.(type) {
case nil, *packageDescriptor:
default:
return errors.New("file %q has a name conflict over %v", fd.Path(), name)
err := errors.New("file %q has a name conflict over %v", fd.Path(), name)
return amendErrorWithCaller(err, prev, fd)
}
}
var err error
rangeTopLevelDescriptors(fd, func(d protoreflect.Descriptor) {
if r.descsByName[d.FullName()] != nil {
if prev := r.descsByName[d.FullName()]; prev != nil {
err = errors.New("file %q has a name conflict over %v", fd.Path(), d.FullName())
err = amendErrorWithCaller(err, prev, fd)
}
})
if err != nil {
@ -414,9 +412,10 @@ typeLoop:
default:
panic(fmt.Sprintf("invalid type: %T", t))
}
if r.typesByName[name] != nil {
if prev := r.typesByName[name]; prev != nil {
if firstErr == nil {
firstErr = errors.New("%v %v is already registered", typeName(typ), name)
err := errors.New("%v %v is already registered", typeName(typ), name)
firstErr = amendErrorWithCaller(err, prev, typ)
}
continue typeLoop
}
@ -425,9 +424,10 @@ typeLoop:
if xt, _ := typ.(protoreflect.ExtensionType); xt != nil {
field := xt.Number()
message := xt.ContainingMessage().FullName()
if r.extensionsByMessage[message][field] != nil {
if prev := r.extensionsByMessage[message][field]; prev != nil {
if firstErr == nil {
firstErr = errors.New("extension %v is already registered on message %v", name, message)
err := errors.New("extension number %d is already registered on message %v", field, message)
firstErr = amendErrorWithCaller(err, prev, typ)
}
continue typeLoop
}
@ -610,3 +610,30 @@ func typeName(t Type) string {
return fmt.Sprintf("%T", t)
}
}
func amendErrorWithCaller(err error, prev, curr interface{}) error {
prevPkg := goPackage(prev)
currPkg := goPackage(curr)
if prevPkg == "" || currPkg == "" || prevPkg == currPkg {
return err
}
return errors.New("%s; previously from %q, currently from %q", err, prevPkg, currPkg)
}
func goPackage(v interface{}) string {
switch d := v.(type) {
case protoreflect.EnumType:
v = d.Descriptor()
case protoreflect.MessageType:
v = d.Descriptor()
case protoreflect.ExtensionType:
v = d.Descriptor()
}
if d, ok := v.(protoreflect.Descriptor); ok {
v = d.ParentFile()
}
if d, ok := v.(interface{ GoPackagePath() string }); ok {
return d.GoPackagePath()
}
return ""
}

View File

@ -8,6 +8,7 @@ import (
prototype "google.golang.org/protobuf/reflect/prototype"
protoiface "google.golang.org/protobuf/runtime/protoiface"
protoimpl "google.golang.org/protobuf/runtime/protoimpl"
reflect "reflect"
sync "sync"
)
@ -534,8 +535,10 @@ func file_test_proto_init() {
}
}
}
type x struct{}
out := protoimpl.TypeBuilder{
File: protoimpl.DescBuilder{
GoPackagePath: reflect.TypeOf(x{}).PkgPath(),
RawDescriptor: file_test_proto_rawDesc,
NumEnums: 3,
NumMessages: 4,

View File

@ -8,6 +8,7 @@ import (
prototype "google.golang.org/protobuf/reflect/prototype"
protoiface "google.golang.org/protobuf/runtime/protoiface"
protoimpl "google.golang.org/protobuf/runtime/protoimpl"
reflect "reflect"
sync "sync"
)
@ -3754,8 +3755,10 @@ func file_google_protobuf_descriptor_proto_init() {
}
}
}
type x struct{}
out := protoimpl.TypeBuilder{
File: protoimpl.DescBuilder{
GoPackagePath: reflect.TypeOf(x{}).PkgPath(),
RawDescriptor: file_google_protobuf_descriptor_proto_rawDesc,
NumEnums: 6,
NumMessages: 27,

View File

@ -6,6 +6,7 @@ package anypb
import (
protoreflect "google.golang.org/protobuf/reflect/protoreflect"
protoimpl "google.golang.org/protobuf/runtime/protoimpl"
reflect "reflect"
sync "sync"
)
@ -237,8 +238,10 @@ func file_google_protobuf_any_proto_init() {
}
}
}
type x struct{}
out := protoimpl.TypeBuilder{
File: protoimpl.DescBuilder{
GoPackagePath: reflect.TypeOf(x{}).PkgPath(),
RawDescriptor: file_google_protobuf_any_proto_rawDesc,
NumEnums: 0,
NumMessages: 1,

View File

@ -8,6 +8,7 @@ import (
protoimpl "google.golang.org/protobuf/runtime/protoimpl"
sourcecontextpb "google.golang.org/protobuf/types/known/sourcecontextpb"
typepb "google.golang.org/protobuf/types/known/typepb"
reflect "reflect"
sync "sync"
)
@ -514,8 +515,10 @@ func file_google_protobuf_api_proto_init() {
}
}
}
type x struct{}
out := protoimpl.TypeBuilder{
File: protoimpl.DescBuilder{
GoPackagePath: reflect.TypeOf(x{}).PkgPath(),
RawDescriptor: file_google_protobuf_api_proto_rawDesc,
NumEnums: 0,
NumMessages: 3,

View File

@ -6,6 +6,7 @@ package durationpb
import (
protoreflect "google.golang.org/protobuf/reflect/protoreflect"
protoimpl "google.golang.org/protobuf/runtime/protoimpl"
reflect "reflect"
sync "sync"
)
@ -198,8 +199,10 @@ func file_google_protobuf_duration_proto_init() {
}
}
}
type x struct{}
out := protoimpl.TypeBuilder{
File: protoimpl.DescBuilder{
GoPackagePath: reflect.TypeOf(x{}).PkgPath(),
RawDescriptor: file_google_protobuf_duration_proto_rawDesc,
NumEnums: 0,
NumMessages: 1,

View File

@ -6,6 +6,7 @@ package emptypb
import (
protoreflect "google.golang.org/protobuf/reflect/protoreflect"
protoimpl "google.golang.org/protobuf/runtime/protoimpl"
reflect "reflect"
sync "sync"
)
@ -118,8 +119,10 @@ func file_google_protobuf_empty_proto_init() {
}
}
}
type x struct{}
out := protoimpl.TypeBuilder{
File: protoimpl.DescBuilder{
GoPackagePath: reflect.TypeOf(x{}).PkgPath(),
RawDescriptor: file_google_protobuf_empty_proto_rawDesc,
NumEnums: 0,
NumMessages: 1,

View File

@ -6,6 +6,7 @@ package fieldmaskpb
import (
protoreflect "google.golang.org/protobuf/reflect/protoreflect"
protoimpl "google.golang.org/protobuf/runtime/protoimpl"
reflect "reflect"
sync "sync"
)
@ -320,8 +321,10 @@ func file_google_protobuf_field_mask_proto_init() {
}
}
}
type x struct{}
out := protoimpl.TypeBuilder{
File: protoimpl.DescBuilder{
GoPackagePath: reflect.TypeOf(x{}).PkgPath(),
RawDescriptor: file_google_protobuf_field_mask_proto_rawDesc,
NumEnums: 0,
NumMessages: 1,

View File

@ -6,6 +6,7 @@ package sourcecontextpb
import (
protoreflect "google.golang.org/protobuf/reflect/protoreflect"
protoimpl "google.golang.org/protobuf/runtime/protoimpl"
reflect "reflect"
sync "sync"
)
@ -125,8 +126,10 @@ func file_google_protobuf_source_context_proto_init() {
}
}
}
type x struct{}
out := protoimpl.TypeBuilder{
File: protoimpl.DescBuilder{
GoPackagePath: reflect.TypeOf(x{}).PkgPath(),
RawDescriptor: file_google_protobuf_source_context_proto_rawDesc,
NumEnums: 0,
NumMessages: 1,

View File

@ -7,6 +7,7 @@ import (
protoreflect "google.golang.org/protobuf/reflect/protoreflect"
prototype "google.golang.org/protobuf/reflect/prototype"
protoimpl "google.golang.org/protobuf/runtime/protoimpl"
reflect "reflect"
sync "sync"
)
@ -440,8 +441,10 @@ func file_google_protobuf_struct_proto_init() {
(*Value_StructValue)(nil),
(*Value_ListValue)(nil),
}
type x struct{}
out := protoimpl.TypeBuilder{
File: protoimpl.DescBuilder{
GoPackagePath: reflect.TypeOf(x{}).PkgPath(),
RawDescriptor: file_google_protobuf_struct_proto_rawDesc,
NumEnums: 1,
NumMessages: 4,

View File

@ -6,6 +6,7 @@ package timestamppb
import (
protoreflect "google.golang.org/protobuf/reflect/protoreflect"
protoimpl "google.golang.org/protobuf/runtime/protoimpl"
reflect "reflect"
sync "sync"
)
@ -218,8 +219,10 @@ func file_google_protobuf_timestamp_proto_init() {
}
}
}
type x struct{}
out := protoimpl.TypeBuilder{
File: protoimpl.DescBuilder{
GoPackagePath: reflect.TypeOf(x{}).PkgPath(),
RawDescriptor: file_google_protobuf_timestamp_proto_rawDesc,
NumEnums: 0,
NumMessages: 1,

View File

@ -9,6 +9,7 @@ import (
protoimpl "google.golang.org/protobuf/runtime/protoimpl"
anypb "google.golang.org/protobuf/types/known/anypb"
sourcecontextpb "google.golang.org/protobuf/types/known/sourcecontextpb"
reflect "reflect"
sync "sync"
)
@ -883,8 +884,10 @@ func file_google_protobuf_type_proto_init() {
}
}
}
type x struct{}
out := protoimpl.TypeBuilder{
File: protoimpl.DescBuilder{
GoPackagePath: reflect.TypeOf(x{}).PkgPath(),
RawDescriptor: file_google_protobuf_type_proto_rawDesc,
NumEnums: 3,
NumMessages: 5,

View File

@ -6,6 +6,7 @@ package wrapperspb
import (
protoreflect "google.golang.org/protobuf/reflect/protoreflect"
protoimpl "google.golang.org/protobuf/runtime/protoimpl"
reflect "reflect"
sync "sync"
)
@ -606,8 +607,10 @@ func file_google_protobuf_wrappers_proto_init() {
}
}
}
type x struct{}
out := protoimpl.TypeBuilder{
File: protoimpl.DescBuilder{
GoPackagePath: reflect.TypeOf(x{}).PkgPath(),
RawDescriptor: file_google_protobuf_wrappers_proto_rawDesc,
NumEnums: 0,
NumMessages: 9,

View File

@ -7,6 +7,7 @@ import (
protoreflect "google.golang.org/protobuf/reflect/protoreflect"
protoimpl "google.golang.org/protobuf/runtime/protoimpl"
descriptorpb "google.golang.org/protobuf/types/descriptorpb"
reflect "reflect"
sync "sync"
)
@ -473,8 +474,10 @@ func file_google_protobuf_compiler_plugin_proto_init() {
}
}
}
type x struct{}
out := protoimpl.TypeBuilder{
File: protoimpl.DescBuilder{
GoPackagePath: reflect.TypeOf(x{}).PkgPath(),
RawDescriptor: file_google_protobuf_compiler_plugin_proto_rawDesc,
NumEnums: 0,
NumMessages: 4,