package processor import ( "fmt" "github.com/golang/protobuf/proto" "testing" ) func onChat(userId int64, req *InternalMsg) { _ = userId fmt.Println("onChat", string(req.Msg)) } func TestProcessor(t *testing.T) { p := NewProcessor() p.RegisterMessages(RegisterMetas{ MsgId_Internal: {InternalMsg{}, onChat}, }) tmp := &InternalMsg{UserId: 1, ConnId: 1, MsgId: int32(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 { t.Error(err) } }