我的目标是从现有的c protobuf消息中恢复其他人写的丢失的.proto文件 . 通过使用描述符和EnumDescriptor,我能够执行以下操作:
const google::protobuf::EnumDescriptor* logOptionDesc =
bgs::protocol::LogOption_descriptor();
std::string logOptionStr = logOptionDesc->DebugString();
bgs::protocol::EntityId entityId;
const google::protobuf::Descriptor* entityIdDesc = entityId.GetDescriptor();
std::string entityIdStr = entityIdDesc->DebugString();
我得到的logOptionStr字符串看起来像这样:
enum LogOption {
HIDDEN = 1;
HEX = 2;
}
和entityIdStr:
message EntityId {
required fixed64 high = 1 [(.bgs.protocol.log) = HEX];
required fixed64 low = 2 [(.bgs.protocol.log) = HEX];
}
请注意,EntityId消息包含一些字段选项 . 在不解决此依赖关系的情况下,我无法生成可帮助我恢复.proto文件的FileDescriptor . 我怀疑EntityId字符串应如下所示:
import "LogOption.proto";
package bgs.protocol;
extend google.protobuf.FieldOptions {
optional LogOptions log = HEX;
}
message EntityId {
required fixed64 high = 1 [(.bgs.protocol.log) = HEX];
required fixed64 low = 2 [(.bgs.protocol.log) = HEX];
}
是否可以恢复需要其他信息(如包,字段选项和导入)的.proto文件?还有什么方法可以恢复.proto文件?