-
Notifications
You must be signed in to change notification settings - Fork 0
Hints for Pormoting Data Types
Choosing a data-type is a long term decision, as preserving it means keeping backward and forward compatibility. Backward compatibility means a later version can read data from an older version. Froward compatibility means an older version can read data from a newer version.
So choosing the right data type should be done with some planning and considerations concerning possible future changes and expansions. Adding new fields will not break forward compatibility, but of course the older version cannot handle this new data - it will simply be ignored (unless configured to trigger an error).
Nevertheless, it might be necessary to change data types later. Expanding an enum with new values is the simplest way, and will not cause any problems and does not require any special consideration.
But changing or expanding a datatype to a higher number of bits is not always possible, and needs some consideration. See below what kind of type changes are possible without breaking backward compatibility. Forward compatibility will always only work if the provided values are still in the old range.
change item | change options |
---|---|
storage type | fixed length of bits according to type |
range expansion | not possible |
type change | no compatbile types |
change item | change options |
---|---|
storage type | variable length |
range expansion | expansion to higher number of bits possible |
type change | for uintxx possible to intyy with xx<yy |
change item | change options |
---|---|
storage type | variable length, negative numbers always require 10 bytes |
range expansion | expansion to higher number of bits possible |
type change | to uintxx possible if negative values were never used |
change item | change options |
---|---|
storage type | variable length, negative numbers encoded efficiently |
range expansion | expansion to higher number of bits possible |
type change | no compatible types |
change item | change options |
---|---|
storage type | variable length prefix followed by data |
type change | to bytes possible |
change item | change options |
---|---|
storage type | variable length prefix followed by data |
type change | no compatible types |
change item | change options |
---|---|
storage type | variable length prefix followed by data |
type change | addition of new fields possible |
Packed repeated types store the related ID just once for all elements instead of storing pairs of id and element. That makes packed repeated types more efficent than regular repeated types, but also incompatible to updating from non-repeated types. I.e. regular fields can be changed from optional to repeated, but not to a packed repeated type.