This commit is contained in:
azw 2023-11-01 13:12:57 +00:00
parent 1e6e6aafae
commit e698f97dbe

View File

@ -65,23 +65,20 @@ class PBTools {
} }
async genCsAutoGen() { async genCsAutoGen() {
let data = ` let data =
use std::rc::{Rc, Weak}; `use std::rc::{Rc, Weak};
use std::cell::RefCell; use std::cell::RefCell;
pub type CsNetMsgHandler = f9.NetMsgHandler<MsgHandler>; //static mut handlers [2000]Option<CsNetMsgHandler>
pub struct MsgHandlerImpl {
}
static mut handlers [2000]Option<CsNetMsgHandler>
/*
func GetNetMsgHandler(msgId uint16) Option<CsNetMsgHandler> { func GetNetMsgHandler(msgId uint16) Option<CsNetMsgHandler> {
// handler := handlers[msgId] // handler := handlers[msgId]
// return handler // return handler
return None return None
} }*/
/*
func DispatchMsg(handler *CsNetMsgHandler, hdr *f5.MsgHdr, msgHandler MsgHandler) { func DispatchMsg(handler *CsNetMsgHandler, hdr *f5.MsgHdr, msgHandler MsgHandler) {
handler.Cb(hdr, msgHandler) handler.Cb(hdr, msgHandler)
} }
@ -97,49 +94,24 @@ func ParsePb(msgId uint16, data []byte) interface{} {
return nil return nil
} }
return handler.ParseCb(data) return handler.ParseCb(data)
} }*/
`; `;
data += ` data += `
type MsgHandler interface {`; pub trait MsgHandler {`;
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 += `
${item.name}(*f5.MsgHdr, *${item.name})`;
${item.name}(&self, _: &f9.MsgHdr, _: Rc::<RefCell::${item.name}>>) {
panic!("not implement");
}`;
} }
}); });
data += ` data += `
} }
`; `;
this.csProtoPb.nested.cs.nestedArray.forEach(
(item) => {
if (item.name[0] == 'C' &&
item.name[1] == 'M') {
data += `
func (this *MsgHandlerImpl) ${item.name}(hdr *f5.MsgHdr, msg *${item.name}) {
}
`;
}
});
this.csProtoPb.nested.cs.nestedArray.forEach(
(item) => {
if (item.name[0] == 'C' &&
item.name[1] == 'M') {
data += `
func (this *${item.name}) GetNetMsgId() uint16 {
return uint16(CMMessageIdE__${item.name})
}
`;
} else if (item.name[0] == 'S' &&
item.name[1] == 'M') {
data += `
func (this *${item.name}) GetNetMsgId() uint16 {
return uint16(SMMessageIdE__${item.name})
}
`;
}
});
data += ` data += `
func init() { func init() {
`; `;
@ -164,7 +136,7 @@ func init() {
}); });
data += ` data += `
}`; }`;
//fs.writeFileSync('./src/cs_auto_gen.rs', data); fs.writeFileSync('./src/cs/cs_auto_gen.rs', data);
} }
async genSsAutoGen() { async genSsAutoGen() {