Difference of proto messages with the relative positions of its attributes

Viewed 69

what is the difference if the attribute in a protobuf message is first or second member?

The Request proto message i have, has 2 fields. i am asked to interchange the position of the attributes

message SomeRequest {
  SomeMessage1 message1 = 1;
  SomeMessage2 message2 = 2;
}

Changed to :

message SomeRequest {
  SomeMessage2 message2 = 1;
  SomeMessage1 message1 = 2;
}

What could be the possible reasons of such a advice? message2 is expected to be more predominately searched? Also can i have few more scenarios to understand it better?

Thanks in advance!!

1 Answers

Ultimately, whoever asked for this change - maybe ask them for their reasons?

There are scenarios where lower field numbers are cheaper (space-wise) and so should be preferred, but fields 1 and 2 are identical in terms of space, so this this isn't a concern here.

If this was for byte compatibility with a pre-existing similar type, it might be a reasonable request.

Related