Greetings,

Similar questions have been asked in the past and I've read those posts... 
and I believe I'm asking something different here.

I'm using length prefixed CBOR over unix domain socket as my wire format. 
However the reader doesn't known which CBOR type it needs to decode.
I'd like a mechanism similar to the golang switch type assertion where a 
known set of types are specified.

Before you go and tell me to use the empty interface let me explain that 
certainly this works:

// "github.com/fxamacker/cbor"
var v interface{}
err = cbor.Unmarshal(out, &v)

It works for some definitions of "works". It doesn't tell me what type it 
is but it does allow me to access each struct field by name in the map of 
type: map[interface {}]interface {}

The reason this is not good enough is that it doesn't concretely tell me 
the type!
Of course I could go ahead and add a struct field called TypeName and set 
it's value to a string encoding the name. But that feels wrong and I'd feel 
bad after writing it.

I've also tried to ask this question on a ticket here:
https://github.com/fxamacker/cbor/issues/241

Is the least incorrect solution to iteratively try cbor.Unmarshal with all 
the types in the known set of possible types until one of them works?

Certainly this problem isn't specific to CBOR. Am I asking the question 
incorrectly here?


Sincerely,
David

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/f48f6955-0478-4adf-a775-268a480dfdbfo%40googlegroups.com.

Reply via email to