@@ -474,7 +474,7 @@ Connection.prototype.parseT = function(msg) {
474474 msg . fieldCount = this . parseInt16 ( ) ;
475475 var fields = [ ] ;
476476 for ( var i = 0 ; i < msg . fieldCount ; i ++ ) {
477- fields [ i ] = this . parseField ( ) ;
477+ fields . push ( this . parseField ( ) ) ;
478478 }
479479 msg . fields = fields ;
480480 return msg ;
@@ -498,7 +498,11 @@ Connection.prototype.parseD = function(msg) {
498498 var fields = [ ] ;
499499 for ( var i = 0 ; i < fieldCount ; i ++ ) {
500500 var length = this . parseInt32 ( ) ;
501- fields [ i ] = ( length === - 1 ? null : this . readBytes ( length ) ) ;
501+ var value = null ;
502+ if ( length !== - 1 ) {
503+ value = this . readBytes ( length ) ;
504+ }
505+ fields . push ( value ) ;
502506 }
503507 msg . fieldCount = fieldCount ;
504508 msg . fields = fields ;
@@ -553,49 +557,35 @@ Connection.prototype.parseA = function(msg) {
553557} ;
554558
555559Connection . prototype . parseGH = function ( msg ) {
556- msg . binary = Boolean ( this . parseInt8 ( ) ) ;
560+ var isBinary = this . buffer [ this . offset ] !== 0 ;
561+ this . offset ++ ;
562+ msg . binary = isBinary ;
557563 var columnCount = this . parseInt16 ( ) ;
558564 msg . columnTypes = [ ] ;
559565 for ( var i = 0 ; i < columnCount ; i ++ ) {
560- msg . columnTypes [ i ] = this . parseInt16 ( ) ;
566+ msg . columnTypes . push ( this . parseInt16 ( ) ) ;
561567 }
562568 return msg ;
563569} ;
564570
565- Connection . prototype . parseInt8 = function ( ) {
566- var value = Number ( this . buffer [ this . offset ] ) ;
567- this . offset ++ ;
568- return value ;
569- } ;
570-
571571Connection . prototype . readChar = function ( ) {
572572 return Buffer ( [ this . buffer [ this . offset ++ ] ] ) . toString ( this . encoding ) ;
573573} ;
574574
575575Connection . prototype . parseInt32 = function ( ) {
576- var value = this . peekInt32 ( ) ;
576+ var value = this . buffer . readInt32BE ( this . offset , true ) ;
577577 this . offset += 4 ;
578578 return value ;
579579} ;
580580
581- Connection . prototype . peekInt32 = function ( offset ) {
582- offset = offset || this . offset ;
583- var buffer = this . buffer ;
584- return ( ( buffer [ offset ++ ] << 24 ) +
585- ( buffer [ offset ++ ] << 16 ) +
586- ( buffer [ offset ++ ] << 8 ) +
587- buffer [ offset ++ ] ) ;
588- } ;
589-
590-
591581Connection . prototype . parseInt16 = function ( ) {
592- return ( ( this . buffer [ this . offset ++ ] << 8 ) +
593- ( this . buffer [ this . offset ++ ] << 0 ) ) ;
582+ var value = this . buffer . readInt16BE ( this . offset , true ) ;
583+ this . offset += 2 ;
584+ return value ;
594585} ;
595586
596587Connection . prototype . readString = function ( length ) {
597- return this . buffer . toString ( this . encoding , this . offset ,
598- ( this . offset += length ) ) ;
588+ return this . buffer . toString ( this . encoding , this . offset , ( this . offset += length ) ) ;
599589} ;
600590
601591Connection . prototype . readBytes = function ( length ) {
0 commit comments