1 Star 0 Fork 0

jack/protoactor-go

加入 Gitee
与超过 1400万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
serializer.go 1.45 KB
一键复制 编辑 原始数据 按行查看 历史
490689386@qq.com 提交于 2025-05-19 14:50 +08:00 . 初始化
package remote
var (
DefaultSerializerID int32
serializers []Serializer
)
func init() {
RegisterSerializer(newProtoSerializer())
RegisterSerializer(newJsonSerializer())
}
func RegisterSerializer(serializer Serializer) {
serializers = append(serializers, serializer)
}
type Serializer interface {
Serialize(msg interface{}) ([]byte, error)
Deserialize(typeName string, bytes []byte) (interface{}, error)
GetTypeName(msg interface{}) (string, error)
}
func Serialize(message interface{}, serializerID int32) ([]byte, string, error) {
res, err := serializers[serializerID].Serialize(message)
if err != nil {
return nil, "", err
}
typeName, err := serializers[serializerID].GetTypeName(message)
if err != nil {
return nil, "", err
}
return res, typeName, nil
}
func Deserialize(message []byte, typeName string, serializerID int32) (interface{}, error) {
return serializers[serializerID].Deserialize(typeName, message)
}
// RootSerializable is the root level in-process representation of a message
type RootSerializable interface {
// Serialize returns the on-the-wire representation of the message
// Message -> IRootSerialized -> ByteString
Serialize() (RootSerialized, error)
}
// RootSerialized is the root level on-the-wire representation of a message
type RootSerialized interface {
// Deserialize returns the in-process representation of a message
// ByteString -> IRootSerialized -> Message
Deserialize() (RootSerializable, error)
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/wujianhai/protoactor-go.git
git@gitee.com:wujianhai/protoactor-go.git
wujianhai
protoactor-go
protoactor-go
5633fe2499dd

搜索帮助