Browse files

[fix] requestId support

  • Loading branch information...
1 parent 422585f commit 3eef881fa73e72fa3817d28633b1f005491b371a @marcello3d committed Dec 19, 2011
Showing with 14 additions and 11 deletions.
  1. +14 −11 lib/mongo.js
View
25 lib/mongo.js
@@ -54,14 +54,17 @@ exports.RESPONSE_AWAIT_CAPABLE = 4<<0
// int32 op code
// command
-function writeHeader(buffer, offset, size, requestId, opCode) {
- offset = binary.writeInt(buffer, 0, size)
- offset = binary.writeInt(buffer, 4, requestId)
- offset = binary.writeInt(buffer, 8, 0)
- offset = binary.writeInt(buffer, 12, opCode)
+function writeHeader(buffer, offset, size, opCode) {
+ offset = binary.writeInt(buffer, offset, size)
+ offset = binary.writeInt(buffer, offset, 0)
+ offset = binary.writeInt(buffer, offset, 0)
+ offset = binary.writeInt(buffer, offset, opCode)
return offset
}
+exports.setRequestId = function(buffer, requestId) {
+ binary.writeInt(buffer, 4, requestId)
+}
// MsgHeader header; // standard message header
// int32 ZERO; // 0 - reserved for future use
@@ -81,7 +84,7 @@ exports.serializeUpdate = function(fullCollectionName, spec, document, upsert, m
documentSize
var buffer = new Buffer(size)
- var offset = writeHeader(buffer, 0, size, 0, OP_UPDATE)
+ var offset = writeHeader(buffer, 0, size, OP_UPDATE)
offset = binary.writeInt(buffer, offset, 0) // bson spec: 0 reserved for future use
offset = binary.writeCString(buffer, offset, fullCollectionName)
var flags = (upsert ? DB_UPSERT : 0) |
@@ -111,7 +114,7 @@ exports.serializeInsert = function(fullCollectionName, documents, continueOnErro
}
var buffer = new Buffer(size)
- var offset = writeHeader(buffer, 0, size, 0, OP_INSERT)
+ var offset = writeHeader(buffer, 0, size, OP_INSERT)
offset = binary.writeInt(buffer, offset, continueOnError ? DB_CONTINUE_ON_ERROR : 0)
offset = binary.writeCString(buffer, offset, fullCollectionName)
@@ -141,7 +144,7 @@ exports.serializeQuery = function(fullCollectionName, flags, skip, limit, query,
(fields ? BSON.calculate(fields) : 0)
var buffer = new Buffer(size)
- var offset = writeHeader(buffer, 0, size, 0, OP_QUERY)
+ var offset = writeHeader(buffer, 0, size, OP_QUERY)
offset = binary.writeInt(buffer, offset, flags )
offset = binary.writeCString(buffer, offset, fullCollectionName)
offset = binary.writeInt(buffer, offset, skip)
@@ -168,7 +171,7 @@ exports.serializeGetMore = function(fullCollectionName, numberToReturn, cursorId
8 // cursorId
var buffer = new Buffer(size)
- var offset = writeHeader(buffer, 0, size, 0, OP_GET_MORE)
+ var offset = writeHeader(buffer, 0, size, OP_GET_MORE)
offset = binary.writeInt(buffer, offset, 0) // bson spec: 0 reserved for future use
offset = binary.writeCString(buffer, offset, fullCollectionName)
offset = binary.writeInt(buffer, offset, numberToReturn)
@@ -190,7 +193,7 @@ exports.serializeDelete = function(fullCollectionName, query) {
BSON.calculate(query)
var buffer = new Buffer(size)
- var offset = writeHeader(buffer, 0, size, 0, OP_DELETE)
+ var offset = writeHeader(buffer, 0, size, OP_DELETE)
offset = binary.writeInt(buffer, offset, 0) // bson spec: 0 reserved for future use
offset = binary.writeCString(buffer, offset, fullCollectionName)
offset = binary.writeInt(buffer, offset, 0)
@@ -210,7 +213,7 @@ exports.serializeKillCursors = function(cursors) {
8 * cursors.length
var buffer = new Buffer(size)
- var offset = writeHeader(buffer, 0, size, 0, OP_KILL_CURSORS)
+ var offset = writeHeader(buffer, 0, size, OP_KILL_CURSORS)
offset = binary.writeInt(buffer, offset, 0) // bson spec: 0 reserved for future use
offset = binary.writeInt(buffer, offset, cursors.length)
for (var i=0; i<cursors.length; i++) {

0 comments on commit 3eef881

Please sign in to comment.