-
Notifications
You must be signed in to change notification settings - Fork 61
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
feature: Shorthand encmode/decode functions for predefined encoding options #214
Comments
I should note I'm happy to submit a PR for this if accepted. |
@e3b0c442 thanks for opening this issue. It escalated quickly from 1 simple func to a full CTAP2 interface providing encoding & decoding funcs. 🤣
More than 1 call to If you write a func that is called more than once, that func should reuse a mode rather than call EncMode() itself.
A CTAP2 interface requires more time & effort than what you initially proposed, so I think @fxamacker will code it (if approved). It would involve both encoding and decoding. DetailsSeparation of options and modes allows sanity checks and translation into different data structures (to speed up encoding or decoding) so that overhead shouldn't be repeated. Ideally, mode(s) should be created during startup and preferably before init() runs. Any helper functions requiring modes would simply reuse the modes created during startup. I agree the API should make CTAP2 easier. CTAP2 is special case. In part because other predefined options are typically starting points for modification. @fxamacker please consider exporting a CTAP2 interface that provides these:
CTAP2 Canonical CBOR should be reviewed to make sure decoding (not just encoding) is in compliance with any extra limitations imposed by CTAP2. Use io.LimitReader, etc. if needed. |
Would it though? The OP-proposed Whether or not the extra globals are warranted is an open question. This could also be handled with a |
Is your feature request related to a problem? Please describe.
Seeing a bunch of
em, _ := cbor.CTAP2EncOptions().EncMode()
is a bit of a code smell (at least to me)Describe the solution you'd like
Given that these predefined options would ostensibly never error, provide similar predefined encoding/decoding modes that can be used inline à la
json.NewEncoder(blah)...
.Example:
cbor.CTAP2EncMode().Marshal(&obj)
Describe alternatives you've considered
Additional context
n/a, this is just a suggested API improvement
The text was updated successfully, but these errors were encountered: