I have a proto message I'm using in a service to store data in various places
My message is like this:
message Matrix {
double width = 1;
double height = 2;
repeated double entries = 3;
}
My team has decided that the Matrix
message is too large, and changing the types to float
seems like an easy way to achieve a payload size reduction.
But when I change the proto definition to use float
instead of double
here, and try to read old data (in a Python reader), it looks corrupted.
One option I can think of is to add a new float option for each field:
message Matrix {
oneof r_oneof {
double width_d = 1;
float width_f = 4;
}
oneof c_oneof {
double height_d = 2;
float height_f = 5;
}
oneof e_oneof {
repeated double entries_d = 3;
repeated float entries_f = 6;
}
}
Then my deserializing code can check whether each oneof field is the double
or float
field. This works, but feels like a clunky design pattern.
Is there another way to provide backwards-compatibility with old data in this example?