[go-nuts] Re: decode unknown CBOR type with set of known types

2020-07-10 Thread David Stainton
Hi, I've been informed of how exactly to use the CBOR tag solution by the author of one of the cbor.io recommended CBOR libraries: https://github.com/fxamacker/cbor/issues/241#issuecomment-656881180 This solution is clearly a bit nicer than the wrapping struct solution but it's specific to

[go-nuts] Re: decode unknown CBOR type with set of known types

2020-07-09 Thread David Stainton
Hi Jonathan, Thanks for the suggestion. I'm going to take this approach of using a wrapping struct like in your example. Although it might be possible to solve this problem with CBOR tags this seems more difficult and possibly not supported by the existing go CBOR libraries. Cheers, David

[go-nuts] Re: decode unknown CBOR type with set of known types

2020-07-09 Thread Brian Candler
By "unknown type", do you mean you want to unmarshal this CBOR map into a struct? You need some way of identifying what the data is semantically, otherwise it might unmarshal successfully into multiple different structs. I believe the CBOR native way of doing this is with "tags":

[go-nuts] Re: decode unknown CBOR type with set of known types

2020-07-08 Thread Jonathan Amsterdam
My first question would be, is the type encoded into the CBOR blob somehow? Like by a tag? If structs are encoded as maps, with no type information, then the input doesn't have enough information to do what you want. How could the blob (using JSON notation) {"X": 1, "Y": 2} know whether