11const { PartialReadError } = require ( '../utils' )
22
3- class BigIntExtended extends Array {
3+ class SignedBigInt extends Array {
44 valueOf ( ) { return BigInt . asIntN ( 64 , BigInt ( this [ 0 ] ) << 32n ) | BigInt . asUintN ( 32 , BigInt ( this [ 1 ] ) ) }
5+ toString ( ) { return this . valueOf ( ) . toString ( ) }
6+ [ Symbol . for ( 'nodejs.util.inspect.custom' ) ] ( ) { return this . valueOf ( ) }
7+ }
8+
9+ class UnsignedBigInt extends Array {
10+ valueOf ( ) { return BigInt . asUintN ( 64 , BigInt ( this [ 0 ] ) << 32n ) | BigInt . asUintN ( 32 , BigInt ( this [ 1 ] ) ) }
11+ toString ( ) { return this . valueOf ( ) . toString ( ) }
512 [ Symbol . for ( 'nodejs.util.inspect.custom' ) ] ( ) { return this . valueOf ( ) }
613}
714
815function readI64 ( buffer , offset ) {
916 if ( offset + 8 > buffer . length ) { throw new PartialReadError ( ) }
1017 return {
11- value : new BigIntExtended ( buffer . readInt32BE ( offset ) , buffer . readInt32BE ( offset + 4 ) ) ,
18+ value : new SignedBigInt ( buffer . readInt32BE ( offset ) , buffer . readInt32BE ( offset + 4 ) ) ,
1219 size : 8
1320 }
1421}
@@ -26,7 +33,7 @@ function writeI64 (value, buffer, offset) {
2633function readLI64 ( buffer , offset ) {
2734 if ( offset + 8 > buffer . length ) { throw new PartialReadError ( ) }
2835 return {
29- value : new BigIntExtended ( buffer . readInt32LE ( offset + 4 ) , buffer . readInt32LE ( offset ) ) ,
36+ value : new SignedBigInt ( buffer . readInt32LE ( offset + 4 ) , buffer . readInt32LE ( offset ) ) ,
3037 size : 8
3138 }
3239}
@@ -44,7 +51,7 @@ function writeLI64 (value, buffer, offset) {
4451function readU64 ( buffer , offset ) {
4552 if ( offset + 8 > buffer . length ) { throw new PartialReadError ( ) }
4653 return {
47- value : new BigIntExtended ( buffer . readUInt32BE ( offset ) , buffer . readUInt32BE ( offset + 4 ) ) ,
54+ value : new UnsignedBigInt ( buffer . readUInt32BE ( offset ) , buffer . readUInt32BE ( offset + 4 ) ) ,
4855 size : 8
4956 }
5057}
@@ -62,7 +69,7 @@ function writeU64 (value, buffer, offset) {
6269function readLU64 ( buffer , offset ) {
6370 if ( offset + 8 > buffer . length ) { throw new PartialReadError ( ) }
6471 return {
65- value : new BigIntExtended ( buffer . readUInt32LE ( offset + 4 ) , buffer . readUInt32LE ( offset ) ) ,
72+ value : new UnsignedBigInt ( buffer . readUInt32LE ( offset + 4 ) , buffer . readUInt32LE ( offset ) ) ,
6673 size : 8
6774 }
6875}
0 commit comments