I'm trying to reverse-engineer and document several protobufs for which I don't have the descriptor metadata, and to create .proto
files for them. It's been going great until I encountered a protobuf where two completely differently structured messages share the same unique ID. The top level is simple:
message main
{
string user=1;
repeated Section sections=2;
}
Looking at the Section type, there are some that look like this:
message Section
{
string name=1;
string fulldescription=2;
string briefdescription=3;
int32 level=4;
...
}
...and some that look like this:
message Section
{
int32 cost=1;
int32 tier=2;
int64 timestamp=3;
...
}
It would make perfect sense if one of these had the id of 2 and the other of, say, 3, but no, both types show with the unique ID of 2. The protobuf documentation very clearly states that each field in the message definition must have a unique number, and here is a perfectly valid (well, working) protobuf that does the exact opposite. I don't understand how it's possible or, more importantly, how to re-create this in the .proto
file?
This does not seem to be a "oneof" situation either, since both message types are present in the same protobuf at the same time, and at any rate the "oneof" alternatives would still have different identifiers for fields of different types.
For reference, here's an example excerpt from the output generated by protoc --decode-raw
, which I'm trying to document:
1 {
1: "User123"
2 {
1 {
1: "JohnDoe"
2: "This is the full description of the user, with a lot of details"
3: "A brief summary of the above"
4: 13
}
}
2 {
1 {
1: 135
2: 2
3: 1653606400
}
}
}
(This post seems to be asking the same thing, but it's old and doesn't have an actual answer: Can you assign multiple different value types to one field in a repeated Protobuf message?)
(This is my absolutely very first StackOverflow question, so apologies if the quality of the post is not up to snuff; please let me know what I need to add to make it clearer).