Skip to content
This repository has been archived by the owner on Oct 31, 2021. It is now read-only.

Commit

Permalink
isolated parseHeader into own function
Browse files Browse the repository at this point in the history
  • Loading branch information
tenorviol committed Jul 1, 2011
1 parent 70c2b68 commit f6aa8bf
Showing 1 changed file with 18 additions and 12 deletions.
30 changes: 18 additions & 12 deletions lib/mongodb-socket.js
Expand Up @@ -22,27 +22,33 @@ function createServer(callback) {


function parseMessage(data) {
var message = {
header : {}
};
var message = {};

var offset = 0;
message.header.messageLength = BinaryParser.toInt(data.substr(offset, 4));
offset += 4;
message.header.requestID = BinaryParser.toInt(data.substr(offset, 4));
offset += 4;
message.header.responseTo = BinaryParser.toInt(data.substr(offset, 4));
offset += 4;
message.header.opCode = BinaryParser.toInt(data.substr(offset, 4));
offset += 4;
var header = message.header = parseHeader(data, offset);
offset += 16;

switch (message.header.opCode) {
switch (header.opCode) {
case 2004:
return parseQuery(message, data, offset);
}

return message;
}

function parseHeader(data, offset) {
var header = {};
header.messageLength = BinaryParser.toInt(data.substr(offset, 4));
offset += 4;
header.requestID = BinaryParser.toInt(data.substr(offset, 4));
offset += 4;
header.responseTo = BinaryParser.toInt(data.substr(offset, 4));
offset += 4;
header.opCode = BinaryParser.toInt(data.substr(offset, 4));
offset += 4;
return header;
}

function parseQuery(message, data, offset) {
message.flags = BinaryParser.toInt(data.substr(offset, 4));
offset += 4;
Expand Down

0 comments on commit f6aa8bf

Please sign in to comment.