I have a struct with unexported fields which should be gob encoded and decoded.
Say:
type A struct {
s int
}
func (a *A) Inc() {
a.s++
}
Obviously in that case I need to implement gob.GobEncoder
and gob.GobDecoder
interfaces. And if I use the struct directly everything works fine:
https://play.golang.org/p/dm3HwaI8eU
But I also need to have an interface that implements same logic and is serializable:
type Incer interface {
gob.GobEncoder
gob.GobDecoder
Inc()
}
Full code: https://play.golang.org/p/Zig2mPrnrq
And suddenly it panics:
panic: interface conversion: interface is nil, not gob.GobDecoder [recovered]
panic: interface conversion: interface is nil, not gob.GobDecoder
But if I comment gob interfaces out everything become fine again.
Am I missing something important? Cos the described behavior seems quite strange to me
encoding.BinaryUnmarshaler
interface is part of the interface (panic: interface conversion: interface is nil, not encoding.BinaryUnmarshaler
). – Giguere