Description
CBOR defines a self-describing tag which can be added to any item in a CBOR stream. It has no semantic meaning on the content:
It does not impart any
special semantics on the data item that follows; that is, the
semantics of a data item tagged with tag 55799 is exactly identical
to the semantics of the data item itself.
I therefore want to be able to decode some CBOR, but silently strip all 55799 tags as I encounter them.
TagSet.Add(TagOptions, reflect.Type, int)
seems like the right place to try to do this, except that a) I don't want to add 55799 tags when I encode, and b) I want to be able to strip a 55799 tag in any location, on any item encoding any type. But this method only lets me register a tag for a specific named type, not for all types.
Is it possible to a) achieve this using existing fxamacker/cbor features? or b) allow fxamacker/cbor to (optionally) silently strip all 55799 tags when decoding?
(For context, my use case is implementing a Dhall library; it has defined CBOR semantics here, including the possibility of tag 55799 appearing anywhere.)
(See also this similar issue in another library: ugorji/go#300)
Activity
fxamacker commentedon May 7, 2020
@philandstuff thanks for opening this issue!
Yes. And I'm also going to make it automatic in the next release.
There's no need to register tags to handle 55799.
BTW, this library can use separate tag registrations (different TagSet) for encoding and decoding.
Details
There are two CBOR decoding scenarios for tag 55799:
A. ✔️ decode to user-specified Go type
B. ℹ️ decode to empty interface (interface{})
"A" already ignores tag 55799 for you because unrecognized tag numbers are ignored and the tag content is decoded to the user-specified Go type.
"B" currently decodes each unrecognized tag item to a
cbor.Tag
struct, which contains tag number and tag content. For now, you can manually discard the tag number and keep the tag content fromcbor.Tag
.I'm going to open a bug report to ignore tag 55799 when decoding to empty struct. Once that bug is fixed, "B" should handle 55799 automatically for you with no extra step required.
Please let me know if this works for you.
philandstuff commentedon May 9, 2020
Yes that would work great for me 👍
fxamacker commentedon May 11, 2020
@philandstuff commit 28e39be handles tag number 55799 by skipping it when it is a prefix.
https://play.golang.com/p/Fd0IbCQO_bL
Although this isn't an official release, commit 28e39be has passed fuzzing since yesterday (220 million execs and counting).
Please let me know if there is a problem.
philandstuff commentedon May 12, 2020
works a treat! 👍
support self-describing CBOR again
support self-describing CBOR again (#37)