-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adds .default support to typenames (`foo = bar .default baz`) and to map fields (`foo = { ? 1 => bar .default baz }`). This is not applied into nested contexts e.g.: ``` foo = uint .default 2 bar = { * str => foo } ``` as how this should be handled is extremely ambiguous. Should this result in an extra encoding variable which is a map e.g. `default_included: BTreeSet<K>` and having the behavior be to omit it if it's not included in this encoding var and it's equal to the default ? As per the CDDL RFC we only apply it to optional fields: ``` This control is only meaningful when the control type is used in an optional context; otherwise, there would be no way to make use of the default value. ``` We support encoding preservation for round-tripping i.e. if a default value is explicitly present it will remain explicitly present. With `preserve-encodings=false` it will be omitted if the value present is equal to the default value. No changes were done with canonical encodings as the RFC doesn't seem to mention how that should be handled as canonical encodings are specified in the CBOR RFC not the CDDL one, and `.default` is only present in the CDDL one. It's that possible we could omit fields equal to the default if needed but we need to confirm this first. Optional fields with `.default` are no longer encoded as `Option<T>` but instead just `T` now which should help with usability. The field will default to the default via `new()` and deserialization. Fixes #42
- Loading branch information
1 parent
cff2577
commit a995bad
Showing
7 changed files
with
261 additions
and
76 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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