我需要但使用gob
編碼一些數據,我發現「類型的無」不能正確處理(去1.6.2)採空區嘗試解碼在EOF誤差零值結果
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
非常感謝你,很好的詳細信息。 – llx