-
Notifications
You must be signed in to change notification settings - Fork 59
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
Use cases of UnmarshalFirst? #483
Comments
Hi @MastaP 👋 This library supports both CBOR (RFC 8949) and CBOR Sequences (RFC 8742). A CBOR Sequence is simply a concatenation of zero or more CBOR data items.
Use-cases for
For your use-case, you can encode to a CBOR Sequence:
At a glance, your code snippet looks like it is using CBOR Sequence. Both
Actually, this library supports all CBOR data items as top-level data item, such as CBOR integers, bool, array, map, etc. For your use-case, these RFCs may be of interest: |
Thanks a lot for the comprehensive reply, @fxamacker . |
Hello,
I'm new to CBOR and trying to wrap my head around the functionality that UnmarshalFirst() provides.
The documentation says:
It seems that with this lib, the top-level data item is always a CBOR array or a map. Thus, UnmarshalFirst() always returns the whole item, that is, array or a map with all contents.
The only way I was able to utilize UnmarshalFirst() was to create a malformed CBOR by concatenating two (or more) encoded structures into a single byte array.
Is it possible to construct wellformed CBOR encoding and be able to iterate multiple data items from the top level?
Thanks.
p.s. in my use-case I'd like to version my data structures and be able to use UnmarshalFirst() to first read the version and then decode the rest of the payload accordingly.
The text was updated successfully, but these errors were encountered: