mirror of
https://github.com/brianc/node-postgres.git
synced 2025-12-08 20:16:25 +00:00
parsing notificationResponse messages
This commit is contained in:
parent
6b3fb4aa02
commit
16352f9156
@ -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);
|
||||
};
|
||||
|
||||
@ -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;
|
||||
|
||||
@ -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() {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user