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