我需要使用gob
对一些数据进行编码,但是,我发现无法正确处理“type nil”(转到 1.6.2)
https://play.golang.org/p/faypK8uobF
package main
import (
"bytes"
"encoding/gob"
"log"
)
type T struct {
A int
}
func init() {
gob.Register(map[string]interface{}{})
gob.Register(new(T))
}
func main() {
bys := bytes.NewBuffer(nil)
gob.NewEncoder(bys).Encode(map[string]interface{}{
"v": (*T)(nil),
})
out := map[string]interface{}{}
if err := gob.NewDecoder(bys).Decode(&out); err != nil {
log.Panic(err)
}
return
}
输出:
panic: EOF