Reading data by new versions of protobuf

For a data which is produced by Protobuf 2.5.X, is it safe to read it by Protobuf version 3.0.X?

Upvotes: 0

Views: 175

Answers (1)

Pavel Zdenek
Pavel Zdenek

Reputation: 7278

Protobuf wire format is designed to be backward and forward compatible. So generally it is safe, unless you shot yourself in the foot with one specific v2 feature: custom default values. Default values are constant in v3. Specifically enum default value is the first entry and it must be zero. So your v2 custom values will be lost - fields of default value do not appear on the wire at all, so the receiver has no idea whether it was not set or was set to default value. Mind that in v3 all fields are optional (no more required), so any field can be legally missing.

If you haven't used custom defaults in v2, or nonzero value for the first enum entry, v3 should read it just fine.

Upvotes: 1

Related Questions