I encountered this tricky bug today. After going through all the playground
examples, I finally understood what was happening.
Similar to Jochen, I was including encoding.MarshalBinary() and
encoding.UnmarshalBinary() in the interface definition.
A question though. Why does this bug resolve by
Hi Axel,
Thanks a lot for looking into this. Your post makes things much clearer
for me. In particular, I now think that I probably should not have
(Un)MarshalBinary() methods on the interface type, but have them only on
the concrete type instead. For example, this
works:
via golang-nuts
> Sent: Aug 15, 2019 3:12 AM
> To: Jochen Voss
> Cc: golang-nuts
> Subject: Re: [go-nuts] panic: interface conversion: interface is nil, not
> encoding.BinaryUnmarshaler
>
> I haven't really used gob much, so unfortunately I can't *really* help
> you. But
Hm, I looked a bit at the code. ISTM that if you implement
BinaryMarshaler/Unmarshaler (or GobEncoder/Decoder), the values are sent as
a []byte, not an interface, so the concrete type information is lost. You
can kind of circumvent this, by instead passing the values as interface{}:
On Thu, Aug 15, 2019 at 11:14 AM Jochen Voss wrote:
> You are right. But the type is somehow represented by some index or so,
> instead of the name? Since the type needs to be registered using
> gob.Register() beforehand, this seems not totally impossible to me.
>
`Register` only gets the
Hi Axel,
On Thursday, 15 August 2019 09:13:17 UTC+1, Axel Wagner wrote:
>
> I haven't really used gob much, so unfortunately I can't *really* help
> you. But one thing to note is that you can dump the content of the buffer
> and see that it doesn't actually contain the name of the type you are
I haven't really used gob much, so unfortunately I can't *really* help you.
But one thing to note is that you can dump the content of the buffer and
see that it doesn't actually contain the name of the type you are encoding:
https://play.golang.org/p/R8HB6RP8kS0
I agree that from the
Dear Marcin,
My aim is to unmarshal into an interface variable, without having to know
in advance which concrete type I'm receiving (the actual interface has
several possible implementations, and gob data comes in over a network
connection). So, while your code avoids the panic, it does not
Here you go:
https://play.golang.org/p/_cPmaSxRatC
You want to unmarshal into , not into
This means:
var duck2 A
not:
var duck2 Duck
On Wed, Aug 14, 2019 at 8:46 AM Jochen Voss wrote:
> Hello,
>
> I'm trying to read gob-encoded data into a variable of interface type. In
> simple cases,