Ejemplo n.º 1
0
Status CommandReplyBuilder::addOutputDoc(const BSONObj& outputDoc) {
    invariant(_state == State::kOutputDocs);

    auto dataSize = static_cast<std::size_t>(outputDoc.objsize());
    auto hasSpace = _hasSpaceFor(dataSize);
    if (!hasSpace.isOK()) {
        return hasSpace;
    }

    outputDoc.appendSelfToBufBuilder(_builder);
    return Status::OK();
}
Ejemplo n.º 2
0
Status CommandReplyBuilder::addOutputDocs(DocumentRange outputDocs) {
    invariant(_state == State::kOutputDocs);
    auto rangeData = outputDocs.data();
    auto dataSize = rangeData.length();
    auto hasSpace = _hasSpaceFor(dataSize);
    if (!hasSpace.isOK()) {
        return hasSpace;
    }

    _builder.appendBuf(rangeData.data(), dataSize);
    return Status::OK();
}
Ejemplo n.º 3
0
Status LegacyReplyBuilder::addOutputDocs(DocumentRange docs) {
    invariant(_state == State::kOutputDocs);
    invariant(_allowAddingOutputDocs);

    auto dataSize = docs.data().length();

    auto hasSpace = _hasSpaceFor(dataSize);
    if (!hasSpace.isOK()) {
        return hasSpace;
    }

    // The temporary obj is used to address the case when where is not enough space.
    // BSONArray overhead can not be estimated upfront.
    std::vector<BSONObj> docsTmp{};
    std::size_t lenTmp = 0;
    std::size_t tmpIndex(_currentIndex);
    for (auto&& it : docs) {
        docsTmp.emplace_back(it.getOwned());
        lenTmp += BSONObjBuilder::numStr(++tmpIndex).length() + 2;  // space for storing array index
    }

    hasSpace = _hasSpaceFor(dataSize + lenTmp);
    if (!hasSpace.isOK()) {
        return hasSpace;
    }

    // vector::insert instead of swap allows to call addOutputDoc(s) multiple times
    _outputDocs.insert(_outputDocs.end(),
                       std::make_move_iterator(docsTmp.begin()),
                       std::make_move_iterator(docsTmp.end()));

    _currentIndex = tmpIndex;
    _currentLength += lenTmp;
    _currentLength += dataSize;
    return Status::OK();
}
Ejemplo n.º 4
0
Status LegacyReplyBuilder::addOutputDoc(const BSONObj& bson) {
    invariant(_state == State::kOutputDocs);
    invariant(_allowAddingOutputDocs);

    auto dataSize = static_cast<std::size_t>(bson.objsize());
    auto hasSpace = _hasSpaceFor(dataSize);
    if (!hasSpace.isOK()) {
        return hasSpace;
    }

    _outputDocs.emplace_back(bson.getOwned());
    _currentLength += dataSize;
    _currentLength += BSONObjBuilder::numStr(++_currentIndex).length() + 2;  // storing array index

    return Status::OK();
}