Skip to content

Commit

Permalink
fix: Strings not properly using offset (#10)
Browse files Browse the repository at this point in the history
  • Loading branch information
MierenManz authored Mar 15, 2023
1 parent 79b28d6 commit 90cc9a8
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
2 changes: 1 addition & 1 deletion types/array/array.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,6 @@ export class ArrayType<T> implements SizedType<T[]>, ViewableType<T[]> {
});
}

return array as T[];
return array;
}
}
12 changes: 10 additions & 2 deletions types/string/fixed_length.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,22 @@ export class FixedLengthString implements SizedType<string> {

read(dataView: DataView, byteOffset = 0): string {
return decoder.decode(
new Uint8Array(dataView.buffer, byteOffset, byteOffset + this.byteLength),
new Uint8Array(
dataView.buffer,
dataView.byteOffset + byteOffset,
this.byteLength - byteOffset,
),
);
}

write(value: string, dataView: DataView, byteOffset = 0) {
encoder.encodeInto(
value,
new Uint8Array(dataView.buffer, byteOffset, this.byteLength),
new Uint8Array(
dataView.buffer,
dataView.byteOffset + byteOffset,
this.byteLength - byteOffset,
),
);
}
}

0 comments on commit 90cc9a8

Please sign in to comment.