|
|
|
@ -6,6 +6,8 @@ var util = require('util');
|
|
|
|
|
var utils = require(__dirname + '/utils');
|
|
|
|
|
var Writer = require('buffer-writer');
|
|
|
|
|
|
|
|
|
|
var TEXT_MODE = 0;
|
|
|
|
|
var BINARY_MODE = 1;
|
|
|
|
|
var Connection = function(config) {
|
|
|
|
|
EventEmitter.call(this);
|
|
|
|
|
config = config || {};
|
|
|
|
@ -19,6 +21,7 @@ var Connection = function(config) {
|
|
|
|
|
this.writer = new Writer();
|
|
|
|
|
this.ssl = config.ssl || false;
|
|
|
|
|
this._ending = false;
|
|
|
|
|
this._mode = TEXT_MODE;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
util.inherits(Connection, EventEmitter);
|
|
|
|
@ -488,8 +491,15 @@ Connection.prototype.parseField = function() {
|
|
|
|
|
dataTypeID: this.parseInt32(),
|
|
|
|
|
dataTypeSize: this.parseInt16(),
|
|
|
|
|
dataTypeModifier: this.parseInt32(),
|
|
|
|
|
format: this.parseInt16() === 0 ? 'text' : 'binary'
|
|
|
|
|
format: undefined
|
|
|
|
|
};
|
|
|
|
|
if(this.parseInt16() === TEXT_MODE) {
|
|
|
|
|
this._mode = TEXT_MODE;
|
|
|
|
|
field.format = 'text';
|
|
|
|
|
} else {
|
|
|
|
|
this._mode = BINARY_MODE;
|
|
|
|
|
field.format = 'binary';
|
|
|
|
|
}
|
|
|
|
|
return field;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
@ -500,7 +510,11 @@ Connection.prototype.parseD = function(msg) {
|
|
|
|
|
var length = this.parseInt32();
|
|
|
|
|
var value = null;
|
|
|
|
|
if(length !== -1) {
|
|
|
|
|
value = this.readBytes(length);
|
|
|
|
|
if(this._mode === TEXT_MODE) {
|
|
|
|
|
value = this.readString(length);
|
|
|
|
|
} else {
|
|
|
|
|
value = this.readBytes(length);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
fields.push(value);
|
|
|
|
|
}
|
|
|
|
@ -569,7 +583,7 @@ Connection.prototype.parseGH = function (msg) {
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
Connection.prototype.readChar = function() {
|
|
|
|
|
return Buffer([this.buffer[this.offset++]]).toString(this.encoding);
|
|
|
|
|
return this.readString(1);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
Connection.prototype.parseInt32 = function() {
|
|
|
|
@ -594,7 +608,7 @@ Connection.prototype.readBytes = function(length) {
|
|
|
|
|
|
|
|
|
|
Connection.prototype.parseCString = function() {
|
|
|
|
|
var start = this.offset;
|
|
|
|
|
while(this.buffer[this.offset++]) { }
|
|
|
|
|
while(this.buffer[this.offset++] !== 0) { }
|
|
|
|
|
return this.buffer.toString(this.encoding, start, this.offset - 1);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|