- Notifications
You must be signed in to change notification settings - Fork18.4k
Closed
Labels
Milestone
Description
In Go 1.2, encoding/gob respects the new encoding.TextMarshaler andencoding.TextUnmarshaler methods, and net.IP adds those methods.Unfortunately, this means that the gob encoding of a net.IP changes from Go 1.1 to Go1.2. That by itself might be okay: I don't believe people expect that Go 1.1 will beable to read Go 1.2 gobs.However, gob is also a bit picky about the decoding: if the type has a TextUnmarshaler,gob expects to get the TextMarshaler version of the encoding and does not accept anencoding of the underlying data. A Go 1.1 gob encoding of a net.IP will send the gob encoding of a standard []byte. Go1.2 gob will refuse to decode that form.The only other type we have added a MarshalText or MarshalBinary method to is time.Time.But time.Time already had a GobEncode and GobDecode methods, so its behavior with gobdoes not change. It appears that net.IP is the only affected type in the standardlibrary.Possibilities:1. Do nothing; allow Go 1.1 and Go 1.2 to be mutually unintelligible in gob when thereis a net.IP involved.2. Change gob to accept the concrete data representation during decode, so that Go 1.1can talk to Go 1.2 but not vice versa.3. Change gob to ignore MarshalText/UnmarshalText, allowing onlyMarshalBinary/UnmarshalBinary.4. Remove net.IP's MarshalText/UnmarshalText methods, breaking encoding/json's supportfor net.IP (new in Go 1.2).5. Replace net.IP's MarshalText/UnmarshalText methods with MarshalJSON/UnmarshalJSON, sothat we keep encoding/json working well for Go 1.2. (Of course, the new generic methodswere designed explicitly to avoid making package net mention JSON, so it is a bit of ashame not to use them.)I am leaning toward 5, which seems like the most limited change.Rob, what do you think?