Skip to content

feat(proto)!: keep unknown fields on every message - #70

Merged
jonasz-lasut merged 1 commit into
mainfrom
feat/unknown-fields-every-message
Nov 19, 2026
Merged

jonasz-lasut merged 1 commit into
mainfrom
feat/unknown-fields-every-message

Conversation

@jonasz-lasut

Copy link
Copy Markdown
Collaborator

All 16 messages of the function API now keep the fields their proto doesn't know, as State and Resource have since 0.5.0. Codegen replaces prost's Message derive: prost-build still writes each struct, and codegen/src/messages.rs adds unknown_fields and writes the impls the derive would have written, with the fallback arm keeping the bytes. Codegen generates State and Resource again, which removes sdk/src/proto/state.rs. A proto update doesn't need hand edits unless it uses a field kind the pass doesn't write yet, and then codegen fails with the field's name.

This is breaking for every message in the way 0.5.0 was for two: a struct literal or a pattern that lists every field needs ..Default::default() or .., and Debug output includes unknown_fields. It needs 0.6.0.

Codegen also writes the messages as prost derives them to sdk/tests/generated/prost_v1.rs, and sdk/tests/generated_messages.rs compares each message with that reference: the bytes, the verdict and error on malformed input, Debug, the defaults and the accessors. A map decoded without its wire-type check and a wrong default for an enumeration, each put into the pass on purpose, failed those tests. codegen-drift covers the reference file too.

Fixes #69

0.5.0 keeps unknown fields on State and Resource alone. Every field
Crossplane has added since the function API went v1 is on another
message, where prost still discards it, so a function that forwards a
request or returns a response it did not build loses such a field.
protobuf-go keeps unknown fields on every message.

Codegen now replaces prost's Message derive. prost-build writes every
struct as before, and codegen/src/messages.rs gives each one an
unknown_fields field and the impls the derive would have written: the
fallback arm of merge_field keeps a field's bytes and encode_raw writes
them back. It reads the field kinds the function proto uses from the
#[prost(...)] attributes and refuses one it does not know. State and
Resource are generated again, and sdk/src/proto/state.rs is gone.

Codegen also writes the messages as prost derives them to
sdk/tests/generated/prost_v1.rs. sdk/tests/generated_messages.rs holds
every message to that reference: the same bytes, the same verdict and
error on malformed input, the same Debug, defaults and accessors. The
codegen-drift check covers the new file.

BREAKING CHANGE: every message has a new public unknown_fields field.
Struct literals and patterns that list every field of a message no
longer compile; add ..Default::default() or `..`. The Debug output of
every message includes unknown_fields.

Fixes #69

Signed-off-by: Jonasz Małecki <[email protected]>
@jonasz-lasut
jonasz-lasut marked this pull request as ready for review November 19, 2026 10:54
@jonasz-lasut
jonasz-lasut merged commit 01a4e59 into main Nov 19, 2026
5 checks passed
@jonasz-lasut
jonasz-lasut deleted the feat/unknown-fields-every-message branch November 19, 2026 10:57
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.

Keep unknown protobuf fields on every message

1 participant