本文整理汇总了C++中BSONObjBuilder::appendIntOrLL方法的典型用法代码示例。如果您正苦于以下问题:C++ BSONObjBuilder::appendIntOrLL方法的具体用法?C++ BSONObjBuilder::appendIntOrLL怎么用?C++ BSONObjBuilder::appendIntOrLL使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类BSONObjBuilder
的用法示例。
在下文中一共展示了BSONObjBuilder::appendIntOrLL方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: invariant
std::vector<ReplicationExecutor::RemoteCommandRequest>
FreshnessChecker::Algorithm::getRequests() const {
invariant(_targets.size());
const MemberConfig& selfConfig = _rsConfig.getMemberAt(_selfIndex);
// gather all not-down nodes, get their fullnames(or hostandport's)
// schedule fresh command for each node
BSONObjBuilder freshCmdBuilder;
freshCmdBuilder.append("replSetFresh", 1);
freshCmdBuilder.append("set", _rsConfig.getReplSetName());
freshCmdBuilder.append("opTime", Date_t(_lastOpTimeApplied.asDate()));
freshCmdBuilder.append("who", selfConfig.getHostAndPort().toString());
freshCmdBuilder.appendIntOrLL("cfgver", _rsConfig.getConfigVersion());
freshCmdBuilder.append("id", selfConfig.getId());
const BSONObj replSetFreshCmd = freshCmdBuilder.obj();
std::vector<ReplicationExecutor::RemoteCommandRequest> requests;
for (std::vector<HostAndPort>::const_iterator it = _targets.begin();
it != _targets.end();
++it) {
invariant(*it != selfConfig.getHostAndPort());
requests.push_back(ReplicationExecutor::RemoteCommandRequest(
*it,
"admin",
replSetFreshCmd,
Milliseconds(30*1000))); // trying to match current Socket timeout
}
return requests;
}
示例2: invariant
std::vector<RemoteCommandRequest> ElectCmdRunner::Algorithm::getRequests() const {
const MemberConfig& selfConfig = _rsConfig.getMemberAt(_selfIndex);
std::vector<RemoteCommandRequest> requests;
BSONObjBuilder electCmdBuilder;
electCmdBuilder.append("replSetElect", 1);
electCmdBuilder.append("set", _rsConfig.getReplSetName());
electCmdBuilder.append("who", selfConfig.getHostAndPort().toString());
electCmdBuilder.append("whoid", selfConfig.getId());
electCmdBuilder.appendIntOrLL("cfgver", _rsConfig.getConfigVersion());
electCmdBuilder.append("round", _round);
const BSONObj replSetElectCmd = electCmdBuilder.obj();
// Schedule a RemoteCommandRequest for each non-DOWN node
for (std::vector<HostAndPort>::const_iterator it = _targets.begin(); it != _targets.end();
++it) {
invariant(*it != selfConfig.getHostAndPort());
requests.push_back(RemoteCommandRequest(
*it,
"admin",
replSetElectCmd,
Milliseconds(30 * 1000))); // trying to match current Socket timeout
}
return requests;
}
示例3: toBSON
BSONObj ReplSetHeartbeatArgs::toBSON() const {
invariant(isInitialized());
BSONObjBuilder builder;
builder.append("replSetHeartbeat", _setName);
builder.appendIntOrLL("pv", _protocolVersion);
builder.appendIntOrLL("v", _configVersion);
builder.append("from", _hasSenderHost ? _senderHost.toString() : "");
if (_hasSenderId) {
builder.appendIntOrLL("fromId", _senderId);
}
if (_hasCheckEmpty) {
builder.append("checkEmpty", _checkEmpty);
}
return builder.obj();
}
示例4: toBSON
BSONObj ReplicaSetConfig::toBSON() const {
BSONObjBuilder configBuilder;
configBuilder.append(kIdFieldName, _replSetName);
configBuilder.appendIntOrLL(kVersionFieldName, _version);
if (_configServer) {
// Only include "configsvr" field if true
configBuilder.append(kConfigServerFieldName, _configServer);
}
if (_protocolVersion > 0) {
configBuilder.append(kProtocolVersionFieldName, _protocolVersion);
}
BSONArrayBuilder members(configBuilder.subarrayStart(kMembersFieldName));
for (MemberIterator mem = membersBegin(); mem != membersEnd(); mem++) {
members.append(mem->toBSON(getTagConfig()));
}
members.done();
BSONObjBuilder settingsBuilder(configBuilder.subobjStart(kSettingsFieldName));
settingsBuilder.append(kChainingAllowedFieldName, _chainingAllowed);
settingsBuilder.appendIntOrLL(kHeartbeatIntervalFieldName,
durationCount<Milliseconds>(_heartbeatInterval));
settingsBuilder.appendIntOrLL(kHeartbeatTimeoutFieldName,
durationCount<Seconds>(_heartbeatTimeoutPeriod));
settingsBuilder.appendIntOrLL(kElectionTimeoutFieldName,
durationCount<Milliseconds>(_electionTimeoutPeriod));
BSONObjBuilder gleModes(settingsBuilder.subobjStart(kGetLastErrorModesFieldName));
for (StringMap<ReplicaSetTagPattern>::const_iterator mode = _customWriteConcernModes.begin();
mode != _customWriteConcernModes.end();
++mode) {
if (mode->first[0] == '$') {
// Filter out internal modes
continue;
}
BSONObjBuilder modeBuilder(gleModes.subobjStart(mode->first));
for (ReplicaSetTagPattern::ConstraintIterator itr = mode->second.constraintsBegin();
itr != mode->second.constraintsEnd();
itr++) {
modeBuilder.append(_tagConfig.getTagKey(ReplicaSetTag(itr->getKeyIndex(), 0)),
itr->getMinCount());
}
modeBuilder.done();
}
gleModes.done();
settingsBuilder.append(kGetLastErrorDefaultsFieldName, _defaultWriteConcern.toBSON());
settingsBuilder.done();
return configBuilder.obj();
}
示例5: mockIsMasterCmd
void MockReplicaSet::mockIsMasterCmd() {
for (ReplNodeMap::iterator nodeIter = _nodeMap.begin(); nodeIter != _nodeMap.end();
++nodeIter) {
const string& hostAndPort = nodeIter->first;
BSONObjBuilder builder;
builder.append("setName", _setName);
const MemberConfig* member = _replConfig.findMemberByHostAndPort(HostAndPort(hostAndPort));
if (!member) {
builder.append("ismaster", false);
builder.append("secondary", false);
vector<string> hostList;
builder.append("hosts", hostList);
} else {
const bool isPrimary = hostAndPort == getPrimary();
builder.append("ismaster", isPrimary);
builder.append("secondary", !isPrimary);
{
// TODO: add passives & arbiters
vector<string> hostList;
hostList.push_back(getPrimary());
const vector<string> secondaries = getSecondaries();
for (vector<string>::const_iterator secIter = secondaries.begin();
secIter != secondaries.end();
++secIter) {
hostList.push_back(*secIter);
}
builder.append("hosts", hostList);
}
builder.append("primary", getPrimary());
if (member->isArbiter()) {
builder.append("arbiterOnly", true);
}
if (member->getPriority() == 0 && !member->isArbiter()) {
builder.append("passive", true);
}
if (member->getSlaveDelay().count()) {
builder.appendIntOrLL("slaveDelay",
durationCount<Seconds>(member->getSlaveDelay()));
}
if (member->isHidden()) {
builder.append("hidden", true);
}
if (!member->shouldBuildIndexes()) {
builder.append("buildIndexes", false);
}
const ReplicaSetTagConfig tagConfig = _replConfig.getTagConfig();
if (member->hasTags(tagConfig)) {
BSONObjBuilder tagBuilder;
for (MemberConfig::TagIterator tag = member->tagsBegin(); tag != member->tagsEnd();
++tag) {
std::string tagKey = tagConfig.getTagKey(*tag);
if (tagKey[0] == '$') {
// Filter out internal tags
continue;
}
tagBuilder.append(tagKey, tagConfig.getTagValue(*tag));
}
builder.append("tags", tagBuilder.done());
}
}
builder.append("me", hostAndPort);
builder.append("ok", true);
nodeIter->second->setCommandReply("ismaster", builder.done());
}
}
示例6: str
static BSONObj bamboo2bson(const dclass::DistributedType *type,
DatagramIterator &dgi)
{
// The BSON library's weird data model doesn't allow elements to exist on
// their own; they must be part of an object. Therefore, we always return
// results in a single BSONObj with key "_"
BSONObjBuilder b;
switch(type->get_type()) {
case dclass::Type::T_INT8: {
b << "_" << dgi.read_int8();
}
break;
case dclass::Type::T_INT16: {
b << "_" << dgi.read_int16();
}
break;
case dclass::Type::T_INT32: {
b << "_" << dgi.read_int32();
}
break;
case dclass::Type::T_INT64: {
b.appendIntOrLL("_", dgi.read_int64());
}
break;
case dclass::Type::T_UINT8: {
b << "_" << dgi.read_uint8();
}
break;
case dclass::Type::T_UINT16: {
b << "_" << dgi.read_uint16();
}
break;
case dclass::Type::T_UINT32: {
b << "_" << dgi.read_uint32();
}
break;
case dclass::Type::T_UINT64: {
b.appendIntOrLL("_", dgi.read_uint64());
}
break;
case dclass::Type::T_CHAR: {
unsigned char c = dgi.read_uint8();
string str(c, 1);
b << "_" << str;
}
break;
case dclass::Type::T_FLOAT32: {
b << "_" << dgi.read_float32();
}
break;
case dclass::Type::T_FLOAT64: {
b << "_" << dgi.read_float64();
}
break;
case dclass::Type::T_STRING: {
vector<uint8_t> vec = dgi.read_data(type->get_size());
string str((const char *)vec.data(), vec.size());
b << "_" << str;
}
case dclass::Type::T_VARSTRING: {
b << "_" << dgi.read_string();
}
break;
case dclass::Type::T_BLOB: {
vector<uint8_t> blob = dgi.read_data(type->get_size());
b.appendBinData("_", blob.size(), BinDataGeneral, blob.data());
}
break;
case dclass::Type::T_VARBLOB: {
vector<uint8_t> blob = dgi.read_blob();
b.appendBinData("_", blob.size(), BinDataGeneral, blob.data());
}
break;
case dclass::Type::T_ARRAY: {
const dclass::ArrayType *array = type->as_array();
BSONArrayBuilder ab;
for(size_t i = 0; i < array->get_array_size(); i++) {
ab << bamboo2bson(array->get_element_type(), dgi)["_"];
}
b << "_" << ab.arr();
}
break;
case dclass::Type::T_VARARRAY: {
const dclass::ArrayType *array = type->as_array();
dgsize_t array_length = dgi.read_size();
dgsize_t starting_size = dgi.tell();
BSONArrayBuilder ab;
while(dgi.tell() != starting_size + array_length) {
ab << bamboo2bson(array->get_element_type(), dgi)["_"];
if(dgi.tell() > starting_size + array_length) {
throw mongo::DBException("Discovered corrupt array-length tag!", 0);
}
}
//.........这里部分代码省略.........