can read single data row of text

This commit is contained in:
brianc 2010-10-01 01:02:52 -05:00
parent 5cf151ad7a
commit ab0076aa68
2 changed files with 30 additions and 3 deletions

View File

@ -212,7 +212,14 @@ p.parseField = function() {
p.parseD = function() {
var msg = this.parseStart('DataRow');
msg.fieldCount = this.readInt16();
var fieldCount = this.readInt16();
var fields = [];
for(var i = 0; i < fieldCount; i++) {
fields[i] = this.readString(this.readInt32());
};
msg.fieldCount = fieldCount;
msg.fields = fields;
return msg;
};
p.readInt32 = function() {
@ -231,7 +238,11 @@ p.parseLength = function() {
return this.readInt32();
};
p.parseCString = function(buffer) {
p.readString = function(length) {
return this.buffer.toString('utf8', this.offset, (this.offset += length));
};
p.parseCString = function() {
var start = this.offset;
while(this.buffer[this.offset++]) { };
return this.buffer.toString('utf8',start, this.offset - 1);

View File

@ -184,13 +184,29 @@ test('Parser on single messages', function() {
});
test('parses raw data row buffers', function() {
var emptyRow = new BufferList()
.addInt16(0)
.join(true, 'D');
test('parses empty data row', function() {
var result = PARSE(emptyRow)[0];
assert.equal(result.columnCount, 0);
assert.equal(result.fieldCount, 0);
assert.equal(result.fields.length, 0);
});
var oneField = new BufferList()
.addInt16(1) //number of fields
.addInt32(5) //length of bytes of fields
.addCString('test')
.join(true, 'D');
test('parses single field data row', function() {
var result = PARSE(oneField)[0];
assert.equal(result.fieldCount, 1);
assert.equal(result.fields[0], "test\0");
});
});
test('parsing empty buffer returns false', function() {