3

My goal is to restore the lost .proto files written by someone else from existing c++ protobuf messages. By using the Descriptor and EnumDescriptor I was able to do the following:

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();

The logOptionStr string I got looked something like this:

enum LogOption {
  HIDDEN = 1;
  HEX = 2;
}

and entityIdStr:

message EntityId {
  required fixed64 high = 1 [(.bgs.protocol.log) = HEX];
  required fixed64 low = 2 [(.bgs.protocol.log) = HEX];
}

Notice the EntityId message contains some field options. Without resolving this dependency I cannot generate a FileDescriptor that can help me restore the .proto files. I suspect the EntityId string should look something like the following:

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];
}

Is it possible to restore the .proto files that require additional information such as package, field options and imports? What else do I need to do to restore the .proto files?

mtkzcs
  • 41
  • 4

0 Answers0