Permalink
Browse files

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
  • Loading branch information...
bpowers authored and robpike committed Jul 13, 2011
1 parent d360e02 commit 050d839df01f0f7ba5bd59ebea54e5fa5f5caba6
Showing with 47 additions and 0 deletions.
  1. +29 −0 src/pkg/gob/encoder_test.go
  2. +18 −0 src/pkg/gob/type.go
@@ -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)
}
}
View
@@ -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))
}

0 comments on commit 050d839

Please sign in to comment.