Repository navigation
Conversation
|
All contributors have signed the CLA ✍️ ✅ |
The owned struct of a message whose proto2 `required` or editions `LEGACY_REQUIRED` field declares `[default = X]` gets a hand-written `Default` that starts the field at X, so `Message::decode` of input without the field returns X. The eager and lazy views derived `Default` unless an enum-type override opened a required enum, so the same field held the type's zero value. For one input the view, its re-encoding and `to_owned_message()` then disagreed with `Message::decode`: with `required int32 count = 1 [default = 42]` and an empty buffer, owned decode gave 42 and `decode_view(..).to_owned_message()` gave 0. `custom_view_default_impl` now initializes these fields from their declared default, under the same gate the owned `Default` uses. Strings and bytes get a `'static` literal because view fields borrow; every other type reuses `parse_default_value`. The opened-enum path is unchanged.
v0ropaev
force-pushed
the
fix/view-required-default
branch
from
October 28, 2026 12:24
d49378b to
5d44450
Compare
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
When a proto2
requiredfield (or an editionsLEGACY_REQUIREDone) declares[default = X], the owned struct gets a hand-writtenDefaultthat starts the field at X, soMessage::decodeof input without the field gives X back. The eager and lazy views derivedDefaultinstead, unless an enum-type override had opened a required enum, so the same field held the type's zero value. For the same bytes the view, its re-encoding andto_owned_message()then disagreed with owned decode. With the existingRequiredDefaultsfixture:C++ after
ParsePartialand Go after anAllowPartialunmarshal also return the declared default from their getters.custom_view_default_implnow fills these fields from their declared default, under the same gate the ownedDefaultuses (explicit presence on the message, or an opened enum). View strings and bytes borrow, so they get a'staticliteral, and a string thatstrict_utf8_mappingturned into bytes keeps its text as UTF-8. Every other type reusesparse_default_value, and the opened-enum path is unchanged. The lazy view picks this up through the same function.The new tests check the view values for an empty buffer and a partial one, and check that
to_owned_message()and the view's own encoding match owned decode. They coverRequiredDefaults,RequiredBytesDefaultswith its nested message in the three bytes configurations,KeywordEnumDefaulton the lazy view, and the editionsLEGACY_REQUIREDfixture in utf8_validation.proto. Checked-in generated code doesn't change.