INT32 _msgBuffer::write( const bson::BSONObj &obj, BOOLEAN align, INT32 bytes ) { INT32 rc = SDB_OK ; INT32 size = 0 ; // new size to realloc INT32 num = 0 ; // number of memory block UINT32 objsize = obj.objsize() ; if( objsize > _capacity - _size ) { num = ( objsize + _size ) / MEMERY_BLOCK_SIZE + 1 ; size = num * MEMERY_BLOCK_SIZE ; rc = realloc( _data, size ) ; if( SDB_OK != rc ) { goto error ; } } ossMemcpy( _data + _size, obj.objdata(), objsize ) ; if ( align ) { _size += ossRoundUpToMultipleX( objsize, bytes ) ; } else { _size += objsize ; } done: return rc ; error: goto done ; }
int MongoBase::Insert(std::string name,bson::BSONObj& doc,int flag /* = 0 */) { return this->doInsert(name.c_str(),name.size(),flag,doc.objdata(),doc.objsize()); }
int MongoBase::Update(std::string name,int flag,bson::BSONObj& selector,bson::BSONObj& updator) { return this->doUpdate(name.c_str(),name.size(),flag,selector.objdata(),selector.objsize(),updator.objdata(),updator.objsize()); }
int MongoBase::Query(MongoQuery* reply,std::string name,bson::BSONObj& query,bson::BSONObj& selector,int flag /* = 0 */,int skip /* = 0 */,int number /* = 100 */) { int session = this->doQuery(name.c_str(),name.size(),query.objdata(),query.objsize(),selector.objdata(),selector.objsize(),flag,skip,number); _queryCallBack[session] = boost::bind(&MongoBase::QueryReply,this,reply,_1,_2); return session; }