@yume-chan/struct 0.0.20 → 0.0.21

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (39) hide show
  1. package/CHANGELOG.json +6 -0
  2. package/CHANGELOG.md +6 -1
  3. package/esm/basic/definition.d.ts.map +1 -1
  4. package/esm/basic/definition.js.map +1 -1
  5. package/esm/basic/field-value.d.ts.map +1 -1
  6. package/esm/basic/field-value.js.map +1 -1
  7. package/esm/basic/struct-value.d.ts.map +1 -1
  8. package/esm/basic/struct-value.js.map +1 -1
  9. package/esm/struct.d.ts +0 -3
  10. package/esm/struct.d.ts.map +1 -1
  11. package/esm/struct.js +13 -13
  12. package/esm/struct.js.map +1 -1
  13. package/esm/sync-promise.js.map +1 -1
  14. package/esm/types/bigint.d.ts.map +1 -1
  15. package/esm/types/bigint.js +1 -2
  16. package/esm/types/bigint.js.map +1 -1
  17. package/esm/types/buffer/base.d.ts.map +1 -1
  18. package/esm/types/buffer/base.js +2 -4
  19. package/esm/types/buffer/base.js.map +1 -1
  20. package/esm/types/buffer/fixed-length.d.ts.map +1 -1
  21. package/esm/types/buffer/fixed-length.js.map +1 -1
  22. package/esm/types/buffer/variable-length.d.ts.map +1 -1
  23. package/esm/types/buffer/variable-length.js.map +1 -1
  24. package/esm/types/number.d.ts.map +1 -1
  25. package/esm/types/number.js +1 -1
  26. package/esm/types/number.js.map +1 -1
  27. package/package.json +8 -8
  28. package/src/basic/definition.ts +12 -12
  29. package/src/basic/field-value.ts +11 -11
  30. package/src/basic/stream.ts +1 -1
  31. package/src/basic/struct-value.ts +4 -4
  32. package/src/struct.ts +101 -101
  33. package/src/sync-promise.ts +14 -14
  34. package/src/types/bigint.ts +27 -35
  35. package/src/types/buffer/base.ts +32 -32
  36. package/src/types/buffer/fixed-length.ts +4 -3
  37. package/src/types/buffer/variable-length.ts +22 -20
  38. package/src/types/number.ts +17 -17
  39. package/tsconfig.build.tsbuildinfo +1 -1
@@ -7,7 +7,7 @@ export interface SyncPromise<T> {
7
7
  onrejected?:
8
8
  | ((reason: any) => TResult2 | PromiseLike<TResult2>)
9
9
  | null
10
- | undefined
10
+ | undefined,
11
11
  ): SyncPromise<TResult1 | TResult2>;
12
12
 
13
13
  valueOrPromise(): T | PromiseLike<T>;
