This commit is contained in:
azw 2023-11-02 01:08:25 +00:00
parent b6841bc20f
commit 06d7487868

View File

@ -74,7 +74,7 @@ use crate::cs::cs_msgid as cs_msgid;
pub struct Handler { pub struct Handler {
msg_id: i32, msg_id: i32,
handler_id: i32, handler_id: i32,
cb: Box::<dyn FnMut (&f9::MsgHdr, &dyn MsgHandler)>, cb: Box::<dyn Fn (&f9::MsgHdr, &dyn MsgHandler)>,
} }
static mut HANDLERS: Vec<Option<Handler>> = Vec::new(); static mut HANDLERS: Vec<Option<Handler>> = Vec::new();
@ -89,7 +89,7 @@ pub fn get_net_msg_handler(msg_id: u16) -> &'static Option<Handler> {
} }
} }
pub fn reg_handler_id(msg_id: u16, handler_id: i32){ pub fn reg_handler_id(msg_id: u16, handler_id: i32) {
unsafe { unsafe {
if (msg_id as usize) < HANDLERS.len() { if (msg_id as usize) < HANDLERS.len() {
match &mut HANDLERS[msg_id as usize] { match &mut HANDLERS[msg_id as usize] {
@ -104,11 +104,23 @@ pub fn reg_handler_id(msg_id: u16, handler_id: i32){
} }
} }
/* pub fn dispatch_msg(msg_id: u16, hdr: &f9::MsgHdr, h: &dyn MsgHandler) {
func DispatchMsg(handler *CsNetMsgHandler, hdr *f5.MsgHdr, msgHandler MsgHandler) { let mut handler: &Option<Handler> = &None;
handler.Cb(hdr, msgHandler) unsafe {
handler = get_net_msg_handler(msg_id);
}
match handler {
Some(v) => {
(*v.cb)(hdr, h);
}
None => {
}
}
} }
/*
func ParsePb(msgId uint16, data []byte) interface{} { func ParsePb(msgId uint16, data []byte) interface{} {
handler := handlers[msgId] handler := handlers[msgId]
if handler == nil { if handler == nil {