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 it should decode into
type Point struct { X, Y int}
or
type Chromosome {X, Y int}
?
You have to encode the type somehow. If you control the encoding process and you're encoding a fixed set of types that you want to distinguish at decode time,
you can do something like this:
type (
This ...
That ...
TheOther ...
Thing struct {
This *This
That *That
TheOther *TheOther
}
)
To encode a `This` named `t`, actually encode `Thing{This: &t}`. When you decode that into a `Thing`, only the `This` field will be non-nil, so you know you've got a `This`.
(Disclaimer: I know this technique works with the encoding/json package; I can't guarantee it works with the cbor package you're using because I'm not familiar with it,
but if it behaves like encoding/json, you should be OK.)