diff --git a/src/core/proto/NapProto.ts b/src/core/proto/NapProto.ts index 68d06f15..f44a1b4e 100644 --- a/src/core/proto/NapProto.ts +++ b/src/core/proto/NapProto.ts @@ -64,7 +64,7 @@ export function ProtoField(no: number, type: ScalarType | (() => ProtoMessageTyp type ProtoFieldReturnType = NonNullable extends ScalarProtoFieldType ? ScalarTypeToTsType : T extends NonNullable> - ? NonNullable, E>> + ? NonNullable, E>> : never; type RequiredFieldsBaseType = { @@ -85,14 +85,18 @@ type RequiredFieldsType = E extends true ? type OptionalFieldsType = E extends true ? Partial> : OptionalFieldsBaseType; -type ProtoStructType = RequiredFieldsType & OptionalFieldsType; +type NapProtoStructType = RequiredFieldsType & OptionalFieldsType; -const NapProtoMsgCache = new Map>>(); +export type NapProtoEncodeStructType = NapProtoStructType; + +export type NapProtoDecodeStructType = NapProtoStructType; + +const NapProtoMsgCache = new Map>>(); export class NapProtoMsg { private readonly _msg: T; private readonly _field: PartialFieldInfo[]; - private readonly _proto_msg: MessageType>; + private readonly _proto_msg: MessageType>; constructor(fields: T) { this._msg = fields; @@ -127,14 +131,14 @@ export class NapProtoMsg { }; } }) as PartialFieldInfo[]; - this._proto_msg = new MessageType>('nya', this._field); + this._proto_msg = new MessageType>('nya', this._field); } - encode(data: ProtoStructType): Uint8Array { - return this._proto_msg.toBinary(this._proto_msg.create(data as PartialMessage>)); + encode(data: NapProtoEncodeStructType): Uint8Array { + return this._proto_msg.toBinary(this._proto_msg.create(data as PartialMessage>)); } - decode(data: Uint8Array): ProtoStructType { - return this._proto_msg.fromBinary(data) as ProtoStructType; + decode(data: Uint8Array): NapProtoDecodeStructType { + return this._proto_msg.fromBinary(data) as NapProtoDecodeStructType; } }