I’m trying to write custom protobuf code generator using C++ (for JSON to gRPC transcoding). I’ve the following example proto file:
syntax = "proto3";
package test;
import "google/api/annotations.proto";
service Test {
rpc TestCall (Request) returns (Response) {
option (google.api.http) = {
post: "/test.Test/TestCall/{query}"
body: "*"
};
}
}
message Request {
string query = 1;
string language = 2;
}
message Response {
float temperature = 2;
int32 pressure = 3;
string description = 4;
}
I got a MethodDescriptor
and I want to get post
and body
options value from the descriptor like this (code is simplifyed):
const google::protobuf::FileDescriptor* file;
const google::protobuf::MethodDescriptor* descriptor = file->service(0)->method(0);
auto ext = descriptor->options().GetExtension(...);
Is it correct way at all? And I don’t know how correctly initialize ExtensionIdentifier
to pass into GetExtension(...)
.
So how can I get options values from a generator code?
Thanks!