From 815ca4d336e254a4869946343460afc8ff6b21c7 Mon Sep 17 00:00:00 2001 From: Ian Lance Taylor Date: Wed, 27 Nov 2013 01:05:38 +0000 Subject: libgo: Update to current Go library. From-SVN: r205426 --- libgo/go/encoding/gob/doc.go | 12 ++++++------ libgo/go/encoding/gob/gobencdec_test.go | 15 +++++++++++++++ libgo/go/encoding/gob/type.go | 15 +++++++++++---- libgo/go/encoding/xml/read.go | 2 +- 4 files changed, 33 insertions(+), 11 deletions(-) (limited to 'libgo/go/encoding') diff --git a/libgo/go/encoding/gob/doc.go b/libgo/go/encoding/gob/doc.go index 28f0c05..d0acaba 100644 --- a/libgo/go/encoding/gob/doc.go +++ b/libgo/go/encoding/gob/doc.go @@ -86,13 +86,13 @@ Functions and channels will not be sent in a gob. Attempting to encode such a va at top the level will fail. A struct field of chan or func type is treated exactly like an unexported field and is ignored. -Gob can encode a value of any type implementing the GobEncoder, -encoding.BinaryMarshaler, or encoding.TextMarshaler interfaces by calling the -corresponding method, in that order of preference. +Gob can encode a value of any type implementing the GobEncoder or +encoding.BinaryMarshaler interfaces by calling the corresponding method, +in that order of preference. -Gob can decode a value of any type implementing the GobDecoder, -encoding.BinaryUnmarshaler, or encoding.TextUnmarshaler interfaces by calling -the corresponding method, again in that order of preference. +Gob can decode a value of any type implementing the GobDecoder or +encoding.BinaryUnmarshaler interfaces by calling the corresponding method, +again in that order of preference. Encoding Details diff --git a/libgo/go/encoding/gob/gobencdec_test.go b/libgo/go/encoding/gob/gobencdec_test.go index 301551d..0193e2b 100644 --- a/libgo/go/encoding/gob/gobencdec_test.go +++ b/libgo/go/encoding/gob/gobencdec_test.go @@ -11,6 +11,7 @@ import ( "errors" "fmt" "io" + "net" "strings" "testing" "time" @@ -767,3 +768,17 @@ func TestGobEncodePtrError(t *testing.T) { t.Fatalf("expected nil, got %v", err2) } } + +func TestNetIP(t *testing.T) { + // Encoding of net.IP{1,2,3,4} in Go 1.1. + enc := []byte{0x07, 0x0a, 0x00, 0x04, 0x01, 0x02, 0x03, 0x04} + + var ip net.IP + err := NewDecoder(bytes.NewReader(enc)).Decode(&ip) + if err != nil { + t.Fatalf("decode: %v", err) + } + if ip.String() != "1.2.3.4" { + t.Errorf("decoded to %v, want 1.2.3.4", ip.String()) + } +} diff --git a/libgo/go/encoding/gob/type.go b/libgo/go/encoding/gob/type.go index 65bf17b..cad1452 100644 --- a/libgo/go/encoding/gob/type.go +++ b/libgo/go/encoding/gob/type.go @@ -88,18 +88,25 @@ func validUserType(rt reflect.Type) (ut *userTypeInfo, err error) { ut.externalEnc, ut.encIndir = xGob, indir } else if ok, indir := implementsInterface(ut.user, binaryMarshalerInterfaceType); ok { ut.externalEnc, ut.encIndir = xBinary, indir - } else if ok, indir := implementsInterface(ut.user, textMarshalerInterfaceType); ok { - ut.externalEnc, ut.encIndir = xText, indir } + // NOTE(rsc): Would like to allow MarshalText here, but results in incompatibility + // with older encodings for net.IP. See golang.org/issue/6760. + // } else if ok, indir := implementsInterface(ut.user, textMarshalerInterfaceType); ok { + // ut.externalEnc, ut.encIndir = xText, indir + // } + if ok, indir := implementsInterface(ut.user, gobDecoderInterfaceType); ok { ut.externalDec, ut.decIndir = xGob, indir } else if ok, indir := implementsInterface(ut.user, binaryUnmarshalerInterfaceType); ok { ut.externalDec, ut.decIndir = xBinary, indir - } else if ok, indir := implementsInterface(ut.user, textUnmarshalerInterfaceType); ok { - ut.externalDec, ut.decIndir = xText, indir } + // See note above. + // } else if ok, indir := implementsInterface(ut.user, textUnmarshalerInterfaceType); ok { + // ut.externalDec, ut.decIndir = xText, indir + // } + userTypeCache[rt] = ut return } diff --git a/libgo/go/encoding/xml/read.go b/libgo/go/encoding/xml/read.go index da7ad3b..8890508 100644 --- a/libgo/go/encoding/xml/read.go +++ b/libgo/go/encoding/xml/read.go @@ -53,7 +53,7 @@ import ( // Unmarshal records the attribute value in that field. // // * If the XML element contains character data, that data is -// accumulated in the first struct field that has tag "chardata". +// accumulated in the first struct field that has tag ",chardata". // The struct field may have type []byte or string. // If there is no such field, the character data is discarded. // -- cgit v1.1