Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Equivalent of #ifdef syntax in protobuf

What is the #ifdef equivalent in protobuf messages? I don't find anything in language guide https://developers.google.com/protocol-buffers/docs/proto

like image 447
shiva shankar Avatar asked Jan 07 '23 06:01

shiva shankar


1 Answers

There is none built into the Protobuf language itself, but you could of course run the C preprocessor over your .proto files before passing them to protoc. On Unix systems:

cpp -P src.proto > preprocessed.proto
protoc preprocessed.proto

cpp (which comes with your C compiler) will evaluate #ifdef and other C preprocessor directives (anything starting with #) and output a new file with the results.

(The -P option prevents the preprocessor from outputting debug info directives intended for the C compiler, which protoc wouldn't understand.)

like image 191
Kenton Varda Avatar answered Jan 27 '23 07:01

Kenton Varda