How to access custom options after protoc -ofile_descriptor_set from Golang?

Viewed 14

Is there a way to access the contents of a custom options extension from a descriptorpb.DescriptorProto read out of a FileDescriptorSet?

First, I defined a custom option in a .proto file and compiled that source file as a Go import.

Second, I imported the option's .proto file in a separate .proto file and used it, then used protoc -omymessage.fds to write a FileDescriptorSet to a file.

Problem: I cannot find a way to read my custom options extension when starting from the FileDescriptorSet.

I tried code similar to this, because I couldn't find any other way to access extended options. I feel like there should be an accessor directly on the DescriptorProto representing the message, but there isn`t.

var fds descriptorpb.FileDescriptorSet
proto.Unmarshal(data, &fds) // Yes I'm checking for errors
for _, file := range fds.File {
  for _, msg := range file.MessageType {
    hasOpts := proto.HasExtension(msg.ProtoReflect().Descriptor().Options(), myoptions.E_MyOptions)
    // hasOpts is always false
  }
}
0 Answers
Related