admin管理员组文章数量:1356745
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.
本文标签:
版权声明:本文标题:protocol buffers - Why does protoc fail with enum name conflict in C++ for valid .proto definitions? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1743989504a2571873.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
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