|| at Jan 6, 2016 at 6:33 pm
Ah, I hadn't thought of that. Thanks!
In general that behavior is a good thing, but in the specific case of
gob.Encode it seems like it'd *always* be wrong. Is there some type assert
that gob.Encode or time.GobEncode could do that could keep it from
happening? That is, it seems like time.GobEncode should be able to realize
that it's being asked to encode something that's not a time.Time and panic
appropriately, or something.
Or maybe it's not always wrong, I dunno.
Anyway, thanks again!
On Wednesday, January 6, 2016 at 1:16:11 PM UTC-5, mb0 wrote:
when embedding time.Time you will also promote its custom methods
GobDecode and GobEncode to your types P and Q. if you then try to
encode and decode using gob the package will see that your types
implement the GobDecoder and GobEncoder interface and only call those.
that is why the name fields seems to be ignored.
the easy solution is not to embed a time.Time or otherwise implement
the encoding and encoding/gob interfaces to encode and decode your
types on your own instead of calling the implementation of time.Time.
hope that helps
On Di, 2016-01-05 at 21:29 -0800, Larry Clapp wrote:
This works: http://play.golang.org/p/nUENUMDM7x
time.Time field is called T
So far so good.
This doesn't seem to work: http://play.golang.org/p/tooXqJ5Eio
time.Time field is anonymous
This panics with a nill dereference: http://play.golang.org/p/kGoY9QA
*time.Time field is anonymous (note: pointer to time.Time)
panic: runtime error: invalid memory address or nil pointer
Am I doing something wrong?
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 email@example.com.
For more options, visit https://groups.google.com/d/optout.