Unable to parse proto file with "oneof" field
If there is "oneof" in any message inside .proto file, proto file parser is unable to parse it. Is there any way to generate typedef automatically using another parser? Unfortunately, there seems to be no easy way to generate typedef using any different parser. For example, I tried this one, but stuck because don't understand how to convert "oneof" values to typedef or how to handle internal protobuf type "timestamp": https://github.com/criccomini/proto-schema-parser
Actually, there are a lot of minor issues in the proto parser. For example, it can't process fields if there are no spaces around "=" like this one:
Type type= 1;
Hi! Unfortunately the proto file parser is mostly a series of regexes and not real protobuf definition parser, so it will probably fail on any non-simple protobuf definitions. That being said, oneofs shouldn't be too difficult to handle and I can add the spaces bug onto the list to get fixed.
The typedefs used by BBPB are it's own representation of the protobuf message types and, as far as I know, no other tool generates or uses BBPB typedefs.
The oneof specifier in proto files do not have any affect on the serialized messasges, so are ignored by BBPB. Fields inside the oneof are treated the same as any other field on the message.
For example:
message SampleMessage {
string target = 1;
oneof test_oneof {
string name = 4;
int32 number = 9;
}
}
Could be represented by the following typedef:
{
"1": {
"type": "string",
"name": "target"
},
"4": {
"type": "string",
"name": "name"
},
"9": {
"type": "int"
"name": "number"
},
}
For the timestamp type, this looks like it should be the right .proto definition: https://github.com/protocolbuffers/protobuf/blob/418399e5281353d0bb9877a88f89bd04a6f2b943/src/google/protobuf/timestamp.proto#L133
Which would map to something like:
{
"1": {
"type": "int",
"name": "seconds",
},
"2": {
"type": "int",
"name": "nanos",
},
}