refactored parsing

This commit is contained in:
brianc 2010-09-30 00:27:56 -05:00
parent 124bd0960e
commit 8c30521cf9

View File

@ -95,43 +95,36 @@ p.parseR = function() {
};
p.parseS = function(buffer) {
var type = this.buffer[this.offset++];
var length = this.parseLength(this.buffer);
var parameterName = this.parseCString();
var parameterValue = this.parseCString();
return {
name: 'ParameterStatus',
id: 'S',
length: length,
parameterName: parameterName,
parameterValue: parameterValue
}
var msg = this.parseStart('ParameterStatus');
msg.parameterName = this.parseCString();
msg.parameterValue = this.parseCString();
return msg;
};
p.parseK = function() {
var type = this.buffer[this.offset++];
var length = this.readInt32();
var processID = this.readInt32();
var secretKey = this.readInt32();
var msg = this.parseStart('BackendKeyData');
msg.processID = this.readInt32();
msg.secretKey = this.readInt32();
return msg;
};
//parses common start of message packets
p.parseStart = function(name) {
return {
name: 'BackendKeyData',
id: 'K',
length: length,
processID: processID,
secretKey: secretKey
name: name,
id: this.readChar(),
length: this.readInt32()
}
};
p.readChar = function() {
return Buffer([this.buffer[this.offset++]]).toString('utf8');
};
p.parseZ = function() {
var type = this.buffer[this.offset++];
var length = this.readInt32();
var status = this.buffer[this.offset++];
return {
name: 'ReadyForQuery',
id: 'Z',
length: length,
status: Buffer([status]).toString('utf8')
}
var msg = this.parseStart('ReadyForQuery');
msg.status = this.readChar();
return msg;
};
p.readInt32 = function() {