Skip to content

Commit

Permalink
Adding unsigned smart support to ByteBuffer
Browse files Browse the repository at this point in the history
  • Loading branch information
Tynarus committed Jan 26, 2021
1 parent aa9b4bc commit 5781707
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 6 deletions.
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@runejs/core",
"version": "1.0.1",
"version": "1.1.0",
"description": "Core logging and networking functionality for RuneJS applications.",
"main": "dist/index.js",
"types": "dist/index.d.ts",
Expand Down
8 changes: 4 additions & 4 deletions src/buffer/byte-buffer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ export class ByteBuffer extends Uint8Array {
const readerIndex = this._readerIndex;

if(type === 'SMART') {
return this.getSmart(readerIndex);
return this.getSmart(readerIndex, signed);
} else {
let size = SIZES[type];
let signedChar = signed === 'SIGNED' ? '' : 'U';
Expand Down Expand Up @@ -189,13 +189,13 @@ export class ByteBuffer extends Uint8Array {
}
}

private getSmart(offset: number): number {
private getSmart(offset: number, signed: Signedness = 'SIGNED'): number {
const peek = this[offset];

if(peek < 128) {
return this.get('BYTE', 'UNSIGNED');
return this.get('BYTE', 'UNSIGNED') - (signed === 'SIGNED' ? 0 : 64);
} else {
return this.get('SHORT', 'UNSIGNED') - 32768;
return this.get('SHORT', 'UNSIGNED') - (signed === 'SIGNED' ? 32768 : 49152);
}
}

Expand Down

0 comments on commit 5781707

Please sign in to comment.