style: NapProto

This commit is contained in:
手瓜一十雪 2024-10-12 21:35:49 +08:00
parent 938a84a460
commit a2c4498694

View File

@ -99,17 +99,18 @@ class NapProtoMsg<T extends ProtoMessageType> {
this._field = Object.keys(fields).map(key => { this._field = Object.keys(fields).map(key => {
const field = fields[key]; const field = fields[key];
if (field.kind === 'scalar') { if (field.kind === 'scalar') {
const repeatType = field.repeated
? [ScalarType.STRING, ScalarType.BYTES].includes(field.type)
? RepeatType.UNPACKED
: RepeatType.PACKED
: RepeatType.NO;
return { return {
no: field.no, no: field.no,
name: key, name: key,
kind: 'scalar', kind: 'scalar',
T: field.type, T: field.type,
opt: field.optional, opt: field.optional,
repeat: field.repeated repeat: repeatType,
? [ScalarType.STRING, ScalarType.BYTES].includes(field.type)
? RepeatType.UNPACKED
: RepeatType.PACKED
: RepeatType.NO,
}; };
} else if (field.kind === 'message') { } else if (field.kind === 'message') {
const rt = NapProtoMsgCache.get(field.type()) ?? (() => { const rt = NapProtoMsgCache.get(field.type()) ?? (() => {