parsing the most simplistic error message

This commit is contained in:
brianc 2010-10-10 17:48:27 -05:00
parent 61ff6055b7
commit b4d1c67eb5
4 changed files with 30 additions and 3 deletions

View File

@ -3,7 +3,7 @@ var sys = require('sys');
var net = require('net');
var NUL = '\0';
var chars = ['R','S','K','Z','Q','C','T','D','X'];
var chars = ['R','S','K','Z','Q','C','T','D','X','E'];
var charBuff = Buffer(chars.join(''),'utf8');
var UTF8 = {};
for(var i = 0; i < charBuff.length; i++){
@ -154,6 +154,8 @@ p.parseMessage = function() {
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) + ")");
}
@ -248,6 +250,15 @@ p.parseD = function() {
return msg;
};
p.parseE = function() {
var msg = this.parseStart('Error');
var fieldType = this.readString(1);
if(fieldType == '\0') {
return msg;
}
};
p.readInt32 = function() {
var buffer = this.buffer;
return ((buffer[this.offset++] << 24) +

View File

@ -36,6 +36,7 @@ test('using closed stream', function() {
test('after stream connects', function() {
stream.emit('connect');
//TODO - test more of the connection packets
});
});

View File

@ -192,7 +192,7 @@ test('Client', function() {
format: 'text'
});
});
});
test('parsing rows', function() {
@ -222,6 +222,12 @@ test('Client', function() {
});
});
test('error messages', function() {
testForMessage(buffers.error(),{
name: 'Error'
});
});
});

View File

@ -65,7 +65,16 @@ buffers.dataRow = function(columns) {
return buf.join(true, 'D');
};
buffers.error = function(fields) {
fields = fields || [];
var buf = new BufferList();
fields.forEach(function(field) {
buf.addChar(field.type);
buf.addCString(field.value);
});
buf.add(Buffer([0]));//terminator
return buf.join(true, 'E');
};