修改bug

This commit is contained in:
liuxiaobo 2025-05-29 16:58:50 +08:00
parent b06327602c
commit e5f3086cfd
2 changed files with 22 additions and 1 deletions

View File

@ -37,6 +37,7 @@ func (h *Processor) RegisterMessage(cmd int32, msg, delegate any) {
func (h *Processor) UnregisterMessage(cmd int32) { func (h *Processor) UnregisterMessage(cmd int32) {
delete(h.types, cmd) delete(h.types, cmd)
delete(h.delegates, cmd)
} }
func (h *Processor) GetMessageType(cmd int32) reflect.Type { func (h *Processor) GetMessageType(cmd int32) reflect.Type {

View File

@ -9,7 +9,7 @@ import (
func onChat(userId int64, req *pb.InternalMsg) { func onChat(userId int64, req *pb.InternalMsg) {
_ = userId _ = userId
fmt.Println("onChat", string(req.Msg)) fmt.Println("onChat.", string(req.Msg))
} }
func TestProcessor(t *testing.T) { func TestProcessor(t *testing.T) {
@ -26,3 +26,23 @@ func TestProcessor(t *testing.T) {
t.Error(err) t.Error(err)
} }
} }
func registerMessage(p *Processor, cmd int32, msg any, cb any) {
p.RegisterMessage(cmd, msg, cb)
}
func TestProcessorAny(t *testing.T) {
p := NewProcessor()
p.RegisterMessages(RegisterMetas{
pb.MsgId_Internal: {pb.InternalMsg{}, onChat},
})
registerMessage(p, int32(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)
}
}