I have a public proto files which cant be altered here is this for Refrence
syntax = "proto2";
package openrtb;
enum ContentCategory {
IAB1 = 1;
IAB1_1 = 2;
IAB1_2 = 3;
IAB11 = 191;
IAB11_1 = 192;
}
When I run:
protoc --proto_path=. --cpp_out=./src --grpc_out=./src --plugin=protoc-gen-grpc=`which grpc_cpp_plugin` test2.proto
It says Warning message and doesn't generate the file
test2.proto:9:3: Enum name IAB11 has the same name as IAB1_1 if you ignore case and strip out the enum name prefix (if any). (If you are using allow_alias, please assign the same number to each enum value name.)
For generating in Go
same message but it's able to generate the file, I'm just trying to get valid C++ code generation without modifying the proto file.
I have a public proto files which cant be altered here is this for Refrence
syntax = "proto2";
package openrtb;
enum ContentCategory {
IAB1 = 1;
IAB1_1 = 2;
IAB1_2 = 3;
IAB11 = 191;
IAB11_1 = 192;
}
When I run:
protoc --proto_path=. --cpp_out=./src --grpc_out=./src --plugin=protoc-gen-grpc=`which grpc_cpp_plugin` test2.proto
It says Warning message and doesn't generate the file
test2.proto:9:3: Enum name IAB11 has the same name as IAB1_1 if you ignore case and strip out the enum name prefix (if any). (If you are using allow_alias, please assign the same number to each enum value name.)
For generating in Go
same message but it's able to generate the file, I'm just trying to get valid C++ code generation without modifying the proto file.
1 Answer
Reset to default 2This 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 MY_ENUM
becomes MyEnum
and IAB1_1
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.
openrtb.proto
referenced by @3cxezivlq usingprotoc
v30.2 (latest). However, I believe the issue is in the outdated (5 year old) proto used by thebid-valuator-endpoint-java
code. The current (!?) RTB Protosopenrtb-proto
compiles successfully. The issue is confusingly reported but appears to be this and a couple of other relateds. – DazWilkin Commented Mar 30 at 17:20