mirror of
https://github.com/NapNeko/NapCatQQ.git
synced 2025-07-19 12:03:37 +00:00
style: NapProto
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
import {MessageType, RepeatType, ScalarType} from '@protobuf-ts/runtime';
|
||||
import {PartialFieldInfo} from "@protobuf-ts/runtime/build/types/reflection-info";
|
||||
import { MessageType, RepeatType, ScalarType } from '@protobuf-ts/runtime';
|
||||
import { PartialFieldInfo } from "@protobuf-ts/runtime/build/types/reflection-info";
|
||||
|
||||
type LowerCamelCase<S extends string> = CamelCaseHelper<S, false, true>;
|
||||
|
||||
@@ -55,9 +55,9 @@ function ProtoField<T extends ScalarType, O extends boolean = false, R extends O
|
||||
function ProtoField<T extends () => ProtoMessageType, O extends boolean = false, R extends O extends true ? false : boolean = false>(no: number, type: T, repeated?: R, optional?: O): MessageProtoFieldType<T, O, R>;
|
||||
function ProtoField(no: number, type: ScalarType | (() => ProtoMessageType), repeated?: boolean, optional?: boolean): ProtoFieldType {
|
||||
if (typeof type === 'function') {
|
||||
return {kind: 'message', no: no, type: type, repeated: repeated ?? false, optional: optional ?? false};
|
||||
return { kind: 'message', no: no, type: type, repeated: repeated ?? false, optional: optional ?? false };
|
||||
} else {
|
||||
return {kind: 'scalar', no: no, type: type, repeated: repeated ?? false, optional: optional ?? false};
|
||||
return { kind: 'scalar', no: no, type: type, repeated: repeated ?? false, optional: optional ?? false };
|
||||
}
|
||||
}
|
||||
|
||||
@@ -99,17 +99,18 @@ class NapProtoMsg<T extends ProtoMessageType> {
|
||||
this._field = Object.keys(fields).map(key => {
|
||||
const field = fields[key];
|
||||
if (field.kind === 'scalar') {
|
||||
const repeatType = field.repeated
|
||||
? [ScalarType.STRING, ScalarType.BYTES].includes(field.type)
|
||||
? RepeatType.UNPACKED
|
||||
: RepeatType.PACKED
|
||||
: RepeatType.NO;
|
||||
return {
|
||||
no: field.no,
|
||||
name: key,
|
||||
kind: 'scalar',
|
||||
T: field.type,
|
||||
opt: field.optional,
|
||||
repeat: field.repeated
|
||||
? [ScalarType.STRING, ScalarType.BYTES].includes(field.type)
|
||||
? RepeatType.UNPACKED
|
||||
: RepeatType.PACKED
|
||||
: RepeatType.NO,
|
||||
repeat: repeatType,
|
||||
};
|
||||
} else if (field.kind === 'message') {
|
||||
const rt = NapProtoMsgCache.get(field.type()) ?? (() => {
|
||||
|
Reference in New Issue
Block a user