Skip to content

Commit acacf81

Browse files
authored
all: rely on protodesc.ToFileDescriptorProto (#1214)
Use protodesc.ToFileDescriptorProto to retrieve the raw descriptors for legacy support instead of the undocumented ProtoLegacyRawDesc method that we expect v2 to provide. This change will cause the legacy proto package to incur a dependency on the descriptorpb package.
1 parent eccd77d commit acacf81

File tree

2 files changed

+5
-16
lines changed

2 files changed

+5
-16
lines changed

descriptor/descriptor.go

+3-8
Original file line numberDiff line numberDiff line change
@@ -79,14 +79,9 @@ func deriveRawDescriptor(d protoreflect.Descriptor) ([]byte, []int) {
7979
}
8080

8181
// Obtain the raw file descriptor.
82-
var raw []byte
83-
switch fd := d.(type) {
84-
case interface{ ProtoLegacyRawDesc() []byte }:
85-
raw = fd.ProtoLegacyRawDesc()
86-
case protoreflect.FileDescriptor:
87-
raw, _ = proto.Marshal(protodesc.ToFileDescriptorProto(fd))
88-
}
89-
file := protoimpl.X.CompressGZIP(raw)
82+
fd := d.(protoreflect.FileDescriptor)
83+
b, _ := proto.Marshal(protodesc.ToFileDescriptorProto(fd))
84+
file := protoimpl.X.CompressGZIP(b)
9085

9186
// Reverse the indexes, since we populated it in reverse.
9287
for i, j := 0, len(idxs)-1; i < j; i, j = i+1, j-1 {

proto/registry.go

+2-8
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import (
1313
"strings"
1414
"sync"
1515

16+
"google.golang.org/protobuf/reflect/protodesc"
1617
"google.golang.org/protobuf/reflect/protoreflect"
1718
"google.golang.org/protobuf/reflect/protoregistry"
1819
"google.golang.org/protobuf/runtime/protoimpl"
@@ -62,14 +63,7 @@ func FileDescriptor(s filePath) fileDescGZIP {
6263
// Find the descriptor in the v2 registry.
6364
var b []byte
6465
if fd, _ := protoregistry.GlobalFiles.FindFileByPath(s); fd != nil {
65-
if fd, ok := fd.(interface{ ProtoLegacyRawDesc() []byte }); ok {
66-
b = fd.ProtoLegacyRawDesc()
67-
} else {
68-
// TODO: Use protodesc.ToFileDescriptorProto to construct
69-
// a descriptorpb.FileDescriptorProto and marshal it.
70-
// However, doing so causes the proto package to have a dependency
71-
// on descriptorpb, leading to cyclic dependency issues.
72-
}
66+
b, _ = Marshal(protodesc.ToFileDescriptorProto(fd))
7367
}
7468

7569
// Locally cache the raw descriptor form for the file.

0 commit comments

Comments
 (0)