Skip to content

Commit

Permalink
ditto
Browse files Browse the repository at this point in the history
  • Loading branch information
MierenManz committed Jan 9, 2024
1 parent cb0201e commit dae1d17
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
8 changes: 4 additions & 4 deletions src/bitflags/bitflags32.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ export class BitFlags32<
I extends Record<string, number>,
O = OutputRecord<I>,
> extends SizedType<O> {
#record: I;
#recordEntries: Array<[string, number]>;

constructor(record: I) {
super(4, 4);
this.#record = record;
this.#recordEntries = Object.entries(record);
}

readPacked(dt: DataView, options: Options = { byteOffset: 0 }): O {
Expand All @@ -18,7 +18,7 @@ export class BitFlags32<
const returnObject: Record<string, boolean> = {};

const byteBag = dt.getUint32(options.byteOffset);
for (const { 0: key, 1: flag } of Object.entries(this.#record)) {
for (const { 0: key, 1: flag } of this.#recordEntries) {
returnObject[key] = (byteBag & flag) === flag;
}

Expand All @@ -36,7 +36,7 @@ export class BitFlags32<

let flags = 0;

for (const { 0: key, 1: flagValue } of Object.entries(this.#record)) {
for (const { 0: key, 1: flagValue } of this.#recordEntries) {
if (value[key as keyof O]) {
flags |= flagValue;
}
Expand Down
8 changes: 4 additions & 4 deletions src/bitflags/bitflags64.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ export class BitFlags64<
I extends Record<string, bigint>,
O = OutputRecord<I>,
> extends SizedType<O> {
#record: I;
#recordEntries: Array<[string, bigint]>;

constructor(record: I) {
super(8, 8);
this.#record = record;
this.#recordEntries = Object.entries(record);
}

readPacked(dt: DataView, options: Options = { byteOffset: 0 }): O {
Expand All @@ -18,7 +18,7 @@ export class BitFlags64<
const returnObject: Record<string, boolean> = {};

const byteBag = dt.getBigUint64(options.byteOffset);
for (const { 0: key, 1: flag } of Object.entries(this.#record)) {
for (const { 0: key, 1: flag } of this.#recordEntries) {
returnObject[key] = (byteBag & flag) === flag;
}

Expand All @@ -36,7 +36,7 @@ export class BitFlags64<

let flags = 0n;

for (const { 0: key, 1: flagValue } of Object.entries(this.#record)) {
for (const { 0: key, 1: flagValue } of this.#recordEntries) {
if (value[key as keyof O]) {
flags |= flagValue;
}
Expand Down

0 comments on commit dae1d17

Please sign in to comment.