1 Star 0 Fork 0

Ling_Boogie/mahjong-helper

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
helper.go 875 Bytes
一键复制 编辑 原始数据 按行查看 历史
18520664652 提交于 2021-12-31 10:06 +08:00 . qwq
package api
import (
"gitee.com/ling_boogie/mahjong-helper/platform/majsoul/proto/lq"
"github.com/golang/protobuf/proto"
)
func WrapMessage(name string, message proto.Message) (data []byte, err error) {
data, err = proto.Marshal(message)
if err != nil {
return
}
wrap := lq.Wrapper{
Name: name,
Data: data,
}
return proto.Marshal(&wrap)
}
func UnwrapData(rawData []byte) (methodName string, data []byte, err error) {
wrapper := lq.Wrapper{}
if err = proto.Unmarshal(rawData, &wrapper); err != nil {
return
}
return wrapper.GetName(), wrapper.GetData(), nil
}
// TODO: auto UnwrapMessage by methodName
func UnwrapMessage(rawData []byte, message proto.Message) error {
methodName, data, err := UnwrapData(rawData)
if err != nil {
return err
}
// TODO: assert methodName when its not empty
_ = methodName
return proto.Unmarshal(data, message)
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/ling_boogie/mahjong-helper.git
git@gitee.com:ling_boogie/mahjong-helper.git
ling_boogie
mahjong-helper
mahjong-helper
v0.1.0

搜索帮助