Skip to content

Commit

Permalink
Fix errors (#44)
Browse files Browse the repository at this point in the history
  • Loading branch information
MierenManz authored Nov 12, 2024
1 parent 144ab85 commit 541df5b
Show file tree
Hide file tree
Showing 28 changed files with 38 additions and 77 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/checks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,4 @@ jobs:
uses: denoland/setup-deno@main

- name: Run deno test
run: deno test --allow-none
run: deno test
4 changes: 2 additions & 2 deletions src/array/array.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export class ArrayType<T> extends UnsizedType<T[]> {
return result;
}

read(dt: DataView, options: Options = { byteOffset: 0 }): T[] {
override read(dt: DataView, options: Options = { byteOffset: 0 }): T[] {
if (this.length === 0) return [];
const result = new Array(this.length);
const { type } = this;
Expand Down Expand Up @@ -47,7 +47,7 @@ export class ArrayType<T> extends UnsizedType<T[]> {
}
}

write(
override write(
value: T[],
dt: DataView,
options: Options = { byteOffset: 0 },
Expand Down
4 changes: 0 additions & 4 deletions src/array/array_buffer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@ export class ArrayBufferType extends SizedType<ArrayBuffer> {
dt: DataView,
options: Options = { byteOffset: 0 },
): ArrayBuffer {
super.rangeCheck(dt.byteLength, options.byteOffset);

const resultAB = new ArrayBuffer(this.byteSize);
const resultView = new Uint8Array(resultAB);

Expand All @@ -32,8 +30,6 @@ export class ArrayBufferType extends SizedType<ArrayBuffer> {
dt: DataView,
options: Options = { byteOffset: 0 },
): void {
super.rangeCheck(dt.byteLength, options.byteOffset);

const view = new Uint8Array(
dt.buffer,
dt.byteOffset + options.byteOffset,
Expand Down
8 changes: 6 additions & 2 deletions src/array/sized_array.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export class SizedArrayType<T> extends SizedType<T[]> implements ArrayType<T> {
return this.#inner.readPacked(dt, options);
}

read(dt: DataView, options: Options = { byteOffset: 0 }): T[] {
override read(dt: DataView, options: Options = { byteOffset: 0 }): T[] {
return this.#inner.read(dt, options);
}

Expand All @@ -25,7 +25,11 @@ export class SizedArrayType<T> extends SizedType<T[]> implements ArrayType<T> {
this.#inner.writePacked(value, dt, options);
}

write(value: T[], dt: DataView, options: Options = { byteOffset: 0 }): void {
override write(
value: T[],
dt: DataView,
options: Options = { byteOffset: 0 },
): void {
this.#inner.write(value, dt, options);
}
}
4 changes: 0 additions & 4 deletions src/array/typed_array.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,6 @@ export class TypedArray<T extends TypedArrays> extends SizedType<T> {
}

readPacked(dt: DataView, options: Options = { byteOffset: 0 }): T {
super.rangeCheck(dt.byteLength, options.byteOffset);

const value = new this.arrayConstructor(
dt.buffer,
dt.byteOffset + options.byteOffset,
Expand All @@ -56,8 +54,6 @@ export class TypedArray<T extends TypedArrays> extends SizedType<T> {
dt: DataView,
options: Options = { byteOffset: 0 },
): void {
super.rangeCheck(dt.byteLength, options.byteOffset);

const view = new this.arrayConstructor(
dt.buffer,
dt.byteOffset + options.byteOffset,
Expand Down
4 changes: 0 additions & 4 deletions src/bitflags/bitflags16.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@ export class BitFlags16<
}

readPacked(dt: DataView, options: Options = { byteOffset: 0 }): O {
super.rangeCheck(dt.byteLength, options.byteOffset);

const returnObject: Record<string, boolean> = {};

const byteBag = dt.getUint16(options.byteOffset);
Expand All @@ -32,8 +30,6 @@ export class BitFlags16<
dt: DataView,
options: Options = { byteOffset: 0 },
): void {
super.rangeCheck(dt.byteLength, options.byteOffset);

let flags = 0;

for (const { 0: key, 1: flagValue } of this.#recordEntries) {
Expand Down
4 changes: 0 additions & 4 deletions src/bitflags/bitflags32.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@ export class BitFlags32<
}

readPacked(dt: DataView, options: Options = { byteOffset: 0 }): O {
super.rangeCheck(dt.byteLength, options.byteOffset);

const returnObject: Record<string, boolean> = {};

const byteBag = dt.getUint32(options.byteOffset);
Expand All @@ -32,8 +30,6 @@ export class BitFlags32<
dt: DataView,
options: Options = { byteOffset: 0 },
): void {
super.rangeCheck(dt.byteLength, options.byteOffset);

let flags = 0;

for (const { 0: key, 1: flagValue } of this.#recordEntries) {
Expand Down
4 changes: 0 additions & 4 deletions src/bitflags/bitflags64.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@ export class BitFlags64<
}

readPacked(dt: DataView, options: Options = { byteOffset: 0 }): O {
super.rangeCheck(dt.byteLength, options.byteOffset);

const returnObject: Record<string, boolean> = {};

const byteBag = dt.getBigUint64(options.byteOffset);
Expand All @@ -32,8 +30,6 @@ export class BitFlags64<
dt: DataView,
options: Options = { byteOffset: 0 },
): void {
super.rangeCheck(dt.byteLength, options.byteOffset);

let flags = 0n;

for (const { 0: key, 1: flagValue } of this.#recordEntries) {
Expand Down
4 changes: 0 additions & 4 deletions src/bitflags/bitflags8.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@ export class BitFlags8<
}

readPacked(dt: DataView, options: Options = { byteOffset: 0 }): O {
super.rangeCheck(dt.byteLength, options.byteOffset);

const returnObject: Record<string, boolean> = {};

const byteBag = dt.getUint8(options.byteOffset);
Expand All @@ -32,8 +30,6 @@ export class BitFlags8<
dt: DataView,
options: Options = { byteOffset: 0 },
): void {
super.rangeCheck(dt.byteLength, options.byteOffset);

let flags = 0;

for (const { 0: key, 1: flagValue } of this.#recordEntries) {
Expand Down
8 changes: 6 additions & 2 deletions src/compound/sized_struct.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ export class SizedStruct<
return this.#readPacked(dt, options);
}

read(dt: DataView, options: Options = { byteOffset: 0 }): V {
override read(dt: DataView, options: Options = { byteOffset: 0 }): V {
return this.#read(dt, options);
}

Expand All @@ -78,7 +78,11 @@ export class SizedStruct<
this.#writePacked(dt, options, value);
}

write(value: V, dt: DataView, options: Options = { byteOffset: 0 }): void {
override write(
value: V,
dt: DataView,
options: Options = { byteOffset: 0 },
): void {
this.#write(dt, options, value);
}
}
8 changes: 6 additions & 2 deletions src/compound/struct.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export class Struct<
return result as V;
}

read(dt: DataView, options: Options = { byteOffset: 0 }): V {
override read(dt: DataView, options: Options = { byteOffset: 0 }): V {
if (this.#record.length === 0) return {} as V;

const result: Record<string, unknown> = {};
Expand All @@ -53,7 +53,11 @@ export class Struct<
}
}

write(value: V, dt: DataView, options: Options = { byteOffset: 0 }): void {
override write(
value: V,
dt: DataView,
options: Options = { byteOffset: 0 },
): void {
if (this.#record.length === 0) return;

for (let i = 0; i < this.#record.length; i++) {
Expand Down
4 changes: 2 additions & 2 deletions src/compound/tagged_union.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ export class TaggedUnion<
return codec.readPacked(dt, options) as V;
}

read(dt: DataView, options: Options = { byteOffset: 0 }): V {
override read(dt: DataView, options: Options = { byteOffset: 0 }): V {
const discriminant = this.#discriminant.read(dt, options);
super.alignOffset(options);
const codec = this.#record[discriminant];
Expand All @@ -73,7 +73,7 @@ export class TaggedUnion<
codec.writePacked(variant, dt, options);
}

write(
override write(
variant: V,
dt: DataView,
options: Options = { byteOffset: 0 },
Expand Down
8 changes: 6 additions & 2 deletions src/compound/tuple.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export class Tuple<
return result as V;
}

read(dt: DataView, options: Options = { byteOffset: 0 }): V {
override read(dt: DataView, options: Options = { byteOffset: 0 }): V {
if (this.#length === 0) return [] as unknown as V;
const result: unknown[] = new Array(this.#length);

Expand Down Expand Up @@ -55,7 +55,11 @@ export class Tuple<
}
}

write(value: V, dt: DataView, options: Options = { byteOffset: 0 }): void {
override write(
value: V,
dt: DataView,
options: Options = { byteOffset: 0 },
): void {
if (value.length !== this.#length) {
throw new TypeError(
`value V has more entries than expected\nExpected:${this.#length} but got ${value.length}`,
Expand Down
8 changes: 6 additions & 2 deletions src/compound/union.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ export class Union<
return codec.readPacked(dt, options) as V;
}

read(dt: DataView, options: Options = { byteOffset: 0 }): V {
override read(dt: DataView, options: Options = { byteOffset: 0 }): V {
const discriminant = this.#discriminant.read(dt, {
byteOffset: options.byteOffset,
});
Expand All @@ -58,7 +58,11 @@ export class Union<
codec.writePacked(variant, dt, options);
}

write(variant: V, dt: DataView, options: Options = { byteOffset: 0 }): void {
override write(
variant: V,
dt: DataView,
options: Options = { byteOffset: 0 },
): void {
const discriminant = this.#variantFinder(variant);
const codec = this.#record[discriminant];
if (!codec) throw new TypeError("Unknown discriminant");
Expand Down
6 changes: 1 addition & 5 deletions src/primitives/bool.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,7 @@ export class Bool extends SizedType<boolean> {
}

readPacked(dt: DataView, options: Options = { byteOffset: 0 }): boolean {
super.rangeCheck(dt.byteLength, options.byteOffset);

const value = Boolean(dt.getInt8(options.byteOffset));
const value = !!dt.getInt8(options.byteOffset);
super.incrementOffset(options);
return value;
}
Expand All @@ -18,8 +16,6 @@ export class Bool extends SizedType<boolean> {
dt: DataView,
options: Options = { byteOffset: 0 },
): void {
super.rangeCheck(dt.byteLength, options.byteOffset);

dt.setInt8(options.byteOffset, Number(value));
super.incrementOffset(options);
}
Expand Down
2 changes: 0 additions & 2 deletions src/primitives/f32.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ export class F32 extends SizedType<number> {
}

readPacked(dt: DataView, options: Options = { byteOffset: 0 }): number {
super.rangeCheck(dt.byteLength, options.byteOffset);
const value = dt.getFloat32(options.byteOffset, this.littleEndian);
super.incrementOffset(options);
return value;
Expand All @@ -18,7 +17,6 @@ export class F32 extends SizedType<number> {
dt: DataView,
options: Options = { byteOffset: 0 },
): void {
super.rangeCheck(dt.byteLength, options.byteOffset);
dt.setFloat32(options.byteOffset, value, this.littleEndian);
super.incrementOffset(options);
}
Expand Down
2 changes: 0 additions & 2 deletions src/primitives/f64.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ export class F64 extends SizedType<number> {
}

readPacked(dt: DataView, options: Options = { byteOffset: 0 }): number {
super.rangeCheck(dt.byteLength, options.byteOffset);
const value = dt.getFloat64(options.byteOffset, this.littleEndian);
super.incrementOffset(options);
return value;
Expand All @@ -18,7 +17,6 @@ export class F64 extends SizedType<number> {
dt: DataView,
options: Options = { byteOffset: 0 },
): void {
super.rangeCheck(dt.byteLength, options.byteOffset);
dt.setFloat64(options.byteOffset, value, this.littleEndian);
super.incrementOffset(options);
}
Expand Down
2 changes: 0 additions & 2 deletions src/primitives/i16.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ export class I16 extends SizedType<number> {
}

readPacked(dt: DataView, options: Options = { byteOffset: 0 }): number {
super.rangeCheck(dt.byteLength, options.byteOffset);
const value = dt.getInt16(options.byteOffset, this.littleEndian);
super.incrementOffset(options);
return value;
Expand All @@ -18,7 +17,6 @@ export class I16 extends SizedType<number> {
dt: DataView,
options: Options = { byteOffset: 0 },
): void {
super.rangeCheck(dt.byteLength, options.byteOffset);
dt.setInt16(options.byteOffset, value, this.littleEndian);
super.incrementOffset(options);
}
Expand Down
2 changes: 0 additions & 2 deletions src/primitives/i32.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ export class I32 extends SizedType<number> {
}

readPacked(dt: DataView, options: Options = { byteOffset: 0 }): number {
super.rangeCheck(dt.byteLength, options.byteOffset);
const value = dt.getInt32(options.byteOffset, this.littleEndian);
super.incrementOffset(options);
return value;
Expand All @@ -18,7 +17,6 @@ export class I32 extends SizedType<number> {
dt: DataView,
options: Options = { byteOffset: 0 },
): void {
super.rangeCheck(dt.byteLength, options.byteOffset);
dt.setInt32(options.byteOffset, value, this.littleEndian);
super.incrementOffset(options);
}
Expand Down
2 changes: 0 additions & 2 deletions src/primitives/i64.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ export class I64 extends SizedType<bigint> {
}

readPacked(dt: DataView, options: Options = { byteOffset: 0 }): bigint {
super.rangeCheck(dt.byteLength, options.byteOffset);
const value = dt.getBigInt64(options.byteOffset, this.littleEndian);
super.incrementOffset(options);
return value;
Expand All @@ -18,7 +17,6 @@ export class I64 extends SizedType<bigint> {
dt: DataView,
options: Options = { byteOffset: 0 },
): void {
super.rangeCheck(dt.byteLength, options.byteOffset);
dt.setBigInt64(options.byteOffset, value, this.littleEndian);
super.incrementOffset(options);
}
Expand Down
2 changes: 0 additions & 2 deletions src/primitives/i8.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ export class I8 extends SizedType<number> {
}

readPacked(dt: DataView, options: Options = { byteOffset: 0 }): number {
super.rangeCheck(dt.byteLength, options.byteOffset);
const value = dt.getInt8(options.byteOffset);
super.incrementOffset(options);
return value;
Expand All @@ -17,7 +16,6 @@ export class I8 extends SizedType<number> {
dt: DataView,
options: Options = { byteOffset: 0 },
): void {
super.rangeCheck(dt.byteLength, options.byteOffset);
dt.setInt8(options.byteOffset, value);
super.incrementOffset(options);
}
Expand Down
2 changes: 0 additions & 2 deletions src/primitives/u16.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ export class U16 extends SizedType<number> {
}

readPacked(dt: DataView, options: Options = { byteOffset: 0 }): number {
super.rangeCheck(dt.byteLength, options.byteOffset);
const value = dt.getUint16(options.byteOffset, this.littleEndian);
super.incrementOffset(options);
return value;
Expand All @@ -18,7 +17,6 @@ export class U16 extends SizedType<number> {
dt: DataView,
options: Options = { byteOffset: 0 },
): void {
super.rangeCheck(dt.byteLength, options.byteOffset);
dt.setUint16(options.byteOffset, value, this.littleEndian);
super.incrementOffset(options);
}
Expand Down
Loading

0 comments on commit 541df5b

Please sign in to comment.