Skip to content

Preserve stable Protobuf field tags and support field lifecycle management - #188

Open
stelund wants to merge 3 commits into
COVESA:masterfrom
stelund:protobuf-stable-tags
Open

Preserve stable Protobuf field tags and support field lifecycle management#188
stelund wants to merge 3 commits into
COVESA:masterfrom
stelund:protobuf-stable-tags

Conversation

@stelund

@stelund stelund commented Sep 10, 2026

Copy link
Copy Markdown

Preserve stable Protobuf field tags and support field lifecycle management

Summary

This PR makes IFEX-to-Protobuf generation safe for long-lived, wire-compatible
APIs.

It preserves field numbers when parsing and rendering .proto files, requires
explicit stable tags for IFEX-generated fields, and adds support for deprecated
and removed struct members.

Changes

  • Preserve regular and map-field numbers in the Protobuf AST and round-trip output.
  • Render actual Protobuf field numbers instead of the previous hard-coded = 0.
  • Add protobuf_tag to IFEX struct members and method input/output/return arguments.
  • Validate generated messages before rendering:
    • tags are required;
    • tags are unique per message;
    • tags must be within 1..536870911;
    • tags 19000..19999 are rejected. (Reserved by protobuf)
  • Prevent declaration order from assigning wire identifiers: inserting or reordering fields without explicit tags now fails generation.
  • Add protobuf_deprecated: true, emitted as [deprecated = true] while retaining the existing tag.
  • Add struct-level protobuf_reserved_tags and protobuf_reserved_names, emitted as valid Protobuf reserved statements.
  • Reject active struct members that conflict with a reserved tag or name.
  • Document the stable-tag, deprecation, and removal policy in the Protobuf mapping guide.

Example

structs:
  - name: VehicleStatus
    protobuf_reserved_tags: [2]
    protobuf_reserved_names: [legacy_state]
    members:
      - name: speed
        datatype: uint32
        protobuf_tag: 1
      - name: old_state
        datatype: string
        protobuf_tag: 3
        protobuf_deprecated: true

Generates:

message VehicleStatus {
  uint32 speed = 1;
  string old_state = 3 [deprecated = true];
  reserved 2;
  reserved "legacy_state";
}

Compatibility / migration impact

This intentionally makes missing protobuf_tag a generation error. Existing
IFEX definitions that generate Protobuf must add explicit tags before
generation. Tags must never be renumbered or reused after publication.

Validation

Tested with repository-local .venv on Python 3.12:

8 passed

Commits included:

  1. Preserve protobuf field numbers
  2. Require stable protobuf field tags
  3. Support deprecated and reserved protobuf fields

@stelund

stelund commented Sep 11, 2026

Copy link
Copy Markdown
Author

If this is the path for defining protobuf tags, I have some more improvements for better protobuf generations.

If someone has another idea how to describe it, I would be all ears.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant