diff options
author | Mark Benvenuto <mark.benvenuto@mongodb.com> | 2015-06-20 00:22:50 -0400 |
---|---|---|
committer | Mark Benvenuto <mark.benvenuto@mongodb.com> | 2015-06-20 10:56:02 -0400 |
commit | 9c2ed42daa8fbbef4a919c21ec564e2db55e8d60 (patch) | |
tree | 3814f79c10d7b490948d8cb7b112ac1dd41ceff1 /src/mongo/db/query/getmore_request.cpp | |
parent | 01965cf52bce6976637ecb8f4a622aeb05ab256a (diff) | |
download | mongo-9c2ed42daa8fbbef4a919c21ec564e2db55e8d60.tar.gz |
SERVER-18579: Clang-Format - reformat code, no comment reflow
Diffstat (limited to 'src/mongo/db/query/getmore_request.cpp')
-rw-r--r-- | src/mongo/db/query/getmore_request.cpp | 165 |
1 files changed, 78 insertions, 87 deletions
diff --git a/src/mongo/db/query/getmore_request.cpp b/src/mongo/db/query/getmore_request.cpp index 678276f8467..bb3054af79e 100644 --- a/src/mongo/db/query/getmore_request.cpp +++ b/src/mongo/db/query/getmore_request.cpp @@ -40,113 +40,104 @@ namespace mongo { - GetMoreRequest::GetMoreRequest() - : cursorid(0), - batchSize(0) { } - - GetMoreRequest::GetMoreRequest(const std::string& fullns, - CursorId id, - boost::optional<int> sizeOfBatch) - : nss(fullns), - cursorid(id), - batchSize(sizeOfBatch) { } - - Status GetMoreRequest::isValid() const { - if (!nss.isValid()) { - return Status(ErrorCodes::BadValue, str::stream() - << "Invalid namespace for getMore: " << nss.ns()); - } +GetMoreRequest::GetMoreRequest() : cursorid(0), batchSize(0) {} - if (cursorid == 0) { - return Status(ErrorCodes::BadValue, "Cursor id for getMore must be non-zero"); - } +GetMoreRequest::GetMoreRequest(const std::string& fullns, + CursorId id, + boost::optional<int> sizeOfBatch) + : nss(fullns), cursorid(id), batchSize(sizeOfBatch) {} - if (batchSize && *batchSize <= 0) { - return Status(ErrorCodes::BadValue, str::stream() - << "Batch size for getMore must be positive, " - << "but received: " << *batchSize); - } - - return Status::OK(); +Status GetMoreRequest::isValid() const { + if (!nss.isValid()) { + return Status(ErrorCodes::BadValue, + str::stream() << "Invalid namespace for getMore: " << nss.ns()); } - // static - std::string GetMoreRequest::parseNs(const std::string& dbname, const BSONObj& cmdObj) { - BSONElement collElt = cmdObj["collection"]; - const std::string coll = (collElt.type() == BSONType::String) ? collElt.String() - : ""; + if (cursorid == 0) { + return Status(ErrorCodes::BadValue, "Cursor id for getMore must be non-zero"); + } - return str::stream() << dbname << "." << coll; + if (batchSize && *batchSize <= 0) { + return Status(ErrorCodes::BadValue, + str::stream() << "Batch size for getMore must be positive, " + << "but received: " << *batchSize); } - // static - StatusWith<GetMoreRequest> GetMoreRequest::parseFromBSON(const std::string& dbname, - const BSONObj& cmdObj) { - invariant(!dbname.empty()); + return Status::OK(); +} - // Required fields. - boost::optional<CursorId> cursorid; - boost::optional<std::string> fullns; +// static +std::string GetMoreRequest::parseNs(const std::string& dbname, const BSONObj& cmdObj) { + BSONElement collElt = cmdObj["collection"]; + const std::string coll = (collElt.type() == BSONType::String) ? collElt.String() : ""; - // Optional field. - boost::optional<int> batchSize; + return str::stream() << dbname << "." << coll; +} - for (BSONElement el : cmdObj) { - const char* fieldName = el.fieldName(); - if (str::equals(fieldName, "getMore")) { - if (el.type() != BSONType::NumberLong) { - return {ErrorCodes::TypeMismatch, - str::stream() << "Field 'getMore' must be of type long in: " << cmdObj}; - } +// static +StatusWith<GetMoreRequest> GetMoreRequest::parseFromBSON(const std::string& dbname, + const BSONObj& cmdObj) { + invariant(!dbname.empty()); - cursorid = el.Long(); - } - else if (str::equals(fieldName, "collection")) { - if (el.type() != BSONType::String) { - return {ErrorCodes::TypeMismatch, - str::stream() << "Field 'collection' must be of type string in: " - << cmdObj}; - } - - fullns = parseNs(dbname, cmdObj); - } - else if (str::equals(fieldName, "batchSize")) { - if (!el.isNumber()) { - return {ErrorCodes::TypeMismatch, - str::stream() << "Field 'batchSize' must be a number in: " << cmdObj}; - } + // Required fields. + boost::optional<CursorId> cursorid; + boost::optional<std::string> fullns; - batchSize = el.numberInt(); + // Optional field. + boost::optional<int> batchSize; + + for (BSONElement el : cmdObj) { + const char* fieldName = el.fieldName(); + if (str::equals(fieldName, "getMore")) { + if (el.type() != BSONType::NumberLong) { + return {ErrorCodes::TypeMismatch, + str::stream() << "Field 'getMore' must be of type long in: " << cmdObj}; } - else if (str::equals(fieldName, "maxTimeMS")) { - // maxTimeMS is parsed by the command handling code, so we don't repeat the parsing - // here. - continue; + + cursorid = el.Long(); + } else if (str::equals(fieldName, "collection")) { + if (el.type() != BSONType::String) { + return {ErrorCodes::TypeMismatch, + str::stream() + << "Field 'collection' must be of type string in: " << cmdObj}; } - else if (!str::startsWith(fieldName, "$")) { - return {ErrorCodes::FailedToParse, - str::stream() << "Failed to parse: " << cmdObj << ". " - << "Unrecognized field '" << fieldName << "'."}; + + fullns = parseNs(dbname, cmdObj); + } else if (str::equals(fieldName, "batchSize")) { + if (!el.isNumber()) { + return {ErrorCodes::TypeMismatch, + str::stream() << "Field 'batchSize' must be a number in: " << cmdObj}; } - } - if (!cursorid) { + batchSize = el.numberInt(); + } else if (str::equals(fieldName, "maxTimeMS")) { + // maxTimeMS is parsed by the command handling code, so we don't repeat the parsing + // here. + continue; + } else if (!str::startsWith(fieldName, "$")) { return {ErrorCodes::FailedToParse, - str::stream() << "Field 'getMore' missing in: " << cmdObj}; + str::stream() << "Failed to parse: " << cmdObj << ". " + << "Unrecognized field '" << fieldName << "'."}; } + } - if (!fullns) { - return {ErrorCodes::FailedToParse, - str::stream() << "Field 'collection' missing in: " << cmdObj}; - } + if (!cursorid) { + return {ErrorCodes::FailedToParse, + str::stream() << "Field 'getMore' missing in: " << cmdObj}; + } - GetMoreRequest request(*fullns, *cursorid, batchSize); - Status validStatus = request.isValid(); - if (!validStatus.isOK()) { - return validStatus; - } + if (!fullns) { + return {ErrorCodes::FailedToParse, + str::stream() << "Field 'collection' missing in: " << cmdObj}; + } - return request; + GetMoreRequest request(*fullns, *cursorid, batchSize); + Status validStatus = request.isValid(); + if (!validStatus.isOK()) { + return validStatus; } -} // namespace mongo + return request; +} + +} // namespace mongo |