gob

最后更新于:2022-04-02 02:43:28

[TOC] ## 结构体与buf转换 ``` type Person struct { Name string Age int } func main() { var buf1 bytes.Buffer en := gob.NewEncoder(&buf1) en.Encode(Person{"idcpj1", 111}) en.Encode(Person{"idcpj2", 222}) var p1 Person var p2 Person de := gob.NewDecoder(&buf1) de.Decode(&p1) de.Decode(&p2) fmt.Printf("%+v\n", p1) // {Name:idcpj1 Age:111} fmt.Printf("%+v\n", p2) // {Name:idcpj2 Age:222} } ```
';