1
This commit is contained in:
parent
b6841bc20f
commit
06d7487868
@ -74,7 +74,7 @@ use crate::cs::cs_msgid as cs_msgid;
|
||||
pub struct Handler {
|
||||
msg_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();
|
||||
@ -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 {
|
||||
if (msg_id as usize) < HANDLERS.len() {
|
||||
match &mut HANDLERS[msg_id as usize] {
|
||||
@ -104,11 +104,23 @@ pub fn reg_handler_id(msg_id: u16, handler_id: i32){
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
func DispatchMsg(handler *CsNetMsgHandler, hdr *f5.MsgHdr, msgHandler MsgHandler) {
|
||||
handler.Cb(hdr, msgHandler)
|
||||
pub fn dispatch_msg(msg_id: u16, hdr: &f9::MsgHdr, h: &dyn MsgHandler) {
|
||||
let mut handler: &Option<Handler> = &None;
|
||||
unsafe {
|
||||
handler = get_net_msg_handler(msg_id);
|
||||
}
|
||||
match handler {
|
||||
Some(v) => {
|
||||
(*v.cb)(hdr, h);
|
||||
}
|
||||
None => {
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
func ParsePb(msgId uint16, data []byte) interface{} {
|
||||
handler := handlers[msgId]
|
||||
if handler == nil {
|
||||
|
Loading…
x
Reference in New Issue
Block a user