123 lines
3.3 KiB
Go
123 lines
3.3 KiB
Go
package cs
|
|
|
|
import (
|
|
"f5"
|
|
proto "github.com/golang/protobuf/proto"
|
|
)
|
|
|
|
type MsgHandlerImpl struct {
|
|
}
|
|
|
|
type NetMsgHandler struct {
|
|
MsgId int
|
|
HandlerId int
|
|
parseCb func([]byte) interface{}
|
|
cb func(*f5.MsgHdr, MsgHandler)
|
|
}
|
|
|
|
var handlers [2000]*NetMsgHandler
|
|
|
|
func GetNetMsgHandler(msgId uint16) *NetMsgHandler {
|
|
handler := handlers[msgId]
|
|
return handler
|
|
}
|
|
|
|
func DispatchMsg(handler *NetMsgHandler, hdr *f5.MsgHdr, msgHandler MsgHandler) {
|
|
handler.cb(hdr, msgHandler)
|
|
}
|
|
|
|
func RegHandlerId(msgId int, handlerId int) {
|
|
handler := handlers[msgId]
|
|
handler.HandlerId = handlerId
|
|
}
|
|
|
|
func ParsePb(msgId uint16, data []byte) interface{} {
|
|
handler := handlers[msgId]
|
|
if handler == nil {
|
|
return nil
|
|
}
|
|
return handler.parseCb(data)
|
|
}
|
|
|
|
type MsgHandler interface {
|
|
CMPing(*f5.MsgHdr, *CMPing)
|
|
CMLogin(*f5.MsgHdr, *CMLogin)
|
|
CMReconnect(*f5.MsgHdr, *CMReconnect)
|
|
}
|
|
|
|
func (this *MsgHandlerImpl) CMPing(hdr *f5.MsgHdr, msg *CMPing) {
|
|
}
|
|
|
|
func (this *MsgHandlerImpl) CMLogin(hdr *f5.MsgHdr, msg *CMLogin) {
|
|
}
|
|
|
|
func (this *MsgHandlerImpl) CMReconnect(hdr *f5.MsgHdr, msg *CMReconnect) {
|
|
}
|
|
|
|
func (this *CMPing) GetNetMsgId() uint16 {
|
|
return uint16(CMMessageIdE__CMPing)
|
|
}
|
|
|
|
func (this *SMPing) GetNetMsgId() uint16 {
|
|
return uint16(SMMessageIdE__SMPing)
|
|
}
|
|
|
|
func (this *SMRpcError) GetNetMsgId() uint16 {
|
|
return uint16(SMMessageIdE__SMRpcError)
|
|
}
|
|
|
|
func (this *CMLogin) GetNetMsgId() uint16 {
|
|
return uint16(CMMessageIdE__CMLogin)
|
|
}
|
|
|
|
func (this *SMLogin) GetNetMsgId() uint16 {
|
|
return uint16(SMMessageIdE__SMLogin)
|
|
}
|
|
|
|
func (this *CMReconnect) GetNetMsgId() uint16 {
|
|
return uint16(CMMessageIdE__CMReconnect)
|
|
}
|
|
|
|
func (this *SMReconnect) GetNetMsgId() uint16 {
|
|
return uint16(SMMessageIdE__SMReconnect)
|
|
}
|
|
|
|
func init() {
|
|
|
|
handlers[int(CMMessageIdE__CMPing)] = &NetMsgHandler{
|
|
MsgId: int(CMMessageIdE__CMPing),
|
|
parseCb: func (data []byte) interface{} {
|
|
msg := &CMPing{}
|
|
proto.Unmarshal(data, msg)
|
|
return msg
|
|
},
|
|
cb: func (hdr *f5.MsgHdr, handler MsgHandler) {
|
|
handler.CMPing(hdr, hdr.Msg.(*CMPing))
|
|
},
|
|
}
|
|
|
|
handlers[int(CMMessageIdE__CMLogin)] = &NetMsgHandler{
|
|
MsgId: int(CMMessageIdE__CMLogin),
|
|
parseCb: func (data []byte) interface{} {
|
|
msg := &CMLogin{}
|
|
proto.Unmarshal(data, msg)
|
|
return msg
|
|
},
|
|
cb: func (hdr *f5.MsgHdr, handler MsgHandler) {
|
|
handler.CMLogin(hdr, hdr.Msg.(*CMLogin))
|
|
},
|
|
}
|
|
|
|
handlers[int(CMMessageIdE__CMReconnect)] = &NetMsgHandler{
|
|
MsgId: int(CMMessageIdE__CMReconnect),
|
|
parseCb: func (data []byte) interface{} {
|
|
msg := &CMReconnect{}
|
|
proto.Unmarshal(data, msg)
|
|
return msg
|
|
},
|
|
cb: func (hdr *f5.MsgHdr, handler MsgHandler) {
|
|
handler.CMReconnect(hdr, hdr.Msg.(*CMReconnect))
|
|
},
|
|
}
|
|
|
|
} |