添加消息分发器

This commit is contained in:
liuxiaobo 2025-05-27 00:23:46 +08:00
parent c7d29893fe
commit 92d0dcef62
2 changed files with 7 additions and 6 deletions

View File

@ -4,7 +4,7 @@
// protoc v6.31.0
// source: internal.proto
package processor
package pb
import (
protoreflect "google.golang.org/protobuf/reflect/protoreflect"

View File

@ -2,11 +2,12 @@ package processor
import (
"fmt"
"github.com/fox/fox/processor/pb"
"github.com/golang/protobuf/proto"
"testing"
)
func onChat(userId int64, req *InternalMsg) {
func onChat(userId int64, req *pb.InternalMsg) {
_ = userId
fmt.Println("onChat", string(req.Msg))
}
@ -14,14 +15,14 @@ func onChat(userId int64, req *InternalMsg) {
func TestProcessor(t *testing.T) {
p := NewProcessor()
p.RegisterMessages(RegisterMetas{
MsgId_Internal: {InternalMsg{}, onChat},
pb.MsgId_Internal: {pb.InternalMsg{}, onChat},
})
tmp := &InternalMsg{UserId: 1, ConnId: 1, MsgId: int32(MsgId_Internal), Msg: []byte("hello world")}
tmp := &pb.InternalMsg{UserId: 1, ConnId: 1, MsgId: int32(pb.MsgId_Internal), Msg: []byte("hello world")}
data, _ := proto.Marshal(tmp)
req, _ := p.Unmarshal(int32(MsgId_Internal), data)
if err := p.Dispatch(int32(MsgId_Internal), int64(1), req); err != nil {
req, _ := p.Unmarshal(int32(pb.MsgId_Internal), data)
if err := p.Dispatch(int32(pb.MsgId_Internal), int64(1), req); err != nil {
t.Error(err)
}
}