buffa-build: path-scoped preserve_unknown_fields_in - #395
Conversation
Fixes anthropics#281. preserve_unknown_fields is currently all-or-nothing. Builds that disable it globally for the 24-byte Vec header then lose round-trip fidelity on the handful of types that still get re-encoded. Path-prefix rules (same matching as unbox_oneof_in) now overlay the global default; last match wins. Nested messages resolve independently.
|
All contributors have signed the CLA ✍️ ✅ |
|
I have read the CLA Document and I hereby sign the CLA |
|
recheck |
|
[claude code] The shape is right: one resolver (
Smaller, at your discretion: hoist the resolved value into a local in Pre-existing but easier to hit with this knob: With 0.9.2 close, this will most likely ride the next patch unless the above lands quickly; the |
sylvesterkaczmarek
left a comment
There was a problem hiding this comment.
preserve_unknown_fields_in(".pkg.Outer") also matches .pkg.Outer.Inner because this uses proto-prefix matching, so nested messages are not actually independent as documented. Please distinguish package-prefix matching from exact message-FQN matching and add an outer-enabled/inner-disabled regression test.
Fixes #281.
What this does
preserve_unknown_fields(bool)is all-or-nothing. Disabling it is a legitimate memory optimization (drops the 24-byteUnknownFieldsVec header from every message), but it also silently removes round-trip fidelity on the handful of types that still get re-encoded, forwarded, or persisted.This adds path-scoped overlays on top of the global default, following the existing
_inconvention (bytes_type_in,unbox_oneof_in):matches_proto_prefix(message FQNs and package prefixes). Last matching rule wins.__buffa_unknown_fields.protoc-gen-buffagets the matching repeatable optionunknown_fields_in=<path>.Public
_inis enable-only (same asunbox_oneof_in). Internally the rule list isVec<(String, bool)>so last-match can mix polarities in tests.Testing
All passed. Targeted extras:
preserve_unknown_fields_*inbuffa-codegen,inline_preserve_unknown_fields_in_*incodegen_integration,preserve_unknown_fields_in_normalizes_leading_dotinbuffa-build, andunknown_fields_in_*inprotoc-gen-buffa.Conformance (
task conformance) was not run locally; this change does not alter the default-on codec path the suite exercises.