Suppress emitting explicit accessors for protobuf message fields

12 views
Skip to first unread message

Mainak Kundu

unread,
Mar 16, 2021, 4:21:48 AM3/16/21
to Protocol Buffers
Hi,

Can we have a way to suppress emitting explicit accessors for protobuf message fields during protoc compilation? My server implementation is auto-generated from a backend component and uses the protobuf reflection mechanism instead of the explicit accessors. If I can suppress emitting those explicit accessors, that will reduce my compilation time.

To get a proof-of-concept, I added `option optimize_for = CODE_SIZE;` in helloworld.proto, re-wrote the SayHello method in greeter_server.cc using reflection:

auto nameDescriptor = request->GetDescriptor()->FindFieldByName("name");
std::string name = request->GetReflection()->GetString(*request, nameDescriptor);
auto messageDescriptor = reply->GetDescriptor()->FindFieldByName("message");
reply->GetReflection()->SetString(reply, messageDescriptor, prefix + name);

and then deleted all public accessor definitions from the generated helloworld.pb.h. The server-side is compiled and is running fine with these changes.

Regards,
Mainak


Reply all
Reply to author
Forward
0 new messages