Follow the Sync Protocol Style for Protobufs
mainWhen defining or modifying protobufs within the Sync Protocol, adhere to these core guidelines to ensure consistency and compatibility:
General Rules
- Use proto2 syntax.
- Follow the Protocol Buffers Style Guide.
- Maintain local consistency.
Naming and Formatting
- Enums: Entries must be in
ALL_CAPS. The first entry should always be an unspecified value:FOO_UNSPECIFIED = 0. - Timestamps: Must specify epoch and unit in the suffix using the format
_[unix|windows]_epoch_[seconds|millis|micros|nanos].- Example:
creation_time_unix_epoch_millis.
- Example:
- Durations: Must specify the unit as a suffix, e.g.,
_[minutes|seconds|millis|...].
Compatibility and Evolution
- Avoid Version Numbers: Do not use explicit version numbers in protobufs. Instead, write code that tests for the existence of a field to determine logic.
- Backwards Compatibility: All changes must be fully backwards-compatible. Sync supports clients that may be several years old.
- Field Renaming: Renaming a field within a specifics message is generally safe. Never rename fields outside of specifics.
- Field Repurposing: Do not repurpose existing fields. Add a new field for new data and deprecate the old one.
- Adding Fields: New fields are unrecognized by older clients and pose a risk of data loss during commits by older clients. Ensure data types follow Protection against data override by old Sync clients.