fix: deprecate the cache in constructor in NapProtoMsg

This commit is contained in:
pk5ls20 2024-10-14 01:07:14 +08:00
parent 095f1c270b
commit 9304430889
No known key found for this signature in database
GPG Key ID: 6370ED7A169F493A

View File

@ -117,17 +117,12 @@ export class NapProtoMsg<T extends ProtoMessageType> {
repeat: repeatType, repeat: repeatType,
}; };
} else if (field.kind === 'message') { } else if (field.kind === 'message') {
const rt = NapProtoMsgCache.get(field.type()) ?? (() => {
const msg = new NapProtoMsg(field.type());
NapProtoMsgCache.set(field.type(), msg._proto_msg);
return msg._proto_msg;
})();
return { return {
no: field.no, no: field.no,
name: key, name: key,
kind: 'message', kind: 'message',
repeat: field.repeat ? RepeatType.PACKED : RepeatType.NO, repeat: field.repeat ? RepeatType.PACKED : RepeatType.NO,
T: () => rt, T: () => new NapProtoMsg(field.type())._proto_msg,
}; };
} }
}) as PartialFieldInfo[]; }) as PartialFieldInfo[];