Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace options struct and improve option handling #62

Closed
x448 opened this issue Dec 8, 2019 · 2 comments
Closed

Replace options struct and improve option handling #62

x448 opened this issue Dec 8, 2019 · 2 comments
Labels
enhancement New feature or request
Milestone

Comments

@x448
Copy link
Contributor

x448 commented Dec 8, 2019

It would be easier and cleaner to do this in v2.0 instead of v1.4 due to SemVer policy.

RFC 7049bis indicates additional considerations for encoding not mentioned in 7049, so future protocols are likely to use new encoding modes.

One way to handle options would be to use some integer "enums" to specify different aspects of encoding modes. So 6-7+ of these aspects can combine to specify any current or future mode. And each is an integer so they can have new values made available as needed.

Something like the following (with better names than this rough draft):

  1. Sorting: 0=default, unsorted; 1=RFC 7049 Canonical, 2=Bytewise Lexicographic, 3=reserved, ...
  2. SmallestFormFloats: 0=default, unchanged; 1=float16, 2=float32, 3=float64, 4=reserved, ...
  3. SmallestFormIntegers: 0=default, smallest form is byte; 1=reserved, ...
  4. DupMapKeys: 0=default, unchecked, last one used, continue; 1=reserved, ...
  5. Utf8Problems: 0=default, reject as malformed and stop; 1=reserved, ...

And one or more aspects for each of these:

  • Other error-handling options 7049bis requires protocols to specify (so they can use this library).
  • Tag options like whether or not to encode tag for time values.

So a combination of these options can handle all existing CBOR modes plus some future modes that don't exist yet.

@fxamacker fxamacker added the enhancement New feature or request label Dec 9, 2019
@fxamacker fxamacker added this to the v2.0.0 milestone Dec 9, 2019
@x448
Copy link
Contributor Author

x448 commented Dec 19, 2019

As discussed, maybe a v1.4 before 2.0 can have this baby step before merging in CBOR tags.

  1. deprecate but still support boolean encoding modes in v1.4
  2. add SortMode (int) and ShortestFloat (int) as encoding options to replace encoding mode booleans.

The combination of SortMode and ShortestFloat can be used to specify these modes in v1:

  • default
  • Canonical
  • CTAP2
  • Core Deterministic Encoding Rule 2 (7049bis)
  • and modes that don't have a name yet
type SortMode int

const (
	SortNone			SortMode = 0	// no sorting
	SortLengthFirst			SortMode = 1	// Old Canonical
	SortBytewiseLexical		SortMode = 2	// Bytewise Lexicographic
	SortCanonical			SortMode = SortLengthFirst
	SortCTAP2			SortMode = SortBytewiseLex	
	SortCoreDeterministic		SortMode = SortBytewiseLex
)
type ShortestFloat int

const (
	ShortestFloatNone		ShortestFloat = 0	// no change
	ShortestFloat16			ShortestFloat = 1	// float16 as shortest form of float that preserves value
	ShortestFloat32			ShortestFloat = 2	// float32 as shortest form of float that preserves value
	ShortestFloat64			ShortestFloat = 3	// float64 as shortest form of float (this may convert from float32 to float64, etc.)
)

@x448
Copy link
Contributor Author

x448 commented Jan 9, 2020

@fxamacker hey, I think this can be closed because of your commits today. nice work!

@x448 x448 closed this as completed Jan 9, 2020
@fxamacker fxamacker modified the milestones: v2.0.0, v1.5.0 Jan 13, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants