添加消息分发器
This commit is contained in:
parent
c7d29893fe
commit
92d0dcef62
@ -4,7 +4,7 @@
|
||||
// protoc v6.31.0
|
||||
// source: internal.proto
|
||||
|
||||
package processor
|
||||
package pb
|
||||
|
||||
import (
|
||||
protoreflect "google.golang.org/protobuf/reflect/protoreflect"
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user