Question Details

No question body available.

Tags

c++ protocol-buffers grpc protoc

Answers (1)

March 30, 2025 Score: 4 Rep: 12,598 Quality: Medium Completeness: 80%

This confusing behavior of protoc has been reported upstream in multiple issues: #9272, #16375 and #18149.

The underlying cause is not common prefixes, as the error message would lead you to believe, but the underscores. Protoc strips them out in the comparison, because some language generators (at least C# and JSON) convert them to case differences. For example MYENUM becomes MyEnum and IAB11 becomes Iab11.

Protobuf specification mentions this in the section JSON Name Conflicts.

Apparently the Go generator for protobuf does not check for this, because it does not do this name transformation in its output.

The most straightforward option is to have a local copy of the file, and change the names to use a letter in place of the underscore. Normally the encoded format of protobuf only uses the numbers, to changing the names wouldn't be a problem for compatibility. However, in this specific case it looks like it is the names that are used in string arrays, and not the enum value itself. That is a weird design for a proto file. But in this case you can just discard the enumeration and hard-code the texts.

Ideally you would report this bug to the project containing the .proto files, but it may be difficult for them to make the change as the names would affect many projects. According to a comment by DazWilkin, the latest version openrtb-proto does not contain the problem, but on the other hand it might not be compatible with the project you are using.