1 Star 2 Fork 0

李文建/light-protoactor-go

加入 Gitee
与超过 1400万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
serializer.go 923 Bytes
一键复制 编辑 原始数据 按行查看 历史
李文建 提交于 2017-07-18 10:01 +08:00 . 调整log
package remote
import (
"reflect"
"os"
"github.com/gogo/protobuf/proto"
)
func serialize(message proto.Message) ([]byte, string, error) {
typeName := proto.MessageName(message)
ensureGoGo(typeName)
bytes, err := proto.Marshal(message)
if err != nil {
return nil, "", err
}
return bytes, typeName, nil
}
func deserialize(message *MessageEnvelope, typeName string) proto.Message {
ensureGoGo(typeName)
t1 := proto.MessageType(typeName)
if t1 == nil {
logger.Error("Unknown message type=[%v]", typeName)
os.Exit(1)
}
t := t1.Elem()
intPtr := reflect.New(t)
instance := intPtr.Interface().(proto.Message)
proto.Unmarshal(message.MessageData, instance)
return instance
}
func ensureGoGo(typeName string) {
if typeName == "" {
logger.Error("Message type name is empty string, make sure you have generated the Proto contacts with GOGO Proto: github.com/gogo/protobuf/proto")
os.Exit(1)
}
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Go
1
https://gitee.com/lwj8507/light-protoactor-go.git
git@gitee.com:lwj8507/light-protoactor-go.git
lwj8507
light-protoactor-go
light-protoactor-go
013e33d7022f

搜索帮助