This commit is contained in:
azw 2023-11-01 14:18:25 +00:00
parent aaa22350f4
commit 4f322d3cbd

View File

@ -70,7 +70,12 @@ class PBTools {
use std::cell::RefCell; use std::cell::RefCell;
use crate::cs::cs_proto as cs; use crate::cs::cs_proto as cs;
//static mut handlers [2000]Option<CsNetMsgHandler> struct Handler {
msg_id: i32,
handler_id: i32,
}
static HANDLERS: Vec<Handler> = Vec::new();
/* /*
func GetNetMsgHandler(msgId uint16) Option<CsNetMsgHandler> { func GetNetMsgHandler(msgId uint16) Option<CsNetMsgHandler> {
@ -108,37 +113,33 @@ pub trait MsgHandler {`;
fn ${finalyName}(&self, _: &f9::MsgHdr, _: Rc::<RefCell::<cs::${item.name}>>) { fn ${finalyName}(&self, _: &f9::MsgHdr, _: Rc::<RefCell::<cs::${item.name}>>) {
panic!("not implement"); panic!("not implement");
}`; }
`;
} }
}); });
data += ` data += `
} }
`; `;
/*
data += ` data += `
func init() { pub fn registe_handlers() {
`; `;
this.csProtoPb.nested.cs.nestedArray.forEach( this.csProtoPb.nested.cs.nestedArray.forEach(
(item) => { (item) => {
if (item.name[0] == 'C' && if (item.name[0] == 'C' &&
item.name[1] == 'M') { item.name[1] == 'M') {
/*
data += ` data += `
handlers[int(CMMessageIdE__${item.name})] = &CsNetMsgHandler{ HANDLERS[int(CMMessageIdE__${item.name})] = &CsNetMsgHandler{
MsgId: int(CMMessageIdE__${item.name}), MsgId: int(CMMessageIdE__${item.name}),
ParseCb: func (data []byte) interface{} { Cb: func (hdr *f5.MsgHdr, handler MsgHandler) {
msg := &${item.name}{} handler.${item.name}(hdr, hdr.Msg.(*${item.name}))
proto.Unmarshal(data, msg) },
return msg };
}, `;*/
Cb: func (hdr *f5.MsgHdr, handler MsgHandler) {
handler.${item.name}(hdr, hdr.Msg.(*${item.name}))
},
}
`;
} }
}); });
data += ` data += `
}`;*/ }`;
fs.writeFileSync('./src/cs/cs_auto_gen.rs', data); fs.writeFileSync('./src/cs/cs_auto_gen.rs', data);
} }