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