本文整理汇总了C++中BSONElement::valuestrsize方法的典型用法代码示例。如果您正苦于以下问题:C++ BSONElement::valuestrsize方法的具体用法?C++ BSONElement::valuestrsize怎么用?C++ BSONElement::valuestrsize使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类BSONElement
的用法示例。
在下文中一共展示了BSONElement::valuestrsize方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: fillWriterVectors
void fillWriterVectors(const std::deque<BSONObj>& ops,
std::vector<std::vector<BSONObj>>* writerVectors) {
for (std::deque<BSONObj>::const_iterator it = ops.begin(); it != ops.end(); ++it) {
const BSONElement e = it->getField("ns");
verify(e.type() == String);
const char* ns = e.valuestr();
int len = e.valuestrsize();
uint32_t hash = 0;
MurmurHash3_x86_32(ns, len, 0, &hash);
const char* opType = it->getField("op").valuestrsafe();
if (getGlobalServiceContext()->getGlobalStorageEngine()->supportsDocLocking() &&
isCrudOpType(opType)) {
BSONElement id;
switch (opType[0]) {
case 'u':
id = it->getField("o2").Obj()["_id"];
break;
case 'd':
case 'i':
id = it->getField("o").Obj()["_id"];
break;
}
const size_t idHash = BSONElement::Hasher()(id);
MurmurHash3_x86_32(&idHash, sizeof(idHash), hash, &hash);
}
(*writerVectors)[hash % writerVectors->size()].push_back(*it);
}
}
示例2: parseNsCollectionRequired
string Command::parseNsCollectionRequired(const string& dbname, const BSONObj& cmdObj) const {
// Accepts both BSON String and Symbol for collection name per SERVER-16260
// TODO(kangas) remove Symbol support in MongoDB 3.0 after Ruby driver audit
BSONElement first = cmdObj.firstElement();
uassert(17009,
"no collection name specified",
first.canonicalType() == canonicalizeBSONType(mongo::String)
&& first.valuestrsize() > 0);
std::string coll = first.valuestr();
return dbname + '.' + coll;
}
示例3: fillWriterVectors
void SyncTail::fillWriterVectors(const std::deque<BSONObj>& ops,
std::vector< std::vector<BSONObj> >* writerVectors) {
for (std::deque<BSONObj>::const_iterator it = ops.begin();
it != ops.end();
++it) {
const BSONElement e = it->getField("ns");
verify(e.type() == String);
const char* ns = e.valuestr();
int len = e.valuestrsize();
uint32_t hash = 0;
MurmurHash3_x86_32( ns, len, 0, &hash);
(*writerVectors)[hash % writerVectors->size()].push_back(*it);
}
}
示例4: matchesSingleElement
bool RegexMatchExpression::matchesSingleElement(const BSONElement& e) const {
switch (e.type()) {
case String:
case Symbol: {
// String values stored in documents can contain embedded NUL bytes. We construct a
// pcrecpp::StringPiece instance using the full length of the string to avoid truncating
// 'data' early.
pcrecpp::StringPiece data(e.valuestr(), e.valuestrsize() - 1);
return _re->PartialMatch(data);
}
case RegEx:
return _regex == e.regex() && _flags == e.regexFlags();
default:
return false;
}
}
示例5: extract
FieldParser::FieldState FieldParser::extract(BSONElement elem,
const BSONField<string>& field,
string* out,
string* errMsg) {
if (elem.eoo()) {
if (field.hasDefault()) {
*out = field.getDefault();
return FIELD_DEFAULT;
} else {
return FIELD_NONE;
}
}
if (elem.type() == String) {
// Extract everything, including embedded null characters.
*out = string(elem.valuestr(), elem.valuestrsize() - 1);
return FIELD_SET;
}
_genFieldErrMsg(elem, field, "string", errMsg);
return FIELD_INVALID;
}
示例6: i
// fromBSON to Key format
KeyV1Owned::KeyV1Owned(const BSONObj& obj) {
BSONObj::iterator i(obj);
unsigned char bits = 0;
while( 1 ) {
BSONElement e = i.next();
if( i.more() )
bits |= cHASMORE;
switch( e.type() ) {
case MinKey:
b.appendUChar(cminkey|bits);
break;
case jstNULL:
b.appendUChar(cnull|bits);
break;
case MaxKey:
b.appendUChar(cmaxkey|bits);
break;
case Bool:
b.appendUChar( (e.boolean()?ctrue:cfalse) | bits );
break;
case jstOID:
b.appendUChar(coid|bits);
b.appendBuf(&e.__oid(), sizeof(OID));
break;
case BinData:
{
int t = e.binDataType();
// 0-7 and 0x80 to 0x87 are supported by Key
if( (t & 0x78) == 0 && t != ByteArrayDeprecated ) {
int len;
const char * d = e.binData(len);
if( len <= BinDataLenMax ) {
int code = BinDataLengthToCode[len];
if( code >= 0 ) {
if( t >= 128 )
t = (t-128) | 0x08;
dassert( (code&t) == 0 );
b.appendUChar( cbindata|bits );
b.appendUChar( code | t );
b.appendBuf(d, len);
break;
}
}
}
traditional(obj);
return;
}
case Date:
b.appendUChar(cdate|bits);
b.appendStruct(e.date());
break;
case String:
{
b.appendUChar(cstring|bits);
// note we do not store the terminating null, to save space.
unsigned x = (unsigned) e.valuestrsize() - 1;
if( x > 255 ) {
traditional(obj);
return;
}
b.appendUChar(x);
b.appendBuf(e.valuestr(), x);
break;
}
case NumberInt:
b.appendUChar(cint|bits);
b.appendNum((double) e._numberInt());
break;
case NumberLong:
{
long long n = e._numberLong();
long long m = 2LL << 52;
DEV {
long long d = m-1;
verify( ((long long) ((double) -d)) == -d );
}
if( n >= m || n <= -m ) {
// can't represent exactly as a double
traditional(obj);
return;
}
b.appendUChar(clong|bits);
b.appendNum((double) n);
break;
}
case NumberDouble:
{
double d = e._numberDouble();
if( isNaN(d) ) {
traditional(obj);
return;
}
b.appendUChar(cdouble|bits);
b.appendNum(d);
break;
}
default:
// if other types involved, store as traditional BSON
traditional(obj);
//.........这里部分代码省略.........
示例7: StringData
static inline StringData makeStringDataFromBSONElement(const BSONElement& element) {
return StringData(element.valuestr(), element.valuestrsize() - 1);
}
示例8: jsonString
std::string jsonString(BSONElement &elem, JsonStringFormat format, bool includeFieldNames, int pretty, UUIDEncoding uuidEncoding)
{
BSONType t = elem.type();
int sign;
if ( t == Undefined )
return "undefined";
stringstream s;
if ( includeFieldNames )
s << '"' << escape( elem.fieldName() ) << "\" : ";
switch ( elem.type() ) {
case mongo::String:
case Symbol:
s << '"' << escape( string(elem.valuestr(), elem.valuestrsize()-1) ) << '"';
break;
case NumberLong:
s << "NumberLong(" << elem._numberLong() << ")";
break;
case NumberInt:
case NumberDouble:
if ( elem.number() >= -numeric_limits< double >::max() &&
elem.number() <= numeric_limits< double >::max() ) {
s.precision( 16 );
s << elem.number();
}
else if ( mongo::isNaN(elem.number()) ) {
s << "NaN";
}
else if ( mongo::isInf(elem.number(), &sign) ) {
s << ( sign == 1 ? "Infinity" : "-Infinity");
}
else {
StringBuilder ss;
ss << "Number " << elem.number() << " cannot be represented in JSON";
string message = ss.str();
//massert( 10311 , message.c_str(), false );
}
break;
case mongo::Bool:
s << ( elem.boolean() ? "true" : "false" );
break;
case jstNULL:
s << "null";
break;
case Object: {
BSONObj obj = elem.embeddedObject();
s << jsonString(obj, format, pretty, uuidEncoding);
}
break;
case mongo::Array: {
if ( elem.embeddedObject().isEmpty() ) {
s << "[]";
break;
}
s << "[ ";
BSONObjIterator i( elem.embeddedObject() );
BSONElement e = i.next();
if ( !e.eoo() ) {
int count = 0;
while ( 1 ) {
if( pretty ) {
s << '\n';
for( int x = 0; x < pretty; x++ )
s << " ";
}
if (strtol(e.fieldName(), 0, 10) > count) {
s << "undefined";
}
else {
s << jsonString(e, format, false, pretty?pretty+1:0, uuidEncoding);
e = i.next();
}
count++;
if ( e.eoo() ) {
s << '\n';
for( int x = 0; x < pretty - 1; x++ )
s << " ";
s << "]";
break;
}
s << ", ";
}
}
//s << " ]";
break;
}
case DBRef: {
mongo::OID *x = (mongo::OID *) (elem.valuestr() + elem.valuestrsize());
if ( format == TenGen )
s << "Dbref( ";
else
s << "{ \"$ref\" : ";
s << '"' << elem.valuestr() << "\", ";
if ( format != TenGen )
s << "\"$id\" : ";
s << '"' << *x << "\" ";
if ( format == TenGen )
s << ')';
else
//.........这里部分代码省略.........
示例9: i
// fromBSON to Key format
KeyV1Owned::KeyV1Owned(const BSONObj& obj) {
BSONObj::iterator i(obj);
assert( i.more() );
unsigned char bits = 0;
while( 1 ) {
BSONElement e = i.next();
if( i.more() )
bits |= cHASMORE;
switch( e.type() ) {
case MinKey:
b.appendUChar(cminkey|bits);
break;
case jstNULL:
b.appendUChar(cnull|bits);
break;
case MaxKey:
b.appendUChar(cmaxkey|bits);
break;
case Bool:
b.appendUChar( (e.boolean()?ctrue:cfalse) | bits );
break;
case jstOID:
b.appendUChar(coid|bits);
b.appendBuf(&e.__oid(), sizeof(OID));
break;
case BinData:
{
int t = e.binDataType();
// 0-7 and 0x80 to 0x87 are supported by Key
if( (t & 0x78) == 0 && t != ByteArrayDeprecated ) {
int len;
const char * d = e.binData(len);
int code = BinDataLengthToCode[len];
if( code >= 0 ) {
if( t >= 128 )
t = (t-128) | 0x08;
dassert( (code&t) == 0 );
b.appendUChar( cbindata|bits );
b.appendUChar( code | t );
b.appendBuf(d, len);
break;
}
}
traditional(obj);
return;
}
case Date:
b.appendUChar(cdate|bits);
b.appendStruct(e.date());
break;
case String:
{
b.appendUChar(cstring|bits);
// note we do not store the terminating null, to save space.
unsigned x = (unsigned) e.valuestrsize() - 1;
if( x > 255 ) {
traditional(obj);
return;
}
b.appendUChar(x);
b.appendBuf(e.valuestr(), x);
break;
}
case NumberInt:
b.appendUChar(cint|bits);
b.appendNum((double) e._numberInt());
break;
case NumberLong:
{
long long n = e._numberLong();
double d = (double) n;
if( d != n ) {
traditional(obj);
return;
}
b.appendUChar(clong|bits);
b.appendNum(d);
break;
}
case NumberDouble:
{
double d = e._numberDouble();
bool nan = !( d <= numeric_limits< double >::max() &&
d >= -numeric_limits< double >::max() );
if( !nan ) {
b.appendUChar(cdouble|bits);
b.appendNum(d);
break;
}
// else fall through and return a traditional BSON obj so our compressed keys need not check for nan
}
default:
// if other types involved, store as traditional BSON
traditional(obj);
return;
}
if( !i.more() )
break;
bits = 0;
//.........这里部分代码省略.........