jhump / protoreflect

Reflection (Rich Descriptors) for Go Protocol Buffers
Apache License 2.0
1.35k stars 172 forks source link

How to get comments from result of ParseFilesButDoNotLink #560

Closed joesonw closed 1 year ago

joesonw commented 1 year ago

I'm using parser.ParseFilesButDoNotLink to merge files that have circular references (thus unlinked).

But how do I get sourceCodeInfos from descriptorpb structures?

jhump commented 1 year ago

@joesonw, they are in the FileDescriptorProto: https://github.com/protocolbuffers/protobuf-go/blob/v1.30.0/types/descriptorpb/descriptor.pb.go#L751-L755

This representation is a little bit of a challenge to use. You have to build up a path of tag numbers and indexes that represents the traversal within the FileDescriptorProto to the element of interest. These comments in google/protobuf/descriptor.proto describe it a little bit, with some examples: https://github.com/protocolbuffers/protobuf/blob/v23.0/src/google/protobuf/descriptor.proto#L907-L930