This commit is contained in:
aozhiwei 2024-05-29 15:14:16 +08:00
parent 2ed86035d1
commit 3e568c6039

View File

@ -14,7 +14,11 @@ class PBTools {
this.protoDir = './proto/'; this.protoDir = './proto/';
} }
async init() { async loadCsPb() {
if (!fs.existsSync(this.protoDir + 'cs_proto.proto')) {
console.error('cs_proto.proto file not exists');
return;
}
{ {
this.csProtoPb = await (new protobuf.Root()).load( this.csProtoPb = await (new protobuf.Root()).load(
this.protoDir + 'cs_proto.proto', this.protoDir + 'cs_proto.proto',
@ -33,6 +37,13 @@ class PBTools {
this.csCmMsgId = this.csMsgIdPb.lookup('CMMessageId_e'); this.csCmMsgId = this.csMsgIdPb.lookup('CMMessageId_e');
this.csSmMsgId = this.csMsgIdPb.lookup('SMMessageId_e'); this.csSmMsgId = this.csMsgIdPb.lookup('SMMessageId_e');
} }
}
async loadSsPb() {
if (!fs.existsSync(this.protoDir + 'ss_proto.proto')) {
console.error('ss_proto.proto file not exists');
return;
}
{ {
this.ssProtoPb = await (new protobuf.Root()).load( this.ssProtoPb = await (new protobuf.Root()).load(
this.protoDir + 'ss_proto.proto', this.protoDir + 'ss_proto.proto',
@ -50,6 +61,13 @@ class PBTools {
); );
this.ssSSmMsgId = this.ssMsgIdPb.lookup('SSMMessageId_e'); this.ssSSmMsgId = this.ssMsgIdPb.lookup('SSMMessageId_e');
} }
}
async loadMtPb() {
if (!fs.existsSync(this.protoDir + 'mt.proto')) {
console.error('mt.proto file not exists');
return;
}
{ {
this.mtPb = await (new protobuf.Root()).load( this.mtPb = await (new protobuf.Root()).load(
this.protoDir + 'mt.proto', this.protoDir + 'mt.proto',
@ -58,9 +76,18 @@ class PBTools {
} }
); );
} }
await this.genCsAutoGen(); }
await this.genMtbAutoGen();
await this.genSsAutoGen(); async init() {
if (this.csProtoPb) {
await this.genCsAutoGen();
}
if (this.ssProtoPb) {
await this.genMtbAutoGen();
}
if (this.mtPb) {
await this.genSsAutoGen();
}
} }
async genCsAutoGen() { async genCsAutoGen() {