parsing notificationResponse messages

This commit is contained in:
brianc 2010-10-23 22:31:43 -05:00
parent 6b3fb4aa02
commit 16352f9156
3 changed files with 26 additions and 1 deletions

View File

@ -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);
};

View File

@ -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;

View File

@ -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() {