This commit is contained in:
aozhiwei 2023-08-10 19:56:55 +08:00
parent 29680246f5
commit 94a82c4e1f

View File

@ -2,12 +2,9 @@ package cs
import (
"q5"
proto "github.com/golang/protobuf/proto"
)
func ParsePb(msgId int, data []byte) interface{} {
return nil
}
type MsgHandler interface {
CMPing(*q5.MsgHdr, *CMPing)
CMLogin(*q5.MsgHdr, *CMLogin)
@ -20,9 +17,12 @@ type MsgHandlerImpl struct {
type NetMsgHandler struct {
MsgId int
HandlerId int
parseCb func([]byte) interface{}
cb func(*q5.MsgHdr, MsgHandler)
}
var handlers [2000]*NetMsgHandler
func (this *MsgHandlerImpl) CMPing(hdr *q5.MsgHdr, msg *CMPing) {
}
@ -33,9 +33,30 @@ func (this *MsgHandlerImpl) CMReconnect(hdr *q5.MsgHdr, msg *CMReconnect) {
}
func GetNetMsgHandler(msgId int) *NetMsgHandler {
return nil
handler := handlers[msgId]
return handler
}
func DispatchMsg(handler *NetMsgHandler, hdr *q5.MsgHdr, msgHandler MsgHandler) {
handler.cb(hdr, msgHandler)
}
func ParsePb(msgId int, data []byte) interface{} {
handler := handlers[msgId]
return handler.parseCb(data)
}
func init() {
handlers[10] = &NetMsgHandler{
MsgId: int(CMMessageIdE__CMPing),
parseCb: func (data []byte) interface{} {
msg := &CMLogin{}
proto.Unmarshal(data, msg)
return msg
},
cb: func (hdr *q5.MsgHdr, handler MsgHandler) {
handler.CMPing(hdr, hdr.Msg.(*CMPing))
},
};
}