What do I need to be careful of when changing protobuf serialized types in order not to break existing clients

StackOverflow https://stackoverflow.com/questions/20220459

  •  05-08-2022
  •  | 
  •  

Question

I need to make changes (additive in this case) to my serialized types without breaking existing clients. What do I need to be careful of? Or another way to put it, what types of changes will definitely break existing clients?

Était-ce utile?

La solution

Additive changes won't usually break clients. Unknown fields will either be ignored or stored as "extension" data. One possible scenario, however, is inheritance: if you have

abstract A
   concrete B

And you usually serialize B instances which works great; theb later you add C:

abstract A
    concrete B
    concrete C

Then new data of type C will not be recognised. The system will fall back to what it knows - A - but that is abstract so won't be creatable. Perhaps "dont use abstract base-classes in a DTO model" is the advice here!

Note that changing fields is almost universally a bad field. Don't change field 5 from an int to a string, for example.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top