Skip to content

Commit

Permalink
fix i64 bug
Browse files Browse the repository at this point in the history
  • Loading branch information
piloking committed Oct 13, 2024
1 parent 51da6c8 commit a003553
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
11 changes: 10 additions & 1 deletion packages/linejs/client/libs/thrift/read.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,15 @@ function isBinary(bin: Buffer) {
return bin.toString("base64") !== bin2.toString("base64");
}

function bigInt(bin: Buffer):number|bigint {
const str = bin.toString("hex");
const num = parseInt(str,16)
if (str!==num.toString(16)) {
return BigInt("0x"+str);
}
return num
}

function readValue(input: LooseType, ftype: LooseType): LooseType {
const Thrift = thrift.Thrift;
if (ftype == Thrift.Type.STRUCT) {
Expand Down Expand Up @@ -125,7 +134,7 @@ function TreadValue(input: LooseType, ftype: LooseType): LooseType {
} else if (ftype == Thrift.Type.I32) {
return input.readI32();
} else if (ftype == Thrift.Type.I64) {
return parseInt(input.readI64().buffer.toString("hex"), 16);
return bigInt(input.readI64().buffer);
} else if (ftype == Thrift.Type.STRING) {
return input.readString();
} else if (ftype == Thrift.Type.LIST) {
Expand Down
2 changes: 1 addition & 1 deletion packages/types/line_types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
*
* DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING
*/
type Int64 = number;
type Int64 = number|bigint;
import type { Buffer } from "node:buffer";

export enum ApplicationType {
Expand Down

0 comments on commit a003553

Please sign in to comment.