@@ -57,11 +57,11 @@ export const SyncPromise: SyncPromiseStatic = {
57
57
  class PendingSyncPromise<T> implements SyncPromise<T> {
58
58
  #promise: PromiseLike<T>;
59
59
 
60
- public constructor(promise: PromiseLike<T>) {
60
+ constructor(promise: PromiseLike<T>) {
61
61
  this.#promise = promise;
62
62
  }
63
63
 
64
- public then<TResult1 = T, TResult2 = never>(
64
+ then<TResult1 = T, TResult2 = never>(
65
65
  onfulfilled?:
66
66
  | ((value: T) => TResult1 | PromiseLike<TResult1>)
67
67
  | null
@@ -69,14 +69,14 @@ class PendingSyncPromise<T> implements SyncPromise<T> {
69
69
  onrejected?:
70
70
  | ((reason: any) => TResult2 | PromiseLike<TResult2>)
71
71
  | null
72
- | undefined
72
+ | undefined,
73
73
  ) {
74
74
  return new PendingSyncPromise<TResult1 | TResult2>(
75
- this.#promise.then(onfulfilled, onrejected)
75
+ this.#promise.then(onfulfilled, onrejected),
76
76
  );
77
77
  }
78
78
 
79
- public valueOrPromise(): T | PromiseLike<T> {
79
+ valueOrPromise(): T | PromiseLike<T> {
80
80
  return this.#promise;
81
81
  }
82
82
  }
@@ -84,15 +84,15 @@ class PendingSyncPromise<T> implements SyncPromise<T> {
84
84
  class ResolvedSyncPromise<T> implements SyncPromise<T> {
85
85
  #value: T;
86
86
 
87
- public constructor(value: T) {
87
+ constructor(value: T) {
88
88
  this.#value = value;
89
89
  }
90
90
 
91
- public then<TResult1 = T>(
91
+ then<TResult1 = T>(
92
92
  onfulfilled?:
93
93
  | ((value: T) => TResult1 | PromiseLike<TResult1>)
94
94
  | null
95
- | undefined
95
+ | undefined,
96
96
  ) {
97
97
  if (!onfulfilled) {
98
98
  return this as any;
@@ -100,7 +100,7 @@ class ResolvedSyncPromise<T> implements SyncPromise<T> {
100
100
  return SyncPromise.try(() => onfulfilled(this.#value));
101
101
  }
102
102
 
103
- public valueOrPromise(): T | PromiseLike<T> {
103
+ valueOrPromise(): T | PromiseLike<T> {
104
104
  return this.#value;
105
105
  }
106
106
  }
@@ -108,11 +108,11 @@ class ResolvedSyncPromise<T> implements SyncPromise<T> {
108
108
  class RejectedSyncPromise<T> implements SyncPromise<T> {
109
109
  #reason: any;
110
110
 
111
- public constructor(reason: any) {
111
+ constructor(reason: any) {
112
112
  this.#reason = reason;
113
113
  }
114
114
 
115
- public then<TResult1 = T, TResult2 = never>(
115
+ then<TResult1 = T, TResult2 = never>(
116
116
  onfulfilled?:
117
117
  | ((value: T) => TResult1 | PromiseLike<TResult1>)
118
118
  | null
@@ -120,7 +120,7 @@ class RejectedSyncPromise<T> implements SyncPromise<T> {
120
120
  onrejected?:
121
121
  | ((reason: any) => TResult2 | PromiseLike<TResult2>)
122
122
  | null
123
- | undefined
123
+ | undefined,
124
124
  ) {
125
125
  if (!onrejected) {
126
126
  return this as any;
@@ -128,7 +128,7 @@ class RejectedSyncPromise<T> implements SyncPromise<T> {
128
128
  return SyncPromise.try(() => onrejected(this.#reason));
129
129
  }
130
130
 
131
- public valueOrPromise(): T | PromiseLike<T> {
131
+ valueOrPromise(): T | PromiseLike<T> {
132
132
  throw this.#reason;
133
133
  }
134
134
  }
@@ -18,86 +18,78 @@ import type { ValueOrPromise } from "../utils.js";
18
18
  type DataViewBigInt64Getter = (
19
19
  dataView: DataView,
20
20
  byteOffset: number,
21
- littleEndian: boolean | undefined
21
+ littleEndian: boolean | undefined,
22
22
  ) => bigint;
23
23
 
24
24
  type DataViewBigInt64Setter = (
25
25
  dataView: DataView,
26
26
  byteOffset: number,
27
27
  value: bigint,
28
- littleEndian: boolean | undefined
28
+ littleEndian: boolean | undefined,
29
29
  ) => void;
30
30
 
31
31
  export class BigIntFieldType {
32
- public readonly TTypeScriptType!: bigint;
32
+ readonly TTypeScriptType!: bigint;
33
33
 
34
- public readonly size: number;
34
+ readonly size: number;
35
35
 
36
- public readonly getter: DataViewBigInt64Getter;
36
+ readonly getter: DataViewBigInt64Getter;
37
37
 
38
- public readonly setter: DataViewBigInt64Setter;
38
+ readonly setter: DataViewBigInt64Setter;
39
39
 
40
- public constructor(
40
+ constructor(
41
41
  size: number,
42
42
  getter: DataViewBigInt64Getter,
43
- setter: DataViewBigInt64Setter
43
+ setter: DataViewBigInt64Setter,
44
44
  ) {
45
45
  this.size = size;
46
46
  this.getter = getter;
47
47
  this.setter = setter;
48
48
  }
49
49
 
50
- public static readonly Int64 = new BigIntFieldType(
51
- 8,
52
- getBigInt64,
53
- setBigInt64
54
- );
55
-
56
- public static readonly Uint64 = new BigIntFieldType(
57
- 8,
58
- getBigUint64,
59
- setBigUint64
60
- );
50
+ static readonly Int64 = new BigIntFieldType(8, getBigInt64, setBigInt64);
51
+
52
+ static readonly Uint64 = new BigIntFieldType(8, getBigUint64, setBigUint64);
61
53
  }
62
54
 
63
55
  export class BigIntFieldDefinition<
64
56
  TType extends BigIntFieldType = BigIntFieldType,
65
- TTypeScriptType = TType["TTypeScriptType"]
57
+ TTypeScriptType = TType["TTypeScriptType"],
66
58
  > extends StructFieldDefinition<void, TTypeScriptType> {
67
- public readonly type: TType;
59
+ readonly type: TType;
68
60
 
69
- public constructor(type: TType, typescriptType?: TTypeScriptType) {
61
+ constructor(type: TType, typescriptType?: TTypeScriptType) {
70
62
  void typescriptType;
71
63
  super();
72
64
  this.type = type;
73
65
  }
74
66
 
75
- public getSize(): number {
67
+ getSize(): number {
76
68
  return this.type.size;
77
69
  }
78
70
 
79
- public create(
71
+ create(
80
72
  options: Readonly<StructOptions>,
81
73
  struct: StructValue,
82
- value: TTypeScriptType
74
+ value: TTypeScriptType,
83
75
  ): BigIntFieldValue<this> {
84
76
  return new BigIntFieldValue(this, options, struct, value);
85
77
  }
86
78
 
87
- public override deserialize(
79
+ override deserialize(
88
80
  options: Readonly<StructOptions>,
89
81
  stream: ExactReadable,
90
- struct: StructValue
82
+ struct: StructValue,
91
83
  ): BigIntFieldValue<this>;
92
- public override deserialize(
84
+ override deserialize(
93
85
  options: Readonly<StructOptions>,
94
86
  stream: AsyncExactReadable,
95
- struct: StructValue
87
+ struct: StructValue,
96
88
  ): Promise<BigIntFieldValue<this>>;
97
- public override deserialize(
89
+ override deserialize(
98
90
  options: Readonly<StructOptions>,
99
91
  stream: ExactReadable | AsyncExactReadable,
100
- struct: StructValue
92
+ struct: StructValue,
101
93
  ): ValueOrPromise<BigIntFieldValue<this>> {
102
94
  return SyncPromise.try(() => {
103
95
  return stream.readExactly(this.getSize());
@@ -106,7 +98,7 @@ export class BigIntFieldDefinition<
106
98
  const view = new DataView(
107
99
  array.buffer,
108
100
  array.byteOffset,
109
- array.byteLength
101
+ array.byteLength,
110
102
  );
111
103
  const value = this.type.getter(view, 0, options.littleEndian);
112
104
  return this.create(options, struct, value as any);
@@ -116,14 +108,14 @@ export class BigIntFieldDefinition<
116
108
  }
117
109
 
118
110
  export class BigIntFieldValue<
119
- TDefinition extends BigIntFieldDefinition<BigIntFieldType, any>
111
+ TDefinition extends BigIntFieldDefinition<BigIntFieldType, any>,
120
112
  > extends StructFieldValue<TDefinition> {
121
- public serialize(dataView: DataView, offset: number): void {
113
+ serialize(dataView: DataView, offset: number): void {
122
114
  this.definition.type.setter(
123
115
  dataView,
124
116
  offset,
125
117
  this.value,
126
- this.options.littleEndian
118
+ this.options.littleEndian,
127
119
  );
128
120
  }
129
121
  }
@@ -20,9 +20,9 @@ import { decodeUtf8, encodeUtf8 } from "../../utils.js";
20
20
  */
21
21
  export abstract class BufferFieldSubType<
22
22
  TValue = unknown,
23
- TTypeScriptType = TValue
23
+ TTypeScriptType = TValue,
24
24
  > {
25
- public readonly TTypeScriptType!: TTypeScriptType;
25
+ readonly TTypeScriptType!: TTypeScriptType;
26
26
 
27
27
  /**
28
28
  * When implemented in derived classes, converts the type-specific `value` to an `Uint8Array`
@@ -30,10 +30,10 @@ export abstract class BufferFieldSubType<
30
30
  * This function should be "pure", i.e.,
31
31
  * same `value` should always be converted to `Uint8Array`s that have same content.
32
32
  */
33
- public abstract toBuffer(value: TValue): Uint8Array;
33
+ abstract toBuffer(value: TValue): Uint8Array;
34
34
 
35
35
  /** When implemented in derived classes, converts the `Uint8Array` to a type-specific value */
36
- public abstract toValue(array: Uint8Array): TValue;
36
+ abstract toValue(array: Uint8Array): TValue;
37
37
 
38
38
  /**
39
39
  * When implemented in derived classes, gets the size in byte of the type-specific `value`.
@@ -42,47 +42,47 @@ export abstract class BufferFieldSubType<
42
42
  * implementer can returns `-1`, so the caller will get its size by first converting it to
43
43
  * an `Uint8Array` (and cache the result).
44
44
  */
45
- public abstract getSize(value: TValue): number;
45
+ abstract getSize(value: TValue): number;
46
46
  }
47
47
 
48
48
  /** An `BufferFieldSubType` that's actually an `Uint8Array` */
49
49
  export class Uint8ArrayBufferFieldSubType<
50
- TTypeScriptType = Uint8Array
50
+ TTypeScriptType = Uint8Array,
51
51
  > extends BufferFieldSubType<Uint8Array, TTypeScriptType> {
52
- public static readonly Instance = new Uint8ArrayBufferFieldSubType();
52
+ static readonly Instance = new Uint8ArrayBufferFieldSubType();
53
53
 
54
54
  protected constructor() {
55
55
  super();
56
56
  }
57
57
 
58
- public toBuffer(value: Uint8Array): Uint8Array {
58
+ toBuffer(value: Uint8Array): Uint8Array {
59
59
  return value;
60
60
  }
61
61
 
62
- public toValue(buffer: Uint8Array): Uint8Array {
62
+ toValue(buffer: Uint8Array): Uint8Array {
63
63
  return buffer;
64
64
  }
65
65
 
66
- public getSize(value: Uint8Array): number {
66
+ getSize(value: Uint8Array): number {
67
67
  return value.byteLength;
68
68
  }
69
69
  }
70
70
 
71
71
  /** An `BufferFieldSubType` that converts between `Uint8Array` and `string` */
72
72
  export class StringBufferFieldSubType<
73
- TTypeScriptType = string
73
+ TTypeScriptType = string,
74
74
  > extends BufferFieldSubType<string, TTypeScriptType> {
75
- public static readonly Instance = new StringBufferFieldSubType();
75
+ static readonly Instance = new StringBufferFieldSubType();
76
76
 
77
- public toBuffer(value: string): Uint8Array {
77
+ toBuffer(value: string): Uint8Array {
78
78
  return encodeUtf8(value);
79
79
  }
80
80
 
81
- public toValue(array: Uint8Array): string {
81
+ toValue(array: Uint8Array): string {
82
82
  return decodeUtf8(array);
83
83
  }
84
84
 
85
- public getSize(): number {
85
+ getSize(): number {
86
86
  // Return `-1`, so `BufferLikeFieldDefinition` will
87
87
  // convert this `value` into an `Uint8Array` (and cache the result),
88
88
  // Then get the size from that `Uint8Array`
@@ -99,11 +99,11 @@ export abstract class BufferLikeFieldDefinition<
99
99
  >,
100
100
  TOptions = void,
101
101
  TOmitInitKey extends PropertyKey = never,
102
- TTypeScriptType = TType["TTypeScriptType"]
102
+ TTypeScriptType = TType["TTypeScriptType"],
103
103
  > extends StructFieldDefinition<TOptions, TTypeScriptType, TOmitInitKey> {
104
- public readonly type: TType;
104
+ readonly type: TType;
105
105
 
106
- public constructor(type: TType, options: TOptions) {
106
+ constructor(type: TType, options: TOptions) {
107
107
  super(options);
108
108
  this.type = type;
109
109
  }
@@ -116,29 +116,29 @@ export abstract class BufferLikeFieldDefinition<
116
116
  /**
117
117
  * When implemented in derived classes, creates a `StructFieldValue` for the current field definition.
118
118
  */
119
- public create(
119
+ create(
120
120
  options: Readonly<StructOptions>,
121
121
  struct: StructValue,
122
122
  value: TType["TTypeScriptType"],
123
- array?: Uint8Array
123
+ array?: Uint8Array,
124
124
  ): BufferLikeFieldValue<this> {
125
125
  return new BufferLikeFieldValue(this, options, struct, value, array);
126
126
  }
127
127
 
128
- public override deserialize(
128
+ override deserialize(
129
129
  options: Readonly<StructOptions>,
130
130
  stream: ExactReadable,
131
- struct: StructValue
131
+ struct: StructValue,
132
132
  ): BufferLikeFieldValue<this>;
133
- public override deserialize(
133
+ override deserialize(
134
134
  options: Readonly<StructOptions>,
135
135
  stream: AsyncExactReadable,
136
- struct: StructValue
136
+ struct: StructValue,
137
137
  ): Promise<BufferLikeFieldValue<this>>;
138
- public override deserialize(
138
+ override deserialize(
139
139
  options: Readonly<StructOptions>,
140
140
  stream: ExactReadable | AsyncExactReadable,
141
- struct: StructValue
141
+ struct: StructValue,
142
142
  ): ValueOrPromise<BufferLikeFieldValue<this>> {
143
143
  return SyncPromise.try(() => {
144
144
  const size = this.getDeserializeSize(struct);
@@ -161,29 +161,29 @@ export class BufferLikeFieldValue<
161
161
  BufferFieldSubType<unknown, unknown>,
162
162
  any,
163
163
  any
164
- >
164
+ >,
165
165
  > extends StructFieldValue<TDefinition> {
166
166
  protected array: Uint8Array | undefined;
167
167
 
168
- public constructor(
168
+ constructor(
169
169
  definition: TDefinition,
170
170
  options: Readonly<StructOptions>,
171
171
  struct: StructValue,
172
172
  value: TDefinition["TValue"],
173
- array?: Uint8Array
173
+ array?: Uint8Array,
174
174
  ) {
175
175
  super(definition, options, struct, value);
176
176
  this.array = array;
177
177
  }
178
178
 
179
- public override set(value: TDefinition["TValue"]): void {
179
+ override set(value: TDefinition["TValue"]): void {
180
180
  super.set(value);
181
181
  // When value changes, clear the cached `array`
182
182
  // It will be lazily calculated in `serialize()`
183
183
  this.array = undefined;
184
184
  }
185
185
 
186
- public serialize(dataView: DataView, offset: number): void {
186
+ serialize(dataView: DataView, offset: number): void {
187
187
  if (!this.array) {
188
188
  this.array = this.definition.type.toBuffer(this.value);
189
189
  }
@@ -191,7 +191,7 @@ export class BufferLikeFieldValue<
191
191
  new Uint8Array(
192
192
  dataView.buffer,
193
193
  dataView.byteOffset,
194
- dataView.byteLength
194
+ dataView.byteLength,
195
195
  ).set(this.array, offset);
196
196
  }
197
197
  }
@@ -7,10 +7,11 @@ export interface FixedLengthBufferLikeFieldOptions {
7
7
 
8
8
  export class FixedLengthBufferLikeFieldDefinition<
9
9
  TType extends BufferFieldSubType = BufferFieldSubType,
10
- TOptions extends FixedLengthBufferLikeFieldOptions = FixedLengthBufferLikeFieldOptions,
11
- TTypeScriptType = TType["TTypeScriptType"]
10
+ TOptions extends
11
+ FixedLengthBufferLikeFieldOptions = FixedLengthBufferLikeFieldOptions,
12
+ TTypeScriptType = TType["TTypeScriptType"],
12
13
  > extends BufferLikeFieldDefinition<TType, TOptions, never, TTypeScriptType> {
13
- public getSize(): number {
14
+ getSize(): number {
14
15
  return this.options.length;
15
16
  }
16
17
  }
@@ -13,7 +13,7 @@ export type LengthField<TFields> = KeysOfType<TFields, number | string>;
13
13
 
14
14
  export interface VariableLengthBufferLikeFieldOptions<
15
15
  TFields = object,
16
- TLengthField extends LengthField<TFields> = any
16
+ TLengthField extends LengthField<TFields> = any,
17
17
  > {
18
18
  /**
19
19
  * The name of the field that contains the length of the buffer.
@@ -33,15 +33,16 @@ export interface VariableLengthBufferLikeFieldOptions<
33
33
 
34
34
  export class VariableLengthBufferLikeFieldDefinition<
35
35
  TType extends BufferFieldSubType = BufferFieldSubType,
36
- TOptions extends VariableLengthBufferLikeFieldOptions = VariableLengthBufferLikeFieldOptions,
37
- TTypeScriptType = TType["TTypeScriptType"]
36
+ TOptions extends
37
+ VariableLengthBufferLikeFieldOptions = VariableLengthBufferLikeFieldOptions,
38
+ TTypeScriptType = TType["TTypeScriptType"],
38
39
  > extends BufferLikeFieldDefinition<
39
40
  TType,
40
41
  TOptions,
41
42
  TOptions["lengthField"],
42
43
  TTypeScriptType
43
44
  > {
44
- public getSize(): number {
45
+ getSize(): number {
45
46
  return 0;
46
47
  }
47
48
 
@@ -53,35 +54,36 @@ export class VariableLengthBufferLikeFieldDefinition<
53
54
  return value;
54
55
  }
55
56
 
56
- public override create(
57
+ override create(
57
58
  options: Readonly<StructOptions>,
58
59
  struct: StructValue,
59
60
  value: TTypeScriptType,
60
- array?: Uint8Array
61
+ array?: Uint8Array,
61
62
  ): VariableLengthBufferLikeStructFieldValue<this> {
62
63
  return new VariableLengthBufferLikeStructFieldValue(
63
64
  this,
64
65
  options,
65
66
  struct,
66
67
  value,
67
- array
68
+ array,
68
69
  );
69
70
  }
70
71
  }
71
72
 
72
73
  export class VariableLengthBufferLikeStructFieldValue<
73
- TDefinition extends VariableLengthBufferLikeFieldDefinition = VariableLengthBufferLikeFieldDefinition
74
+ TDefinition extends
75
+ VariableLengthBufferLikeFieldDefinition = VariableLengthBufferLikeFieldDefinition,
74
76
  > extends BufferLikeFieldValue<TDefinition> {
75
77
  protected length: number | undefined;
76
78
 
77
79
  protected lengthFieldValue: VariableLengthBufferLikeFieldLengthValue;
78
80
 
79
- public constructor(
81
+ constructor(
80
82
  definition: TDefinition,
81
83
  options: Readonly<StructOptions>,
82
84
  struct: StructValue,
83
85
  value: TDefinition["TValue"],
84
- array?: Uint8Array
86
+ array?: Uint8Array,
85
87
  ) {
86
88
  super(definition, options, struct, value, array);
87
89
 
@@ -95,12 +97,12 @@ export class VariableLengthBufferLikeStructFieldValue<
95
97
  const originalValue = struct.get(lengthField);
96
98
  this.lengthFieldValue = new VariableLengthBufferLikeFieldLengthValue(
97
99
  originalValue,
98
- this
100
+ this,
99
101
  );
100
102
  struct.set(lengthField, this.lengthFieldValue);
101
103
  }
102
104
 
103
- public override getSize() {
105
+ override getSize() {
104
106
  if (this.length === undefined) {
105
107
  this.length = this.definition.type.getSize(this.value);
106
108
  if (this.length === -1) {
@@ -112,7 +114,7 @@ export class VariableLengthBufferLikeStructFieldValue<
112
114
  return this.length;
113
115
  }
114
116
 
115
- public override set(value: unknown) {
117
+ override set(value: unknown) {
116
118
  super.set(value);
117
119
  this.array = undefined;
118
120
  this.length = undefined;
@@ -129,38 +131,38 @@ export class VariableLengthBufferLikeFieldLengthValue extends StructFieldValue {
129
131
 
130
132
  protected bufferField: VariableLengthBufferLikeFieldValueLike;
131
133
 
132
- public constructor(
134
+ constructor(
133
135
  originalField: StructFieldValue,
134
- arrayBufferField: VariableLengthBufferLikeFieldValueLike
136
+ arrayBufferField: VariableLengthBufferLikeFieldValueLike,
135
137
  ) {
136
138
  super(
137
139
  originalField.definition,
138
140
  originalField.options,
139
141
  originalField.struct,
140
- 0
142
+ 0,
141
143
  );
142
144
  this.originalField = originalField;
143
145
  this.bufferField = arrayBufferField;
144
146
  }
145
147
 
146
- public override getSize() {
148
+ override getSize() {
147
149
  return this.originalField.getSize();
148
150
  }
149
151
 
150
- public override get() {
152
+ override get() {
151
153
  let value: string | number = this.bufferField.getSize();
152
154
 
153
155
  const originalValue = this.originalField.get();
154
156
  if (typeof originalValue === "string") {
155
157
  value = value.toString(
156
- this.bufferField.definition.options.lengthFieldRadix ?? 10
158
+ this.bufferField.definition.options.lengthFieldRadix ?? 10,
157
159
  );
158
160
  }
159
161
 
160
162
  return value;
161
163
  }
162
164
 
163
- public override set() {
165
+ override set() {
164
166
  // Ignore setting
165
167
  // It will always be in sync with the buffer size
166
168
  }
@@ -16,7 +16,7 @@ export interface NumberFieldType {
16
16
  dataView: DataView,
17
17
  offset: number,
18
18
  value: number,
19
- littleEndian: boolean
19
+ littleEndian: boolean,
20
20
  ): void;
21
21
  }
22
22
 
@@ -109,42 +109,42 @@ export namespace NumberFieldType {
109
109
 
110
110
  export class NumberFieldDefinition<
111
111
  TType extends NumberFieldType = NumberFieldType,
112
- TTypeScriptType = number
112
+ TTypeScriptType = number,
113
113
  > extends StructFieldDefinition<void, TTypeScriptType> {
114
- public readonly type: TType;
114
+ readonly type: TType;
115
115
 
116
- public constructor(type: TType, typescriptType?: TTypeScriptType) {
116
+ constructor(type: TType, typescriptType?: TTypeScriptType) {
117
117
  void typescriptType;
118
118
  super();
119
119
  this.type = type;
120
120
  }
121
121
 
122
- public getSize(): number {
122
+ getSize(): number {
123
123
  return this.type.size;
124
124
  }
125
125
 
126
- public create(
126
+ create(
127
127
  options: Readonly<StructOptions>,
128
128
  struct: StructValue,
129
- value: TTypeScriptType
129
+ value: TTypeScriptType,
130
130
  ): NumberFieldValue<this> {
131
131
  return new NumberFieldValue(this, options, struct, value);
132
132
  }
133
133
 
134
- public override deserialize(
134
+ override deserialize(
135
135
  options: Readonly<StructOptions>,
136
136
  stream: ExactReadable,
137
- struct: StructValue
137
+ struct: StructValue,
138
138
  ): NumberFieldValue<this>;
139
- public override deserialize(
139
+ override deserialize(
140
140
  options: Readonly<StructOptions>,
141
141
  stream: AsyncExactReadable,
142
- struct: StructValue
142
+ struct: StructValue,
143
143
  ): Promise<NumberFieldValue<this>>;
144
- public override deserialize(
144
+ override deserialize(
145
145
  options: Readonly<StructOptions>,
146
146
  stream: ExactReadable | AsyncExactReadable,
147
- struct: StructValue
147
+ struct: StructValue,
148
148
  ): ValueOrPromise<NumberFieldValue<this>> {
149
149
  return SyncPromise.try(() => {
150
150
  return stream.readExactly(this.getSize());
@@ -152,7 +152,7 @@ export class NumberFieldDefinition<
152
152
  .then((array) => {
153
153
  const value = this.type.deserialize(
154
154
  array,
155
- options.littleEndian
155
+ options.littleEndian,
156
156
  );
157
157
  return this.create(options, struct, value as any);
158
158
  })
@@ -161,14 +161,14 @@ export class NumberFieldDefinition<
161
161
  }
162
162
 
163
163
  export class NumberFieldValue<
164
- TDefinition extends NumberFieldDefinition<NumberFieldType, any>
164
+ TDefinition extends NumberFieldDefinition<NumberFieldType, any>,
165
165
  > extends StructFieldValue<TDefinition> {
166
- public serialize(dataView: DataView, offset: number): void {
166
+ serialize(dataView: DataView, offset: number): void {
167
167
  this.definition.type.serialize(
168
168
  dataView,
169
169
  offset,
170
170
  this.value,
171
- this.options.littleEndian
171
+ this.options.littleEndian,
172
172
  );
173
173
  }
174
174
  }