本文整理汇总了C++中msgdata::View::setOperation方法的典型用法代码示例。如果您正苦于以下问题:C++ View::setOperation方法的具体用法?C++ View::setOperation怎么用?C++ View::setOperation使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类msgdata::View
的用法示例。
在下文中一共展示了View::setOperation方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: done
Message CommandReplyBuilder::done() {
invariant(_state == State::kOutputDocs);
MsgData::View msg = _builder.buf();
msg.setLen(_builder.len());
msg.setOperation(dbCommandReply);
_builder.decouple(); // release ownership from BufBuilder
_message.setData(msg.view2ptr(), true); // transfer ownership to Message
_state = State::kDone;
return std::move(_message);
}
示例2: opCommandRequestFromOpMsgRequest
Message opCommandRequestFromOpMsgRequest(const OpMsgRequest& request) {
const auto commandName = request.getCommandName();
BufBuilder builder;
builder.skip(mongo::MsgData::MsgDataHeaderSize); // Leave room for message header.
builder.appendStr(request.getDatabase());
builder.appendStr(commandName);
// OP_COMMAND is only used when communicating with 3.4 nodes and they serialize their metadata
// fields differently. In addition to field-level differences, some generic arguments are pulled
// out to a metadata object, separate from the body. We do all down-conversion here so that the
// rest of the code only has to deal with the current format.
BSONObjBuilder metadataBuilder; // Will be appended to the message after we finish the body.
{
BSONObjBuilder bodyBuilder(builder);
for (auto elem : request.body) {
const auto fieldName = elem.fieldNameStringData();
if (fieldName == "$configServerState") {
metadataBuilder.appendAs(elem, "configsvr");
} else if (fieldName == "$readPreference") {
BSONObjBuilder ssmBuilder(metadataBuilder.subobjStart("$ssm"));
ssmBuilder.append(elem);
ssmBuilder.append("$secondaryOk",
uassertStatusOK(ReadPreferenceSetting::fromInnerBSON(elem))
.canRunOnSecondary());
} else if (fieldName == "$db") {
// skip
} else if (fieldGoesInMetadata(commandName, fieldName)) {
metadataBuilder.append(elem);
} else {
bodyBuilder.append(elem);
}
}
for (auto&& seq : request.sequences) {
invariant(seq.name.find('.') == std::string::npos); // Only support top-level for now.
dassert(!bodyBuilder.asTempObj().hasField(seq.name));
bodyBuilder.append(seq.name, seq.objs);
}
}
metadataBuilder.obj().appendSelfToBufBuilder(builder);
MsgData::View msg = builder.buf();
msg.setLen(builder.len());
msg.setOperation(dbCommand);
return Message(builder.release());
}
示例3: handleRequest
DbResponse ServiceEntryPointMock::handleRequest(OperationContext* opCtx,
const Message& request,
const HostAndPort& client) {
// Need to set up our { ok : 1 } response.
BufBuilder b{};
// Leave room for the message header
b.skip(mongo::MsgData::MsgDataHeaderSize);
// Add our response
auto okObj = BSON("ok" << 1.0);
okObj.appendSelfToBufBuilder(b);
// Add some metadata
auto metadata = BSONObj();
metadata.appendSelfToBufBuilder(b);
// Set Message header fields
MsgData::View msg = b.buf();
msg.setLen(b.len());
msg.setOperation(dbCommandReply);
return {Message(b.release()), ""};
}