1
This commit is contained in:
parent
e93cb4df0c
commit
8b682ccb49
@ -60,7 +60,7 @@ class PBTools {
|
||||
}
|
||||
await this.genCsAutoGen();
|
||||
await this.genMtbAutoGen();
|
||||
//await this.genMtAutoGen();
|
||||
await this.genSsAutoGen();
|
||||
}
|
||||
|
||||
async genCsAutoGen() {
|
||||
@ -71,25 +71,20 @@ import (
|
||||
proto "github.com/golang/protobuf/proto"
|
||||
)
|
||||
|
||||
type CsNetMsgHandler f5.NetMsgHandler[MsgHandler];
|
||||
|
||||
type MsgHandlerImpl struct {
|
||||
}
|
||||
|
||||
type NetMsgHandler struct {
|
||||
MsgId int
|
||||
HandlerId int
|
||||
parseCb func([]byte) interface{}
|
||||
cb func(*f5.MsgHdr, MsgHandler)
|
||||
}
|
||||
var handlers [2000]*CsNetMsgHandler
|
||||
|
||||
var handlers [2000]*NetMsgHandler
|
||||
|
||||
func GetNetMsgHandler(msgId uint16) *NetMsgHandler {
|
||||
func GetNetMsgHandler(msgId uint16) *CsNetMsgHandler {
|
||||
handler := handlers[msgId]
|
||||
return handler
|
||||
}
|
||||
|
||||
func DispatchMsg(handler *NetMsgHandler, hdr *f5.MsgHdr, msgHandler MsgHandler) {
|
||||
handler.cb(hdr, msgHandler)
|
||||
func DispatchMsg(handler *CsNetMsgHandler, hdr *f5.MsgHdr, msgHandler MsgHandler) {
|
||||
handler.Cb(hdr, msgHandler)
|
||||
}
|
||||
|
||||
func RegHandlerId(msgId int, handlerId int) {
|
||||
@ -102,7 +97,7 @@ func ParsePb(msgId uint16, data []byte) interface{} {
|
||||
if handler == nil {
|
||||
return nil
|
||||
}
|
||||
return handler.parseCb(data)
|
||||
return handler.ParseCb(data)
|
||||
}
|
||||
`;
|
||||
data += `
|
||||
@ -154,14 +149,14 @@ func init() {
|
||||
if (item.name[0] == 'C' &&
|
||||
item.name[1] == 'M') {
|
||||
data += `
|
||||
handlers[int(CMMessageIdE__${item.name})] = &NetMsgHandler{
|
||||
handlers[int(CMMessageIdE__${item.name})] = &CsNetMsgHandler{
|
||||
MsgId: int(CMMessageIdE__${item.name}),
|
||||
parseCb: func (data []byte) interface{} {
|
||||
ParseCb: func (data []byte) interface{} {
|
||||
msg := &${item.name}{}
|
||||
proto.Unmarshal(data, msg)
|
||||
return msg
|
||||
},
|
||||
cb: func (hdr *f5.MsgHdr, handler MsgHandler) {
|
||||
Cb: func (hdr *f5.MsgHdr, handler MsgHandler) {
|
||||
handler.${item.name}(hdr, hdr.Msg.(*${item.name}))
|
||||
},
|
||||
}
|
||||
@ -173,6 +168,111 @@ func init() {
|
||||
fs.writeFileSync('./cs/cs.auto_gen.go', data);
|
||||
}
|
||||
|
||||
async genSsAutoGen() {
|
||||
let data = `package ss
|
||||
|
||||
import (
|
||||
"f5"
|
||||
proto "github.com/golang/protobuf/proto"
|
||||
)
|
||||
|
||||
type SsNetMsgHandler f5.NetMsgHandler[MsgHandler];
|
||||
|
||||
type MsgHandlerImpl struct {
|
||||
}
|
||||
|
||||
var handlers [2000]*SsNetMsgHandler
|
||||
|
||||
func GetNetMsgHandler(msgId uint16) *SsNetMsgHandler {
|
||||
handler := handlers[msgId]
|
||||
return handler
|
||||
}
|
||||
|
||||
func DispatchMsg(handler *SsNetMsgHandler, hdr *f5.MsgHdr, msgHandler MsgHandler) {
|
||||
handler.Cb(hdr, msgHandler)
|
||||
}
|
||||
|
||||
func RegHandlerId(msgId int, handlerId int) {
|
||||
handler := handlers[msgId]
|
||||
handler.HandlerId = handlerId
|
||||
}
|
||||
|
||||
func ParsePb(msgId uint16, data []byte) interface{} {
|
||||
handler := handlers[msgId]
|
||||
if handler == nil {
|
||||
return nil
|
||||
}
|
||||
return handler.ParseCb(data)
|
||||
}
|
||||
`;
|
||||
data += `
|
||||
type MsgHandler interface {`;
|
||||
this.ssProtoPb.nested.ss.nestedArray.forEach(
|
||||
(item) => {
|
||||
if (item.name[0] == 'C' &&
|
||||
item.name[1] == 'M') {
|
||||
data += `
|
||||
${item.name}(*f5.MsgHdr, *${item.name})`;
|
||||
}
|
||||
});
|
||||
data += `
|
||||
}
|
||||
`;
|
||||
this.ssProtoPb.nested.ss.nestedArray.forEach(
|
||||
(item) => {
|
||||
if (item.name[0] == 'S' &&
|
||||
item.name[1] == 'S') {
|
||||
data += `
|
||||
func (this *MsgHandlerImpl) ${item.name}(hdr *f5.MsgHdr, msg *${item.name}) {
|
||||
}
|
||||
`;
|
||||
}
|
||||
});
|
||||
this.ssProtoPb.nested.ss.nestedArray.forEach(
|
||||
(item) => {
|
||||
if (item.name[0] == 'S' &&
|
||||
item.name[1] == 'S') {
|
||||
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() {
|
||||
`;
|
||||
this.ssProtoPb.nested.ss.nestedArray.forEach(
|
||||
(item) => {
|
||||
if (item.name[0] == 'S' &&
|
||||
item.name[1] == 'S') {
|
||||
data += `
|
||||
handlers[int(SSMessageIdE__${item.name})] = &SsNetMsgHandler{
|
||||
MsgId: int(CMMessageIdE__${item.name}),
|
||||
ParseCb: func (data []byte) interface{} {
|
||||
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 += `
|
||||
}`;
|
||||
fs.writeFileSync('./ss/ss.auto_gen.go', data);
|
||||
}
|
||||
|
||||
async genMtbAutoGen() {
|
||||
let data = `package mtb
|
||||
|
||||
@ -242,65 +342,6 @@ func (this *${item.name}) LoadFromKv(kv map[string]interface{}) {
|
||||
fs.writeFileSync('./mtb/mtb.auto_gen.go', data);
|
||||
}
|
||||
|
||||
async genMtAutoGen() {
|
||||
let data = `package mt
|
||||
|
||||
`;
|
||||
this.mtPb.nested.mt.nestedArray.forEach(
|
||||
(item) => {
|
||||
data += `type ${item.name}RawTable struct {\n`;
|
||||
data += ` rawList []*${item.name}\n`;
|
||||
data += '}\n\n';
|
||||
data += `type ${item.name}IdTable struct {\n`;
|
||||
data += ` ${item.name}RawTable\n`;
|
||||
data += ` idHash map[int64]*${item.name}\n`;
|
||||
data += '}\n\n';
|
||||
data += `type ${item.name}AutoIdTable struct {\n`;
|
||||
data += ` ${item.name}RawTable\n`;
|
||||
data += ` idHash map[int64]*${item.name}\n`;
|
||||
data += '}\n\n';
|
||||
data += `type ${item.name}NameTable struct {\n`;
|
||||
data += ` ${item.name}RawTable\n`;
|
||||
data += ` nameHash map[string]*${item.name}\n`;
|
||||
data += '}\n\n';
|
||||
}
|
||||
);
|
||||
this.mtPb.nested.mt.nestedArray.forEach(
|
||||
(item) => {
|
||||
data += `func (this *${item.name}RawTable) Traverse(cb func (*${item.name}) bool) {\n`;
|
||||
data += ` for _, val := range this.rawList {\n`;
|
||||
data += ` if !cb(val) {\n`;
|
||||
data += ` break\n`;
|
||||
data += ` }\n`;
|
||||
data += ` }\n`;
|
||||
data += '}\n\n';
|
||||
data += `func (this *${item.name}IdTable) GetById(id int64) *${item.name} {\n`;
|
||||
data += ` if v, ok := this.idHash[id]; ok {\n`;
|
||||
data += ` return v\n`;
|
||||
data += ` } else {\n`;
|
||||
data += ` return nil\n`;
|
||||
data += ` }\n`;
|
||||
data += '}\n\n';
|
||||
data += `func (this *${item.name}AutoIdTable) GetById(id int64) *${item.name} {\n`;
|
||||
data += ` if v, ok := this.idHash[id]; ok {\n`;
|
||||
data += ` return v\n`;
|
||||
data += ` } else {\n`;
|
||||
data += ` return nil\n`;
|
||||
data += ` }\n`;
|
||||
data += '}\n\n';
|
||||
data += `func (this *${item.name}NameTable) GetByName(name string) *${item.name} {\n`;
|
||||
data += ` if v, ok := this.nameHash[name]; ok {\n`;
|
||||
data += ` return v\n`;
|
||||
data += ` } else {\n`;
|
||||
data += ` return nil\n`;
|
||||
data += ` }\n`;
|
||||
data += '}\n\n';
|
||||
}
|
||||
);
|
||||
data += '\n\n';
|
||||
fs.writeFileSync('./mt/mt.auto_gen.go', data);
|
||||
}
|
||||
|
||||
dumpClassField(cls, field, index) {
|
||||
const fieldName = field.name;
|
||||
switch (field.type) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user