Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

protobuf oneof backwards compatibility

If I had some protobufs created with the following protobuf schema

message Foo {
    Bar1 bar_1 = 1;

    Bar2 bar_2 = 2;
}

but later on updated the protobuf schema to

message Foo {
  oneof foo {
    Bar1 bar_1 = 1;

    Bar2 bar_2 = 2;
  }
}

Will this second version be able to read the protos created with the first version?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

Yes, the second version of the protobuf schema should be able to read protobufs created with the first version. When you update a protobuf schema, the changes you make only affect how new protobufs are encoded and decoded. Protobufs that were created with the previous version of the schema will still be encoded and decoded using the old schema. This means that the second version of the schema should still be able to read protobufs created with the first version, even though the schema has changed.

However, it is worth noting that when you make changes to a protobuf schema, you should take care to ensure that the changes are backward-compatible. This means that the new schema should still be able to read protobufs created with the old schema, without losing any information. In the example you provided, the change from the first version of the schema to the second is backward-compatible, so the second version should be able to read protobufs created with the first version. However, if you made a change that was not backward-compatible, the second version of the schema would not be able to read protobufs created with the first version.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading