mirror of
https://github.com/yume-chan/ya-webadb.git
synced 2025-10-03 09:49:24 +02:00
chore: experimental moving to rush
This commit is contained in:
parent
963ac49d14
commit
d80288ec9b
209 changed files with 9508 additions and 27413 deletions
73
libraries/struct/src/basic/field-value.ts
Normal file
73
libraries/struct/src/basic/field-value.ts
Normal file
|
@ -0,0 +1,73 @@
|
|||
import type { StructOptions, StructSerializationContext } from './context';
|
||||
import type { StructFieldDefinition } from './definition';
|
||||
import type { StructValue } from './struct-value';
|
||||
|
||||
/**
|
||||
* Field runtime value manages one field of one `Struct` instance.
|
||||
*
|
||||
* If one `StructFieldDefinition` needs to change other field's semantics
|
||||
* It can override other fields' `StructFieldValue` in its own `StructFieldValue`'s constructor
|
||||
*/
|
||||
export abstract class StructFieldValue<
|
||||
TDefinition extends StructFieldDefinition<any, any, any> = StructFieldDefinition<any, any, any>
|
||||
> {
|
||||
/** Gets the definition associated with this runtime value */
|
||||
public readonly definition: TDefinition;
|
||||
|
||||
/** Gets the options of the associated `Struct` */
|
||||
public readonly options: Readonly<StructOptions>;
|
||||
|
||||
/** Gets the serialization context of the associated `Struct` instance */
|
||||
public readonly context: StructSerializationContext;
|
||||
|
||||
/** Gets the associated `Struct` instance */
|
||||
public readonly struct: StructValue;
|
||||
|
||||
protected value: TDefinition['TValue'];
|
||||
|
||||
public constructor(
|
||||
definition: TDefinition,
|
||||
options: Readonly<StructOptions>,
|
||||
context: StructSerializationContext,
|
||||
struct: StructValue,
|
||||
value: TDefinition['TValue'],
|
||||
) {
|
||||
this.definition = definition;
|
||||
this.options = options;
|
||||
this.context = context;
|
||||
this.struct = struct;
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets size of this field. By default, it returns its `definition`'s size.
|
||||
*
|
||||
* When overridden in derived classes, can have custom logic to calculate the actual size.
|
||||
*/
|
||||
public getSize(): number {
|
||||
return this.definition.getSize();
|
||||
}
|
||||
|
||||
/**
|
||||
* When implemented in derived classes, returns the current value of this field
|
||||
*/
|
||||
public get(): TDefinition['TValue'] {
|
||||
return this.value;
|
||||
}
|
||||
|
||||
/**
|
||||
* When implemented in derived classes, update the current value of this field
|
||||
*/
|
||||
public set(value: TDefinition['TValue']): void {
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
/**
|
||||
* When implemented in derived classes, serializes this field into `dataView` at `offset`
|
||||
*/
|
||||
public abstract serialize(
|
||||
dataView: DataView,
|
||||
offset: number,
|
||||
context: StructSerializationContext
|
||||
): void;
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue