Here you go: https://play.golang.org/p/_cPmaSxRatC
You want to unmarshal into &A, not into &Duck This means: var duck2 A not: var duck2 Duck On Wed, Aug 14, 2019 at 8:46 AM Jochen Voss <jochen.v...@gmail.com> wrote: > Hello, > > I'm trying to read gob-encoded data into a variable of interface type. In > simple cases, this works for me, but when I use a custom encoding > via MarshalBinary() and UnmarshalBinary() methods, my code keeps crashing, > with the error message > > panic: interface conversion: interface is nil, not > encoding.BinaryUnmarshaler > > Example: > > - The code at https://play.golang.org/p/y8nWNhObUwb, letting gob do the > en-/decoding works. > > - The very similar code at https://play.golang.org/p/-zS7QjEJg9x, which > uses MarshalBinary() and UnmarshalBinary() crashes with the panic shown > above. > > What am I doing wrong? > > [I asked the same question at > https://stackoverflow.com/questions/57485698/, with no answers so far] > > Many thanks, > Jochen > > -- > 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/b19c51bc-524c-4292-915b-fc00e9289052%40googlegroups.com > <https://groups.google.com/d/msgid/golang-nuts/b19c51bc-524c-4292-915b-fc00e9289052%40googlegroups.com?utm_medium=email&utm_source=footer> > . > -- 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/CA%2Bv29LuB5qtbqm_DRLuCpsNWaczGONBEesUNjFF0jZZxq9EkSQ%40mail.gmail.com.