2 Star 1 Fork 1

mosache / YFrame

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
serializer.go 538 Bytes
一键复制 编辑 原始数据 按行查看 历史
ヤ沒脩袮兲︶ 提交于 2023-08-24 16:15 . temp
package proto
import (
"errors"
"google.golang.org/protobuf/proto"
)
type Serializer struct {
}
func (s Serializer) Code() uint8 {
return 2
}
func (s Serializer) Encode(val any) ([]byte, error) {
msg, ok := val.(proto.Message)
if !ok {
return nil, errors.New("[micro] must type of proto.Message")
}
return proto.Marshal(msg)
}
func (s Serializer) Decode(data []byte, val any) error {
msg, ok := val.(proto.Message)
if !ok {
return errors.New("[micro] must type of proto.Message")
}
return proto.Unmarshal(data, msg)
}
Go
1
https://gitee.com/mosache/YFrame.git
git@gitee.com:mosache/YFrame.git
mosache
YFrame
YFrame
v0.1.73

搜索帮助