Ulrik
Ulrik

Reputation: 73

How to parse .proto file and read custom message options using protobuf-net.Reflection?

I am parsing a set of proto files using FileDescriptorSet. Now I need to read a custom message option applied to a message in the set. How can I do that?

My proto could look like this:

syntax = "proto3";
import "google/protobuf/descriptor.proto";

extend google.protobuf.MessageOptions {
  string my_option = 51234;
}

message Country {
    string code = 1;
    option (my_option) = "true";
}

When I read DescriptorProto for the Country message, the DescriptorProto.Options contains no UninterpretedOptions or similar that could be my option...?

And a bonus question: How can I read the message/field comments in proto files?

Thanks

Upvotes: 1

Views: 1099

Answers (1)

Ulrik
Ulrik

Reputation: 73

Found a way to do this but not sure if best way:

DescriptorProto message = ...
bool isMyBoolOptionSet = message.Options != null && Extensible.GetValue<bool>(message.Options, [tag of option as declared in proto file]);

Upvotes: 1

Related Questions