Skip to content
This repository has been archived by the owner on Feb 4, 2022. It is now read-only.

Commit

Permalink
feat(OP_MSG): add in parsing of OP_MSG
Browse files Browse the repository at this point in the history
  • Loading branch information
daprahamian authored and mbroadst committed Feb 12, 2019
1 parent 11e4132 commit c310a83
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions lib/connection/connection.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,11 @@ var inherits = require('util').inherits,
parseHeader = require('../wireprotocol/shared').parseHeader,
decompress = require('../wireprotocol/compression').decompress,
Response = require('./commands').Response,
BinMsg = require('./msg').BinMsg,
MongoNetworkError = require('../error').MongoNetworkError,
Logger = require('./logger'),
OP_COMPRESSED = require('../wireprotocol/shared').opcodes.OP_COMPRESSED,
OP_MSG = require('../wireprotocol/shared').opcodes.OP_MSG,
MESSAGE_HEADER_SIZE = require('../wireprotocol/shared').MESSAGE_HEADER_SIZE,
Buffer = require('safe-buffer').Buffer;

Expand Down Expand Up @@ -301,14 +303,22 @@ var emitMessageHandler = function(self, message) {
'Decompressing a compressed message from the server failed. The message is corrupt.'
);
}
const ResponseConstructor = msgHeader.opCode === OP_MSG ? BinMsg : Response;
self.messageHandler(
new Response(self.bson, message, msgHeader, decompressedMsgBody, self.responseOptions),
new ResponseConstructor(
self.bson,
message,
msgHeader,
decompressedMsgBody,
self.responseOptions
),
self
);
});
} else {
const ResponseConstructor = msgHeader.opCode === OP_MSG ? BinMsg : Response;
self.messageHandler(
new Response(
new ResponseConstructor(
self.bson,
message,
msgHeader,
Expand Down

0 comments on commit c310a83

Please sign in to comment.