refactor(struct): rename member types

This commit is contained in:
Simon Chan 2021-01-21 10:14:40 +08:00
parent 90dcbad660
commit 5a18c845c2
13 changed files with 85 additions and 85 deletions

View file

@ -35,7 +35,7 @@ export const AdbFrameBufferV1 =
.uint32('alpha_length') .uint32('alpha_length')
.uint8ClampedArray('data', { lengthField: 'size' }); .uint8ClampedArray('data', { lengthField: 'size' });
export type AdbFrameBufferV1 = typeof AdbFrameBufferV1['deserializedType']; export type AdbFrameBufferV1 = typeof AdbFrameBufferV1['TDeserializeResult'];
export const AdbFrameBufferV2 = export const AdbFrameBufferV2 =
new Struct({ littleEndian: true }) new Struct({ littleEndian: true })
@ -54,7 +54,7 @@ export const AdbFrameBufferV2 =
.uint32('alpha_length') .uint32('alpha_length')
.uint8ClampedArray('data', { lengthField: 'size' }); .uint8ClampedArray('data', { lengthField: 'size' });
export type AdbFrameBufferV2 = typeof AdbFrameBufferV2['deserializedType']; export type AdbFrameBufferV2 = typeof AdbFrameBufferV2['TDeserializeResult'];
export type AdbFrameBuffer = AdbFrameBufferV1 | AdbFrameBufferV2; export type AdbFrameBuffer = AdbFrameBufferV1 | AdbFrameBufferV2;

View file

