feat: add support for optional fields at the end of tuple structs#109
Merged
feat: add support for optional fields at the end of tuple structs#109
Conversation
751ff3d to
1e57bba
Compare
Fields at the end of a tuple-encoded struct can be now marked as `cborgen:"optional"`. When thus marked: 1. These fields are not required when unmarshaling CBOR into this struct. Instead, they'll be initialized to their respective zero values. 2. These fields are still written out when marshaling into CBOR. Marking map-encoded struct fields as optional is legal but has no impact in practice as all map fields are optional. As before, tuple-encoded structs will not omit "omitempty" fields, even when optional.
1e57bba to
ebdc598
Compare
Stebalien
commented
Feb 27, 2025
rvagg
reviewed
Feb 28, 2025
Contributor
|
lgtm, simpler than I imagined it would end up being. Some form of documentation would be nice, I know there's not a lot in here but capturing what you said in your comment there next to the feature itself would be nice if you can; otherwise this is just another obscure function that only certainly people with the magic in their heads understand |
rvagg
reviewed
Feb 28, 2025
rvagg
reviewed
Feb 28, 2025
rvagg
reviewed
Feb 28, 2025
Co-authored-by: Rod Vagg <rod@vagg.org>
rvagg
approved these changes
Feb 28, 2025
This was referenced Mar 5, 2025
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.
Motivation: This makes it possible to add fields to structs while still being able to decode versions that don't include those fields.
Fields at the end of a tuple-encoded struct can be now marked as
cborgen:"optional". When thus marked:Marking map-encoded struct fields as optional is legal but has no impact in practice as all map fields are optional. As before, tuple-encoded structs will not omit "omitempty" fields, even when optional.