[go-nuts] Re: encoding/gob decode []byte to multi struct types

2017-01-18 Thread caspian46
Thanks for you reply, I got it done: https://play.golang.org/p/oOEELLyaVv This is how I did it, pass *interface{} to gob.Encode, not interface{} the same with gob.Decode, then get the type info from the decoded value interface{} 在 2017年1月18日星期三 UTC+8下午10:51:51,Jordan Krage写道: > > Actually,

[go-nuts] Re: encoding/gob decode []byte to multi struct types

2017-01-18 Thread Jordan Krage
Actually, it looks like the int/int8 distinction doesn't matter for gob. > There is no int8, int16 etc. discrimination in the gob format; there are > only signed and unsigned integers. > https://golang.org/pkg/encoding/gob/ On Wednesday, January 18, 2017 at 8:43:27 AM UTC-6, Jordan Krage

[go-nuts] Re: encoding/gob decode []byte to multi struct types

2017-01-17 Thread caspian46
First thanks for you reply. Because in fact, I have about more than 10 different struct types (maybe more and more), your suggest is good, this is better type Info struct{ typeStr string // store the type info to decode IData IData interface{} } But I don't like to send the typeInfo

[go-nuts] Re: encoding/gob decode []byte to multi struct types

2017-01-17 Thread Felipe Spinolo
Why not just create a wrapper struct? Something like: type Mixed struct{ A *A B *B } And then just encode/decode that? On Tuesday, January 17, 2017 at 1:16:37 PM UTC-8, casp...@gmail.com wrote: > > I got two struct types encoded into bytes by gob, I want to decode the > bytes into a