Commit 050d839d authored by Bobby Powers's avatar Bobby Powers Committed by Rob Pike

gob: register more slice types

Without explicitly registering slice types, gob fails to encode
map[string]interface{} instances where the value is a slice,
failing with a message such as:

  gob: type not registered for interface: []string

Fixes #2065.

R=golang-dev, gri, r
CC=golang-dev
https://golang.org/cl/4672056
parent d360e021
......@@ -549,3 +549,32 @@ func TestMapBug1(t *testing.T) {
t.Errorf("mismatch: %v %v", in, out)
}
}
func TestGobMapInterfaceEncode(t *testing.T) {
m := map[string]interface{}{
"up": uintptr(0),
"i0": []int{-1},
"i1": []int8{-1},
"i2": []int16{-1},
"i3": []int32{-1},
"i4": []int64{-1},
"u0": []uint{1},
"u1": []uint8{1},
"u2": []uint16{1},
"u3": []uint32{1},
"u4": []uint64{1},
"f0": []float32{1},
"f1": []float64{1},
"c0": []complex64{complex(2, -2)},
"c1": []complex128{complex(2, float64(-2))},
"us": []uintptr{0},
"bo": []bool{false},
"st": []string{"s"},
}
buf := bytes.NewBuffer(nil)
enc := NewEncoder(buf)
err := enc.Encode(m)
if err != nil {
t.Errorf("gob.Encode map: %s", err)
}
}
......@@ -762,7 +762,25 @@ func registerBasics() {
Register(float64(0))
Register(complex64(0i))
Register(complex128(0i))
Register(uintptr(0))
Register(false)
Register("")
Register([]byte(nil))
Register([]int(nil))
Register([]int8(nil))
Register([]int16(nil))
Register([]int32(nil))
Register([]int64(nil))
Register([]uint(nil))
Register([]uint8(nil))
Register([]uint16(nil))
Register([]uint32(nil))
Register([]uint64(nil))
Register([]float32(nil))
Register([]float64(nil))
Register([]complex64(nil))
Register([]complex128(nil))
Register([]uintptr(nil))
Register([]bool(nil))
Register([]string(nil))
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment