企业🤖AI智能体构建引擎,智能编排和调试,一键部署,支持私有化部署方案 广告
[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} } ```