From 32d6fd411500124553821f522a8ec423d9dbe80c Mon Sep 17 00:00:00 2001 From: brianc Date: Sun, 10 Oct 2010 19:03:44 -0500 Subject: [PATCH] removed switch statement --- lib/index.js | 45 +++++++++++++++++---------------------------- 1 file changed, 17 insertions(+), 28 deletions(-) diff --git a/lib/index.js b/lib/index.js index 0f950dd4..a712ab37 100644 --- a/lib/index.js +++ b/lib/index.js @@ -139,29 +139,11 @@ p.parseMessage = function() { return false; } var messageID = this.buffer[this.offset]; - switch(messageID) { - case UTF8.R: - return this.parseR(); - case UTF8.S: - return this.parseS(); - case UTF8.K: - return this.parseK(); - case UTF8.Z: - return this.parseZ(); - case UTF8.C: - return this.parseC(); - case UTF8.T: - return this.parseT(); - case UTF8.D: - return this.parseD(); - case UTF8.E: - return this.parseE(); - default: - throw new Error("Unsupported message ID: " + Buffer([messageID]).toString('utf8') + " (" + messageID.toString(16) + ")"); - } + return this["parse"+messageID](); }; -p.parseR = function() { +//parse 'R' message +p.parse82 = function() { var type = this.buffer[this.offset++]; var length = this.parseLength(); if(length == 8) { @@ -175,21 +157,24 @@ p.parseR = function() { throw new Error("Unknown AuthenticatinOk message type"); }; -p.parseS = function(buffer) { +//parse 'S' message +p.parse83 = function(buffer) { var msg = this.parseStart('ParameterStatus'); msg.parameterName = this.parseCString(); msg.parameterValue = this.parseCString(); return msg; }; -p.parseK = function() { +//parse 'K' message +p.parse75 = function() { var msg = this.parseStart('BackendKeyData'); msg.processID = this.readInt32(); msg.secretKey = this.readInt32(); return msg; }; -p.parseC = function() { +//parse 'C' message +p.parse67 = function() { var msg = this.parseStart('CommandComplete'); msg.text = this.parseCString(); return msg; @@ -208,13 +193,15 @@ p.readChar = function() { return Buffer([this.buffer[this.offset++]]).toString('utf8'); }; -p.parseZ = function() { +//parse 'Z' message +p.parse90 = function() { var msg = this.parseStart('ReadyForQuery'); msg.status = this.readChar(); return msg; }; -p.parseT = function() { +//parse 'T' message +p.parse84 = function() { var msg = this.parseStart('RowDescription'); msg.fieldCount = this.readInt16(); var fields = []; @@ -238,7 +225,8 @@ p.parseField = function() { return row; }; -p.parseD = function() { +//parse 'D' message +p.parse68 = function() { var msg = this.parseStart('DataRow'); var fieldCount = this.readInt16(); var fields = []; @@ -250,7 +238,8 @@ p.parseD = function() { return msg; }; -p.parseE = function() { +//parse 'E' message +p.parse69 = function() { var msg = this.parseStart('Error'); var fields = {}; var fieldType = this.readString(1);