@ -11,7 +11,7 @@ export const AdbSyncEntryResponse =
.string('name', { lengthField: 'nameLength' }) .string('name', { lengthField: 'nameLength' })
.extra({ id: AdbSyncResponseId.Entry as const }); .extra({ id: AdbSyncResponseId.Entry as const });
export type AdbSyncEntryResponse = typeof AdbSyncEntryResponse['deserializedType']; export type AdbSyncEntryResponse = typeof AdbSyncEntryResponse['TDeserializeResult'];
const ResponseTypes = { const ResponseTypes = {
[AdbSyncResponseId.Entry]: AdbSyncEntryResponse, [AdbSyncResponseId.Entry]: AdbSyncEntryResponse,

View file

@ -29,7 +29,7 @@ export const AdbSyncLstatResponse =
} }
}); });
export type AdbSyncLstatResponse = typeof AdbSyncLstatResponse['deserializedType']; export type AdbSyncLstatResponse = typeof AdbSyncLstatResponse['TDeserializeResult'];
export enum AdbSyncStatErrorCode { export enum AdbSyncStatErrorCode {
EACCES = 13, EACCES = 13,
@ -78,7 +78,7 @@ export const AdbSyncStatResponse =
} }
}); });
export type AdbSyncStatResponse = typeof AdbSyncStatResponse['deserializedType']; export type AdbSyncStatResponse = typeof AdbSyncStatResponse['TDeserializeResult'];
const StatResponseType = { const StatResponseType = {
[AdbSyncResponseId.Stat]: AdbSyncStatResponse, [AdbSyncResponseId.Stat]: AdbSyncStatResponse,

View file

@ -25,9 +25,9 @@ const AdbPacketStruct =
.fields(AdbPacketHeader) .fields(AdbPacketHeader)
.arrayBuffer('payload', { lengthField: 'payloadLength' }); .arrayBuffer('payload', { lengthField: 'payloadLength' });
export type AdbPacket = typeof AdbPacketStruct['deserializedType']; export type AdbPacket = typeof AdbPacketStruct['TDeserializeResult'];
export type AdbPacketInit = Omit<typeof AdbPacketStruct['initType'], 'checksum' | 'magic'>; export type AdbPacketInit = Omit<typeof AdbPacketStruct['TInit'], 'checksum' | 'magic'>;
export namespace AdbPacket { export namespace AdbPacket {
export async function read(backend: AdbBackend): Promise<AdbPacket> { export async function read(backend: AdbBackend): Promise<AdbPacket> {

View file

@ -159,7 +159,7 @@ const VideoPacket =
export const NoPts = BigInt(-1); export const NoPts = BigInt(-1);
export type VideoPacket = typeof VideoPacket['deserializedType']; export type VideoPacket = typeof VideoPacket['TDeserializeResult'];
const ClipboardMessage = const ClipboardMessage =
new Struct() new Struct()

View file

@ -18,7 +18,7 @@ export const ScrcpySimpleControlMessage =
new Struct() new Struct()
.uint8('type', placeholder<ScrcpyControlMessageType.BackOrScreenOn>()); .uint8('type', placeholder<ScrcpyControlMessageType.BackOrScreenOn>());
export type ScrcpySimpleControlMessage = typeof ScrcpySimpleControlMessage['initType']; export type ScrcpySimpleControlMessage = typeof ScrcpySimpleControlMessage['TInit'];
export enum AndroidMotionEventAction { export enum AndroidMotionEventAction {
Down, Down,
@ -48,7 +48,7 @@ export const ScrcpyInjectTouchControlMessage =
.uint16('pressure') .uint16('pressure')
.uint32('buttons'); .uint32('buttons');
export type ScrcpyInjectTouchControlMessage = typeof ScrcpyInjectTouchControlMessage['initType']; export type ScrcpyInjectTouchControlMessage = typeof ScrcpyInjectTouchControlMessage['TInit'];
export const ScrcpyInjectTextControlMessage = export const ScrcpyInjectTextControlMessage =
new Struct() new Struct()
@ -57,7 +57,7 @@ export const ScrcpyInjectTextControlMessage =
.string('text', { lengthField: 'length' }); .string('text', { lengthField: 'length' });
export type ScrcpyInjectTextControlMessage = export type ScrcpyInjectTextControlMessage =
typeof ScrcpyInjectTextControlMessage['initType']; typeof ScrcpyInjectTextControlMessage['TInit'];
export enum AndroidKeyEventAction { export enum AndroidKeyEventAction {
Down = 0, Down = 0,
@ -106,7 +106,7 @@ export const ScrcpyInjectKeyCodeControlMessage =
.uint32('metaState'); .uint32('metaState');
export type ScrcpyInjectKeyCodeControlMessage = export type ScrcpyInjectKeyCodeControlMessage =
typeof ScrcpyInjectKeyCodeControlMessage['initType']; typeof ScrcpyInjectKeyCodeControlMessage['TInit'];
export type ScrcpyControlMessage = export type ScrcpyControlMessage =
ScrcpySimpleControlMessage | ScrcpySimpleControlMessage |

View file

@ -57,7 +57,7 @@ const buffer = MyStruct.serialize({
- [Custom field type](#custom-field-type) - [Custom field type](#custom-field-type)
- [`Struct#field`](#structfield) - [`Struct#field`](#structfield)
- [`StructFieldDefinition`](#structfielddefinition) - [`StructFieldDefinition`](#structfielddefinition)
- [`valueType`/`omitInitKeyType`](#valuetypeomitinitkeytype) - [`TValue`/`TOmitInitKey`](#tvaluetomitinitkey)
- [`getSize`](#getsize) - [`getSize`](#getsize)
- [`create`](#create) - [`create`](#create)
- [`deserialize`](#deserialize-1) - [`deserialize`](#deserialize-1)
@ -570,8 +570,8 @@ field<
name: TName, name: TName,
definition: TDefinition definition: TDefinition
): Struct< ): Struct<
TFields & Record<TName, TDefinition['valueType']>, TFields & Record<TName, TDefinition['TValue']>,
TOmitInitKey | TDefinition['omitInitKeyType'], TOmitInitKey | TDefinition['TOmitInitKey'],
TExtra, TExtra,
TPostDeserialized TPostDeserialized
>; >;
@ -615,7 +615,7 @@ A `StructFieldDefinition` describes type, size and runtime semantics of a field.
It's an `abstract` class, means it lacks some method implementations, so it shouldn't be constructed. It's an `abstract` class, means it lacks some method implementations, so it shouldn't be constructed.
#### `valueType`/`omitInitKeyType` #### `TValue`/`TOmitInitKey`
These two fields are used to provide type information to TypeScript. Their values will always be `undefined`, but having correct types is enough. You don't need to care about them. These two fields are used to provide type information to TypeScript. Their values will always be `undefined`, but having correct types is enough. You don't need to care about them.
@ -688,8 +688,8 @@ If this field's size can change based on some criteria, one must override `getSi
#### `get`/`set` #### `get`/`set`
```ts ```ts
get(): TDefinition['valueType']; get(): TDefinition['TValue'];
set(value: TDefinition['valueType']): void; set(value: TDefinition['TValue']): void;
``` ```
Defines how to get or set this field's value. By default, it store its value in `value` field. Defines how to get or set this field's value. By default, it store its value in `value` field.

View file

@ -23,20 +23,20 @@ export abstract class StructFieldDefinition<
TValue = unknown, TValue = unknown,
TOmitInitKey extends PropertyKey = never, TOmitInitKey extends PropertyKey = never,
> { > {
/**
* When `T` is a type initiated `StructFieldDefinition`,
* use `T['TValue']` to retrieve its `TValue` type parameter.
*/
public readonly TValue!: TValue;
/**
* When `T` is a type initiated `StructFieldDefinition`,
* use `T['TOmitInitKey']` to retrieve its `TOmitInitKey` type parameter.
*/
public readonly TOmitInitKey!: TOmitInitKey;
public readonly options: TOptions; public readonly options: TOptions;
/**
* When `T` is a type initiated `StructFieldDefinition`,
* use `T['valueType']` to retrieve its `TValue` type parameter.
*/
public readonly valueType!: TValue;
/**
* When `T` is a type initiated `StructFieldDefinition`,
* use `T['omitInitKeyType']` to retrieve its `TOmitInitKey` type parameter.
*/
public readonly omitInitKeyType!: TOmitInitKey;
public constructor(options: TOptions) { public constructor(options: TOptions) {
this.options = options; this.options = options;
} }

View file

@ -23,14 +23,14 @@ export abstract class StructFieldValue<
/** Gets the associated `Struct` instance */ /** Gets the associated `Struct` instance */
public readonly struct: StructValue; public readonly struct: StructValue;
protected value: TDefinition['valueType']; protected value: TDefinition['TValue'];
public constructor( public constructor(
definition: TDefinition, definition: TDefinition,
options: Readonly<StructOptions>, options: Readonly<StructOptions>,
context: StructSerializationContext, context: StructSerializationContext,
struct: StructValue, struct: StructValue,
value: TDefinition['valueType'], value: TDefinition['TValue'],
) { ) {
this.definition = definition; this.definition = definition;
this.options = options; this.options = options;
@ -51,14 +51,14 @@ export abstract class StructFieldValue<
/** /**
* When implemented in derived classes, returns the current value of this field * When implemented in derived classes, returns the current value of this field
*/ */
public get(): TDefinition['valueType'] { public get(): TDefinition['TValue'] {
return this.value; return this.value;
} }
/** /**
* When implemented in derived classes, update the current value of this field * When implemented in derived classes, update the current value of this field
*/ */
public set(value: TDefinition['valueType']): void { public set(value: TDefinition['TValue']): void {
this.value = value; this.value = value;
} }

View file

@ -28,9 +28,9 @@ type AddFieldDescriptor<
Identity<Struct< Identity<Struct<
// Merge two types // Merge two types
// Evaluate immediately to optimize editor hover tooltip // Evaluate immediately to optimize editor hover tooltip
Evaluate<TFields & Record<TFieldName, TDefinition['valueType']>>, Evaluate<TFields & Record<TFieldName, TDefinition['TValue']>>,
// Merge two `TOmitInitKey`s // Merge two `TOmitInitKey`s
TOmitInitKey | TDefinition['omitInitKeyType'], TOmitInitKey | TDefinition['TOmitInitKey'],
TExtra, TExtra,
TPostDeserialized TPostDeserialized
>>; >>;
@ -56,7 +56,7 @@ interface ArrayBufferLikeFieldCreator<
< <
TName extends PropertyKey, TName extends PropertyKey,
TType extends ArrayBufferLikeFieldType, TType extends ArrayBufferLikeFieldType,
TTypeScriptType = TType['valueType'], TTypeScriptType = TType['TTypeScriptType'],
>( >(
name: TName, name: TName,
type: TType, type: TType,
@ -81,7 +81,7 @@ interface ArrayBufferLikeFieldCreator<
TName extends PropertyKey, TName extends PropertyKey,
TType extends ArrayBufferLikeFieldType, TType extends ArrayBufferLikeFieldType,
TOptions extends VariableLengthArrayBufferLikeFieldOptions<TFields>, TOptions extends VariableLengthArrayBufferLikeFieldOptions<TFields>,
TTypeScriptType = TType['valueType'], TTypeScriptType = TType['TTypeScriptType'],
>( >(
name: TName, name: TName,
type: TType, type: TType,
@ -112,7 +112,7 @@ interface ArrayBufferTypeFieldDefinitionCreator<
> { > {
< <
TName extends PropertyKey, TName extends PropertyKey,
TTypeScriptType = TType['valueType'], TTypeScriptType = TType['TTypeScriptType'],
>( >(
name: TName, name: TName,
options: FixedLengthArrayBufferLikeFieldOptions, options: FixedLengthArrayBufferLikeFieldOptions,
@ -133,7 +133,7 @@ interface ArrayBufferTypeFieldDefinitionCreator<
TName extends PropertyKey, TName extends PropertyKey,
TLengthField extends LengthField<TFields>, TLengthField extends LengthField<TFields>,
TOptions extends VariableLengthArrayBufferLikeFieldOptions<TFields, TLengthField>, TOptions extends VariableLengthArrayBufferLikeFieldOptions<TFields, TLengthField>,
TTypeScriptType = TType['valueType'], TTypeScriptType = TType['TTypeScriptType'],
>( >(
name: TName, name: TName,
options: TOptions, options: TOptions,
@ -154,7 +154,7 @@ interface ArrayBufferTypeFieldDefinitionCreator<
export type StructPostDeserialized<TFields, TPostDeserialized> = export type StructPostDeserialized<TFields, TPostDeserialized> =
(this: TFields, object: TFields) => TPostDeserialized; (this: TFields, object: TFields) => TPostDeserialized;
export type StructDeserializedType<TFields extends object, TExtra extends object, TPostDeserialized> = export type StructDeserializedResult<TFields extends object, TExtra extends object, TPostDeserialized> =
TPostDeserialized extends undefined ? Overwrite<TExtra, TFields> : TPostDeserialized; TPostDeserialized extends undefined ? Overwrite<TExtra, TFields> : TPostDeserialized;
export class Struct< export class Struct<
@ -162,16 +162,16 @@ export class Struct<
TOmitInitKey extends PropertyKey = never, TOmitInitKey extends PropertyKey = never,
TExtra extends object = {}, TExtra extends object = {},
TPostDeserialized = undefined, TPostDeserialized = undefined,
> implements StructLike<StructDeserializedType<TFields, TExtra, TPostDeserialized>>{ > implements StructLike<StructDeserializedResult<TFields, TExtra, TPostDeserialized>>{
public readonly fieldsType!: TFields; public readonly TFields!: TFields;
public readonly omitInitType!: TOmitInitKey; public readonly TOmitInitKey!: TOmitInitKey;
public readonly extraType!: TExtra; public readonly TExtra!: TExtra;
public readonly initType!: Evaluate<Omit<TFields, TOmitInitKey>>; public readonly TInit!: Evaluate<Omit<TFields, TOmitInitKey>>;
public readonly deserializedType!: StructDeserializedType<TFields, TExtra, TPostDeserialized>; public readonly TDeserializeResult!: StructDeserializedResult<TFields, TExtra, TPostDeserialized>;
public readonly options: Readonly<StructOptions>; public readonly options: Readonly<StructOptions>;
@ -229,9 +229,9 @@ export class Struct<
public fields<TOther extends Struct<any, any, any, any>>( public fields<TOther extends Struct<any, any, any, any>>(
other: TOther other: TOther
): Struct< ): Struct<
TFields & TOther['fieldsType'], TFields & TOther['TFields'],
TOmitInitKey | TOther['omitInitType'], TOmitInitKey | TOther['TOmitInitKey'],
TExtra & TOther['extraType'], TExtra & TOther['TExtra'],
TPostDeserialized TPostDeserialized
> { > {
for (const field of other._fields) { for (const field of other._fields) {
@ -245,7 +245,7 @@ export class Struct<
private number< private number<
TName extends PropertyKey, TName extends PropertyKey,
TType extends NumberFieldType = NumberFieldType, TType extends NumberFieldType = NumberFieldType,
TTypeScriptType = TType['valueType'] TTypeScriptType = TType['TTypeScriptType']
>( >(
name: TName, name: TName,
type: TType, type: TType,
@ -262,7 +262,7 @@ export class Struct<
*/ */
public int8< public int8<
TName extends PropertyKey, TName extends PropertyKey,
TTypeScriptType = (typeof NumberFieldType)['Uint8']['valueType'] TTypeScriptType = (typeof NumberFieldType)['Uint8']['TTypeScriptType']
>( >(
name: TName, name: TName,
_typescriptType?: TTypeScriptType, _typescriptType?: TTypeScriptType,
@ -279,7 +279,7 @@ export class Struct<
*/ */
public uint8< public uint8<
TName extends PropertyKey, TName extends PropertyKey,
TTypeScriptType = (typeof NumberFieldType)['Uint8']['valueType'] TTypeScriptType = (typeof NumberFieldType)['Uint8']['TTypeScriptType']
>( >(
name: TName, name: TName,
_typescriptType?: TTypeScriptType, _typescriptType?: TTypeScriptType,
@ -296,7 +296,7 @@ export class Struct<
*/ */
public int16< public int16<
TName extends PropertyKey, TName extends PropertyKey,
TTypeScriptType = (typeof NumberFieldType)['Uint16']['valueType'] TTypeScriptType = (typeof NumberFieldType)['Uint16']['TTypeScriptType']
>( >(
name: TName, name: TName,
_typescriptType?: TTypeScriptType, _typescriptType?: TTypeScriptType,
@ -313,7 +313,7 @@ export class Struct<
*/ */
public uint16< public uint16<
TName extends PropertyKey, TName extends PropertyKey,
TTypeScriptType = (typeof NumberFieldType)['Uint16']['valueType'] TTypeScriptType = (typeof NumberFieldType)['Uint16']['TTypeScriptType']
>( >(
name: TName, name: TName,
_typescriptType?: TTypeScriptType, _typescriptType?: TTypeScriptType,
@ -330,7 +330,7 @@ export class Struct<
*/ */
public int32< public int32<
TName extends PropertyKey, TName extends PropertyKey,
TTypeScriptType = (typeof NumberFieldType)['Int32']['valueType'] TTypeScriptType = (typeof NumberFieldType)['Int32']['TTypeScriptType']
>( >(
name: TName, name: TName,
_typescriptType?: TTypeScriptType, _typescriptType?: TTypeScriptType,
@ -347,7 +347,7 @@ export class Struct<
*/ */
public uint32< public uint32<
TName extends PropertyKey, TName extends PropertyKey,
TTypeScriptType = (typeof NumberFieldType)['Uint32']['valueType'] TTypeScriptType = (typeof NumberFieldType)['Uint32']['TTypeScriptType']
>( >(
name: TName, name: TName,
typescriptType?: TTypeScriptType, typescriptType?: TTypeScriptType,
@ -366,7 +366,7 @@ export class Struct<
*/ */
public int64< public int64<
TName extends PropertyKey, TName extends PropertyKey,
TTypeScriptType = (typeof NumberFieldType)['Int64']['valueType'] TTypeScriptType = (typeof NumberFieldType)['Int64']['TTypeScriptType']
>( >(
name: TName, name: TName,
_typescriptType?: TTypeScriptType, _typescriptType?: TTypeScriptType,
@ -385,7 +385,7 @@ export class Struct<
*/ */
public uint64< public uint64<
TName extends PropertyKey, TName extends PropertyKey,
TTypeScriptType = (typeof NumberFieldType)['Uint64']['valueType'] TTypeScriptType = (typeof NumberFieldType)['Uint64']['TTypeScriptType']
>( >(
name: TName, name: TName,
_typescriptType?: TTypeScriptType, _typescriptType?: TTypeScriptType,
@ -524,7 +524,7 @@ export class Struct<
public async deserialize( public async deserialize(
context: StructDeserializationContext context: StructDeserializationContext
): Promise<StructDeserializedType<TFields, TExtra, TPostDeserialized>> { ): Promise<StructDeserializedResult<TFields, TExtra, TPostDeserialized>> {
const value = new StructValue(); const value = new StructValue();
Object.defineProperties(value.value, this._extra); Object.defineProperties(value.value, this._extra);

View file

@ -10,7 +10,7 @@ import { StructDeserializationContext, StructFieldDefinition, StructFieldValue,
* specified by user when creating field definitions. * specified by user when creating field definitions.
*/ */
export abstract class ArrayBufferLikeFieldType<TValue = unknown, TTypeScriptType = TValue> { export abstract class ArrayBufferLikeFieldType<TValue = unknown, TTypeScriptType = TValue> {
public readonly valueType!: TTypeScriptType; public readonly TTypeScriptType!: TTypeScriptType;
/** /**
* When implemented in derived classes, converts the type-specific `value` to an `ArrayBuffer` * When implemented in derived classes, converts the type-specific `value` to an `ArrayBuffer`
@ -105,7 +105,7 @@ export abstract class ArrayBufferLikeFieldDefinition<
TOmitInitKey extends PropertyKey = never, TOmitInitKey extends PropertyKey = never,
> extends StructFieldDefinition< > extends StructFieldDefinition<
TOptions, TOptions,
TType['valueType'], TType['TTypeScriptType'],
TOmitInitKey TOmitInitKey
>{ >{
public readonly type: TType; public readonly type: TType;
@ -126,7 +126,7 @@ export abstract class ArrayBufferLikeFieldDefinition<
options: Readonly<StructOptions>, options: Readonly<StructOptions>,
context: StructSerializationContext, context: StructSerializationContext,
struct: StructValue, struct: StructValue,
value: TType['valueType'], value: TType['TTypeScriptType'],
arrayBuffer?: ArrayBuffer, arrayBuffer?: ArrayBuffer,
): ArrayBufferLikeFieldValue<this> { ): ArrayBufferLikeFieldValue<this> {
return new ArrayBufferLikeFieldValue(this, options, context, struct, value, arrayBuffer); return new ArrayBufferLikeFieldValue(this, options, context, struct, value, arrayBuffer);
@ -161,14 +161,14 @@ export class ArrayBufferLikeFieldValue<
options: Readonly<StructOptions>, options: Readonly<StructOptions>,
context: StructSerializationContext, context: StructSerializationContext,
struct: StructValue, struct: StructValue,
value: TDefinition['valueType'], value: TDefinition['TValue'],
arrayBuffer?: ArrayBuffer, arrayBuffer?: ArrayBuffer,
) { ) {
super(definition, options, context, struct, value); super(definition, options, context, struct, value);
this.arrayBuffer = arrayBuffer; this.arrayBuffer = arrayBuffer;
} }
public set(value: TDefinition['valueType']): void { public set(value: TDefinition['TValue']): void {
super.set(value); super.set(value);
this.arrayBuffer = undefined; this.arrayBuffer = undefined;
} }

View file

@ -7,23 +7,7 @@ export type DataViewSetters =
{ [TKey in keyof DataView]: TKey extends `set${string}` ? TKey : never }[keyof DataView]; { [TKey in keyof DataView]: TKey extends `set${string}` ? TKey : never }[keyof DataView];
export class NumberFieldType<TTypeScriptType extends number | bigint = number | bigint> { export class NumberFieldType<TTypeScriptType extends number | bigint = number | bigint> {
public static readonly Int8 = new NumberFieldType<number>(1, 'getInt8', 'setInt8'); public readonly TTypeScriptType!: TTypeScriptType;
public static readonly Uint8 = new NumberFieldType<number>(1, 'getUint8', 'setUint8');
public static readonly Int16 = new NumberFieldType<number>(2, 'getInt16', 'setInt16');
public static readonly Uint16 = new NumberFieldType<number>(2, 'getUint16', 'setUint16');
public static readonly Int32 = new NumberFieldType<number>(4, 'getInt32', 'setInt32');
public static readonly Uint32 = new NumberFieldType<number>(4, 'getUint32', 'setUint32');
public static readonly Int64 = new NumberFieldType<bigint>(8, 'getBigInt64', 'setBigInt64');
public static readonly Uint64 = new NumberFieldType<bigint>(8, 'getBigUint64', 'setBigUint64');
public readonly valueType!: TTypeScriptType;
public readonly size: number; public readonly size: number;
@ -40,11 +24,27 @@ export class NumberFieldType<TTypeScriptType extends number | bigint = number |
this.dataViewGetter = dataViewGetter; this.dataViewGetter = dataViewGetter;
this.dataViewSetter = dataViewSetter; this.dataViewSetter = dataViewSetter;
} }
public static readonly Int8 = new NumberFieldType<number>(1, 'getInt8', 'setInt8');
public static readonly Uint8 = new NumberFieldType<number>(1, 'getUint8', 'setUint8');
public static readonly Int16 = new NumberFieldType<number>(2, 'getInt16', 'setInt16');
public static readonly Uint16 = new NumberFieldType<number>(2, 'getUint16', 'setUint16');
public static readonly Int32 = new NumberFieldType<number>(4, 'getInt32', 'setInt32');
public static readonly Uint32 = new NumberFieldType<number>(4, 'getUint32', 'setUint32');
public static readonly Int64 = new NumberFieldType<bigint>(8, 'getBigInt64', 'setBigInt64');
public static readonly Uint64 = new NumberFieldType<bigint>(8, 'getBigUint64', 'setBigUint64');
} }
export class NumberFieldDefinition< export class NumberFieldDefinition<
TType extends NumberFieldType = NumberFieldType, TType extends NumberFieldType = NumberFieldType,
TTypeScriptType = TType['valueType'], TTypeScriptType = TType['TTypeScriptType'],
> extends StructFieldDefinition< > extends StructFieldDefinition<
void, void,
TTypeScriptType TTypeScriptType

View file

@ -35,7 +35,7 @@ export class VariableLengthArrayBufferLikeFieldDefinition<
options: Readonly<StructOptions>, options: Readonly<StructOptions>,
context: StructSerializationContext, context: StructSerializationContext,
struct: StructValue, struct: StructValue,
value: TType['valueType'], value: TType['TTypeScriptType'],
arrayBuffer?: ArrayBuffer arrayBuffer?: ArrayBuffer
): VariableLengthArrayBufferLikeStructFieldValue<this> { ): VariableLengthArrayBufferLikeStructFieldValue<this> {
return new VariableLengthArrayBufferLikeStructFieldValue( return new VariableLengthArrayBufferLikeStructFieldValue(
@ -61,7 +61,7 @@ export class VariableLengthArrayBufferLikeStructFieldValue<
options: Readonly<StructOptions>, options: Readonly<StructOptions>,
context: StructSerializationContext, context: StructSerializationContext,
struct: StructValue, struct: StructValue,
value: TDefinition['valueType'], value: TDefinition['TValue'],
arrayBuffer?: ArrayBuffer, arrayBuffer?: ArrayBuffer,
) { ) {
super(definition, options, context, struct, value, arrayBuffer); super(definition, options, context, struct, value, arrayBuffer);