Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to pass experimental_allow_proto3_optional for C# <proto/> definitions to enable optional in proto3?

I've looked everywhere for this. The C# grpc people don't know how to do it, and point to the grpc/grpc people for the tooling but you're not allowed to ask questions there. I guess I could phrase this as a feature but that feels like cheating. (please add documentation too show how...)

How does one pass the parameter for this to C# grpc in the <proto> definition so that we can use the optional keyword?

Thanks!

like image 753
James Hancock Avatar asked Jul 24 '20 13:07

James Hancock


1 Answers

As for January 2021, the only - yet hacky - way around this is to make your proto filename (or a directory name) contain the string test_proto3_optional, as pointed out by protobuf documentation:

If you try to run protoc on a file with proto3 optional fields, you will get an error because the feature is still experimental. [...] There are two options for getting around this error:

  1. Pass --experimental_allow_proto3_optional to protoc.
  2. Make your filename (or a directory name) contain the string test_proto3_optional. This indicates that the proto file is specifically for testing proto3 optional support, so the check is suppressed.

For more information see #977 (grpc-dotnet), #19164 (AspNetCore.Docs) and #23686 (grpc) issues.

like image 64
Sezi Avatar answered Nov 09 '22 19:11

Sezi