Skip to content

Commit

Permalink
readIntOrUndefined bug fix
Browse files Browse the repository at this point in the history
  • Loading branch information
rylorin committed Jun 13, 2024
1 parent ad5268d commit ce0d948
Showing 1 changed file with 6 additions and 13 deletions.
19 changes: 6 additions & 13 deletions src/core/io/decoder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -460,7 +460,7 @@ export class Decoder {
* Read a token from queue and return it as boolean value.
*/
readBool(): boolean {
return parseInt(this.readStr()) != 0;
return parseInt(this.readStr(), 10) != 0;
}

/**
Expand Down Expand Up @@ -510,15 +510,14 @@ export class Decoder {
* Read a token from queue and return it as integer value.
*
* Returns 0 if the token is empty.
* Returns undefined is the token is Number.MAX_VALUE.
*/
readInt(): number | undefined {
readInt(): number {
const token = this.readStr();
if (!token || token === "") {
return 0;
}
const val = parseInt(token, 10);
return val === Number.MAX_VALUE ? undefined : val;
return val;
}

/**
Expand All @@ -527,26 +526,20 @@ export class Decoder {
* Returns Number.MAX_VALUE if the token is empty.
* @deprecated readIntOrUndefined is probably what you are looking for
*/
readIntMax(): number {
const token = this.readStr();
if (!token || token === "") {
return Number.MAX_VALUE;
}
return parseInt(token, 10);
}
readIntMax = this.readIntOrUndefined;

/**
* Read a token from queue and return it as integer value.
*
* Returns undefined if the token is empty or Number.MAX_VALUE.
* Returns undefined if the token is empty or `2147483647`.
*/
readIntOrUndefined(): number | undefined {
const token = this.readStr();
if (!token || token === "") {
return undefined;
}
const val = parseInt(token, 10);
return val === Number.MAX_VALUE ? undefined : val;
return val === 2147483647 ? undefined : val;
}

/**
Expand Down

0 comments on commit ce0d948

Please sign in to comment.