11import Debug from '../debug' ;
22import { InternalConnectionOptions } from '../connection' ;
3+ import JSBI from 'jsbi' ;
34
45const Transform = require ( 'readable-stream' ) . Transform ;
56import { TYPE , Token , EndOfMessageToken , ColMetadataToken } from './token' ;
@@ -212,6 +213,32 @@ class Parser extends Transform {
212213 } ) ;
213214 }
214215
216+ readBigInt64LE ( callback : ( data : JSBI ) => void ) {
217+ this . awaitData ( 8 , ( ) => {
218+ const result = JSBI . add (
219+ JSBI . leftShift (
220+ JSBI . BigInt (
221+ this . buffer [ this . position + 4 ] +
222+ this . buffer [ this . position + 5 ] * 2 ** 8 +
223+ this . buffer [ this . position + 6 ] * 2 ** 16 +
224+ ( this . buffer [ this . position + 7 ] << 24 ) // Overflow
225+ ) ,
226+ JSBI . BigInt ( 32 )
227+ ) ,
228+ JSBI . BigInt (
229+ this . buffer [ this . position ] +
230+ this . buffer [ this . position + 1 ] * 2 ** 8 +
231+ this . buffer [ this . position + 2 ] * 2 ** 16 +
232+ this . buffer [ this . position + 3 ] * 2 ** 24
233+ )
234+ ) ;
235+
236+ this . position += 8 ;
237+
238+ callback ( result ) ;
239+ } ) ;
240+ }
241+
215242 readInt64LE ( callback : ( data : number ) => void ) {
216243 this . awaitData ( 8 , ( ) => {
217244 const data = Math . pow ( 2 , 32 ) * this . buffer . readInt32LE ( this . position + 4 ) + ( ( this . buffer [ this . position + 4 ] & 0x80 ) === 0x80 ? 1 : - 1 ) * this . buffer . readUInt32LE ( this . position ) ;
@@ -228,6 +255,17 @@ class Parser extends Transform {
228255 } ) ;
229256 }
230257
258+ readBigUInt64LE ( callback : ( data : JSBI ) => void ) {
259+ this . awaitData ( 8 , ( ) => {
260+ const low = JSBI . BigInt ( this . buffer . readUInt32LE ( this . position ) ) ;
261+ const high = JSBI . BigInt ( this . buffer . readUInt32LE ( this . position + 4 ) ) ;
262+
263+ this . position += 8 ;
264+
265+ callback ( JSBI . add ( low , JSBI . leftShift ( high , JSBI . BigInt ( 32 ) ) ) ) ;
266+ } ) ;
267+ }
268+
231269 readUInt64LE ( callback : ( data : number ) => void ) {
232270 this . awaitData ( 8 , ( ) => {
233271 const data = Math . pow ( 2 , 32 ) * this . buffer . readUInt32LE ( this . position + 4 ) + this . buffer . readUInt32LE ( this . position ) ;
0 commit comments