我正按建议in this example进行地图的基本序列化和反序列化。但是我收到以下错误:
SELECT
[Measures].[Assessment Patients Detail] ON COLUMNS,
NON EMPTY
Generate(
[DimPatient].[Patient Key].[Patient Key].MEMBERS
,[DimPatient].[Patient Key].CURRENTMEMBER
*TAIL(
NonEmpty(
[DimDate].[Full Date Alternate Key].[Full Date Alternate Key].MEMBERS
,[DimPatient].[Patient Key].CURRENTMEMBER
)
,1
)
ON ROWS
FROM
[Care];
任何人都可以在下面的代码中告诉我我做错了什么:
panic: EOF
goroutine 1 [running]:
main.load(0x81147e0, 0x1840a378)
/home/naresh/Desktop/Work/GoEventHandler/test.go:39 +0x2cf
main.main()
/home/naresh/Desktop/Work/GoEventHandler/test.go:16 +0xe5
exit status 2
答案 0 :(得分:4)
解码是一个需要编码信息的过程,该信息将在用于编码的缓冲区中。将其传递给解码器。
package main
import (
"bytes"
"encoding/gob"
"fmt"
)
func main() {
org := map[string]string{"hello": "world"}
buf := store(org)
loadedMap := make(map[string]string)
load(&loadedMap, buf)
fmt.Println(loadedMap)
}
func store(data interface{}) *bytes.Buffer {
m := new(bytes.Buffer)
enc := gob.NewEncoder(m)
err := enc.Encode(data)
if err != nil {
panic(err)
}
return m
}
func load(e interface{}, buf *bytes.Buffer) {
dec := gob.NewDecoder(buf)
err := dec.Decode(e)
if err != nil {
panic(err)
}
}