Turns out that the decoding problem only exist when I reuse the encoder: b := new(bytes.Buffer) enc := gob.NewEncoder(b)
for param := range in { b.Reset() if err := enc.Encode(¶m.Val); err != nil { panic(err) } // send encoded data } When I create a new encode inside the loop things are fine. I couldn't find anything regarding enc that should prevent reusing it? Cheers, Andi On Sunday, November 28, 2021 at 9:10:37 PM UTC+1 cpu...@gmail.com wrote: > I'm trying to transfer arbitrary structs over gRPC. To achieve this I've > trying to use gob for encoding the interface{} part of the structs. The > code looks somewhat like https://go.dev/play/p/4Q5CQE4Wcy2 but not > entirely. > > Two things strike me strange: > - I receive "gob: decoding into local type []float64, received remote type > []float" during Decode when the interface is a []float64 > - I need to use &res.Val (which is an interface) or it will stay nil. > Using res.Val (which imho works with JSON when the target is an interface) > does always lead to nil result. > > I would appreciate any hint how to gRPC or gob.Encode interfaces properly. > > Cheers, > Andi > > -- 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/589e4ba5-afe4-4cee-9398-326478171492n%40googlegroups.com.