opyeb protobuflab

protobuflab · Compat

How a breaking change is judged

Where wire compatibility and source compatibility diverge, and how removals, type changes and renames are judged.

Protobuf compatibility has two layers: whether bytes already stored can be read with the new schema (wire compatibility), and whether existing code compiles against it (source compatibility). A breaking check looks mainly at the first.

The most dangerous changes

ChangeWire effectVerdict
Removed number, not reservedOld data is ignored by the new schemaerror
Renumbered field with the same nameThe other side reads a different fielderror
Type change, including int32 to int64The encoding differs and values breakerror
repeated to singular or backThe wire reading differserror
Field name change onlyThe wire is the same; JSON and code breakwarning
Package changeFully qualified type names changeerror

Similar types are still different

int32 and int64 are both varints, but their range and their ten-byte expansion for negatives differ. string and bytes are both length-delimited, but only one is UTF-8. So the tool treats a type change as an error even when the wire type is the same.

Delete with reserved

Leaving reserved 5; behind prevents the old number from being reused. The breaking check reports a removed number as a note when the new schema reserves it and as an error when it does not. Names can be protected the same way with reserved "legacy_ref";.

Enums and rpcs

Packages and message names

A package change alters every fully qualified type name. A message rename is inferred when a new message has the same field numbers, and reported as an error because Any, JSON mapping and generated type names break even though the wire is unchanged.

The check matches the two schemas by number. A field that exists only in the new schema is not an error by itself. Reusing an old number with a different type does hit the rules above.

Questions

Can I rename a field instead of deleting it?

The wire survives, but the JSON name and generated code change. Fix json_name, or treat the rename as a warning and agree on it with the team.

Can reserved be lifted later?

It is not recommended. If another field takes the number, old data quietly mixes in. Write a new field with a new number instead.

What about moving between proto2 and proto3?

The syntax change is a warning, but required, default and the enum zero rule change with it, so read the per-field diagnostics too.

The breaking-v1v2 preset shows a package change, type and label changes, a renumbering, and removed message, enum and rpc at once.

Open the tool

Written against the Protobuf language guide (proto2 and proto3) and the Protobuf encoding documentation. Every schema, byte string and name here is synthetic.