From 16352f9156e62595d20894ce3e6d681aa1d62fdd Mon Sep 17 00:00:00 2001 From: brianc Date: Sat, 23 Oct 2010 22:31:43 -0500 Subject: [PATCH] parsing notificationResponse messages --- lib/connection.js | 10 +++++++++- test/test-buffers.js | 8 ++++++++ test/unit/connection/inbound-parser-tests.js | 9 +++++++++ 3 files changed, 26 insertions(+), 1 deletion(-) diff --git a/lib/connection.js b/lib/connection.js index debbb037..622b3251 100644 --- a/lib/connection.js +++ b/lib/connection.js @@ -171,7 +171,8 @@ var messageNames = { D: 'dataRow', E: 'error', 1: 'parseComplete', - 2: 'bindComplete' + 2: 'bindComplete', + A: 'notificationResponse' }; p.parseMessage = function() { @@ -314,6 +315,13 @@ p.parse2 = function(msg) { return msg; }; +p.parseA = function(msg) { + msg.processId = this.parseInt32(); + msg.channel = this.parseCString(); + msg.message = this.parseCString(); + return msg; +}; + p.readChar = function() { return Buffer([this.buffer[this.offset++]]).toString(this.encoding); }; diff --git a/test/test-buffers.js b/test/test-buffers.js index 53b23eff..ca4c27b5 100644 --- a/test/test-buffers.js +++ b/test/test-buffers.js @@ -98,4 +98,12 @@ buffers.bindComplete = function() { return new BufferList().join(true, '2'); }; +buffers.notificationResponse = function(id, channel, message) { + return new BufferList() + .addInt32(id) + .addCString(channel) + .addCString(message) + .join(true, 'A') +}; + module.exports = buffers; diff --git a/test/unit/connection/inbound-parser-tests.js b/test/unit/connection/inbound-parser-tests.js index a90cadc1..46013be7 100644 --- a/test/unit/connection/inbound-parser-tests.js +++ b/test/unit/connection/inbound-parser-tests.js @@ -153,6 +153,14 @@ var expectedMD5PasswordMessage = { name: 'authenticationMD5Password' }; +var notificationResponseBuffer = buffers.notificationResponse(4, 'hi', 'boom'); +var expectedNotificationResponseMessage = { + id: 'A', + processId: 4, + channel: 'hi', + message: 'boom' +}; + test('Connection', function() { testForMessage(authOkBuffer, expectedAuthenticationOkayMessage); testForMessage(plainPasswordBuffer, expectedPlainPasswordMessage); @@ -164,6 +172,7 @@ test('Connection', function() { testForMessage(backendKeyDataBuffer, expectedBackendKeyDataMessage); testForMessage(readyForQueryBuffer, expectedReadyForQueryMessage); testForMessage(commandCompleteBuffer,expectedCommandCompleteMessage); + testForMessage(notificationResponseBuffer, expectedNotificationResponseMessage); test('empty row message', function() { var message = testForMessage(emptyRowDescriptionBuffer, expectedEmptyRowDescriptionMessage); test('has no fields', function() {