@@ -477,7 +477,7 @@ Connection.prototype.parseT = function(msg) {
477
477
msg . fieldCount = this . parseInt16 ( ) ;
478
478
var fields = [ ] ;
479
479
for ( var i = 0 ; i < msg . fieldCount ; i ++ ) {
480
- fields [ i ] = this . parseField ( ) ;
480
+ fields . push ( this . parseField ( ) ) ;
481
481
}
482
482
msg . fields = fields ;
483
483
return msg ;
@@ -501,7 +501,11 @@ Connection.prototype.parseD = function(msg) {
501
501
var fields = [ ] ;
502
502
for ( var i = 0 ; i < fieldCount ; i ++ ) {
503
503
var length = this . parseInt32 ( ) ;
504
- fields [ i ] = ( length === - 1 ? null : this . readBytes ( length ) ) ;
504
+ var value = null ;
505
+ if ( length !== - 1 ) {
506
+ value = this . readBytes ( length ) ;
507
+ }
508
+ fields . push ( value ) ;
505
509
}
506
510
msg . fieldCount = fieldCount ;
507
511
msg . fields = fields ;
@@ -556,49 +560,35 @@ Connection.prototype.parseA = function(msg) {
556
560
} ;
557
561
558
562
Connection . prototype . parseGH = function ( msg ) {
559
- msg . binary = Boolean ( this . parseInt8 ( ) ) ;
563
+ var isBinary = this . buffer [ this . offset ] !== 0 ;
564
+ this . offset ++ ;
565
+ msg . binary = isBinary ;
560
566
var columnCount = this . parseInt16 ( ) ;
561
567
msg . columnTypes = [ ] ;
562
568
for ( var i = 0 ; i < columnCount ; i ++ ) {
563
- msg . columnTypes [ i ] = this . parseInt16 ( ) ;
569
+ msg . columnTypes . push ( this . parseInt16 ( ) ) ;
564
570
}
565
571
return msg ;
566
572
} ;
567
573
568
- Connection . prototype . parseInt8 = function ( ) {
569
- var value = Number ( this . buffer [ this . offset ] ) ;
570
- this . offset ++ ;
571
- return value ;
572
- } ;
573
-
574
574
Connection . prototype . readChar = function ( ) {
575
575
return Buffer ( [ this . buffer [ this . offset ++ ] ] ) . toString ( this . encoding ) ;
576
576
} ;
577
577
578
578
Connection . prototype . parseInt32 = function ( ) {
579
- var value = this . peekInt32 ( ) ;
579
+ var value = this . buffer . readInt32BE ( this . offset , true ) ;
580
580
this . offset += 4 ;
581
581
return value ;
582
582
} ;
583
583
584
- Connection . prototype . peekInt32 = function ( offset ) {
585
- offset = offset || this . offset ;
586
- var buffer = this . buffer ;
587
- return ( ( buffer [ offset ++ ] << 24 ) +
588
- ( buffer [ offset ++ ] << 16 ) +
589
- ( buffer [ offset ++ ] << 8 ) +
590
- buffer [ offset ++ ] ) ;
591
- } ;
592
-
593
-
594
584
Connection . prototype . parseInt16 = function ( ) {
595
- return ( ( this . buffer [ this . offset ++ ] << 8 ) +
596
- ( this . buffer [ this . offset ++ ] << 0 ) ) ;
585
+ var value = this . buffer . readInt16BE ( this . offset , true ) ;
586
+ this . offset += 2 ;
587
+ return value ;
597
588
} ;
598
589
599
590
Connection . prototype . readString = function ( length ) {
600
- return this . buffer . toString ( this . encoding , this . offset ,
601
- ( this . offset += length ) ) ;
591
+ return this . buffer . toString ( this . encoding , this . offset , ( this . offset += length ) ) ;
602
592
} ;
603
593
604
594
Connection . prototype . readBytes = function ( length ) {
0 commit comments