Skip to content

Expose presence of explicit optional keyword on fields#69

Open
mwatson2 wants to merge 1 commit intomafintosh:masterfrom
mwatson2:explicit-optional
Open

Expose presence of explicit optional keyword on fields#69
mwatson2 wants to merge 1 commit intomafintosh:masterfrom
mwatson2:explicit-optional

Conversation

@mwatson2
Copy link

@mwatson2 mwatson2 commented May 11, 2022

Whilst all fields in proto3 are optional, in the sense that they can be omitted from the message serialization, the optional keyword still carries a meaning. For fields that are not explicitly marked optional then when the field is missing from a message this is considered equivalent to the field being present with default value. APIs need not distinguish these two cases. When fields are explicitly marked optional (or if they are in a oneof) then the field missing case is a separate case from present-with-default-value case.

It would therefore be useful to expose whether a field is explicitly marked as optional in the parsed data structure.

This PR adds a property optional in the field structure that, if present and true, indicates that the field was marked explicitly as optional, or inside a oneof.

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