1 Star 0 Fork 0

Eriloan / goutils

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
gob.go 543 Bytes
一键复制 编辑 原始数据 按行查看 历史
Eriloan 提交于 2022-03-23 18:05 . 修改依赖库引用
package gob
import (
"bytes"
"encoding/gob"
)
//Register 注册Gob类型
func Register(o ...interface{}) {
for _, v := range o {
gob.Register(v)
}
mapGob := make(map[string]interface{})
gob.Register(mapGob)
}
//Marshal 编码
func Marshal(v interface{}) ([]byte, error) {
b := new(bytes.Buffer)
err := gob.NewEncoder(b).Encode(v)
if err != nil {
return nil, err
}
return b.Bytes(), nil
}
//Unmarshal 解码
func Unmarshal(data []byte, v interface{}) error {
b := bytes.NewBuffer(data)
return gob.NewDecoder(b).Decode(v)
}
Go
1
https://gitee.com/shibingli/goutils.git
git@gitee.com:shibingli/goutils.git
shibingli
goutils
goutils
v1.2.5

搜索帮助