summaryrefslogtreecommitdiff
path: root/db/dbmessage.h
diff options
context:
space:
mode:
authordwight <dwight@10gen.com>2010-06-06 15:46:55 -0400
committerdwight <dwight@10gen.com>2010-06-06 15:46:55 -0400
commit3f8da3805a1dbff668b1386df8076ec64ef0522d (patch)
tree28558c48f547f2a2bd30b311620e829d18b383a5 /db/dbmessage.h
parenta3e03d7fe8900f6ea328b3c878e89bad068bc438 (diff)
downloadmongo-3f8da3805a1dbff668b1386df8076ec64ef0522d.tar.gz
towards QueryOption_Exhaust
Diffstat (limited to 'db/dbmessage.h')
-rw-r--r--db/dbmessage.h31
1 files changed, 16 insertions, 15 deletions
diff --git a/db/dbmessage.h b/db/dbmessage.h
index 9e00aa2dbe8..8be52d26e96 100644
--- a/db/dbmessage.h
+++ b/db/dbmessage.h
@@ -75,20 +75,24 @@ namespace mongo {
/* For the database/server protocol, these objects and functions encapsulate
the various messages transmitted over the connection.
- */
+ See http://www.mongodb.org/display/DOCS/Mongo+Wire+Protocol
+ */
class DbMessage {
public:
- DbMessage(const Message& _m) : m(_m) {
+ DbMessage(const Message& _m) : m(_m)
+ {
// for received messages, Message has only one buffer
theEnd = _m.singleData()->_data + _m.header()->dataLen();
- int *r = (int *) _m.singleData()->_data;
- reserved = *r;
- r++;
- data = (const char *) r;
+ char *r = _m.singleData()->_data;
+ reserved = (int *) r;
+ data = r + 4;
nextjsobj = data;
}
+ /** the 32 bit field before the ns */
+ int& reservedField() { return *reserved; }
+
const char * getns() const {
return data;
}
@@ -109,13 +113,12 @@ namespace mongo {
return getInt( 1 );
}
- void resetPull(){
- nextjsobj = data;
- }
- int pullInt() {
+ void resetPull(){ nextjsobj = data; }
+ int pullInt() const { return pullInt(); }
+ int& pullInt() {
if ( nextjsobj == data )
nextjsobj += strlen(data) + 1; // skip namespace
- int i = *((int *)nextjsobj);
+ int& i = *((int *)nextjsobj);
nextjsobj += 4;
return i;
}
@@ -164,9 +167,7 @@ namespace mongo {
return js;
}
- const Message& msg() const {
- return m;
- }
+ const Message& msg() const { return m; }
void markSet(){
mark = nextjsobj;
@@ -178,7 +179,7 @@ namespace mongo {
private:
const Message& m;
- int reserved;
+ int* reserved;
const char *data;
const char *nextjsobj;
const char *theEnd;