Not really.
There are several hacks that you can use. None of them work, and (I think) both go to proto3:
- Define a message with a string field and give it a default value, which is your constant value. However, Protobuf 3 seems to remove the default values.
- Use “customizable options,” which should probably be called “annotations,” since they are very similar to annotations in Java or other languages. You can declare an annotation of a type string, and then annotate some dummy declaration using annotation and use a constant value. However, custom options are based on extensions that are also removed in proto3, so I assume that custom options were also removed. (This is the answer suggested here: fooobar.com/questions/1244104 / .... )
FWIW, Cap'n Proto , an alternative to protocol buffers, supports constants. (Disclosure: I am the author of Cap'n Proto, as well as most of Google Protobuf v2.)
source share