解决proto文件转换时提示“Note that enum values use C++ scoping rules, meaning that enum values are siblings of their type, not children of it. ”

时间:2023-03-09 21:33:09
解决proto文件转换时提示“Note that enum values use C++ scoping rules, meaning that enum values are siblings of their type, not children of it. ”

前言:

想将.proto文件转换成.pb文件时一直报错,一开始以为是文件编码格式的问题,后来将文件改成windows下的utf-8格式后,又出现了新的报错(见下图)。百度了很久,才找到解决方法。

“Note that enum values use C++ scoping rules, meaning that enum values are siblings of their type, not children of it. ”这个报错的意思是:在所有pb文件中必须是唯一的,而不仅仅是在这个enum中唯一。反过来理解就是enum中的属性名定义必须是唯一的。

解决方法:

1.如果提示已经存在了,就将enum里的属性名改个唯一的名字咯

2.谷歌官方文档里还有一个解决方法:

在这个enum中添加option allow_alias = true;

解决proto文件转换时提示“Note that enum values use C++ scoping rules, meaning that enum values are siblings of their type, not children of it. ”

具体的可以查看https://developers.google.com/protocol-buffers/docs/proto3