本文整理汇总了C++中StringData::rawData方法的典型用法代码示例。如果您正苦于以下问题:C++ StringData::rawData方法的具体用法?C++ StringData::rawData怎么用?C++ StringData::rawData使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类StringData
的用法示例。
在下文中一共展示了StringData::rawData方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: findField
Position DocumentStorage::findField(StringData requested) const {
int reqSize = requested.size(); // get size calculation out of the way if needed
if (_numFields >= HASH_TAB_MIN) { // hash lookup
const unsigned bucket = bucketForKey(requested);
Position pos = _hashTab[bucket];
while (pos.found()) {
const ValueElement& elem = getField(pos);
if (elem.nameLen == reqSize
&& memcmp(requested.rawData(), elem._name, reqSize) == 0) {
return pos;
}
// possible collision
pos = elem.nextCollision;
}
}
else { // linear scan
for (DocumentStorageIterator it = iteratorAll(); !it.atEnd(); it.advance()) {
if (it->nameLen == reqSize
&& memcmp(requested.rawData(), it->_name, reqSize) == 0) {
return it.position();
}
}
}
// if we got here, there's no such field
return Position();
}
示例2: hash_combine
void Document::hash_combine(size_t &seed) const {
for (DocumentStorageIterator it = storage().iterator(); !it.atEnd(); it.advance()) {
StringData name = it->nameSD();
boost::hash_range(seed, name.rawData(), name.rawData() + name.size());
it->val.hash_combine(seed);
}
}
示例3: checkTableCreationOptions
// static
Status WiredTigerUtil::checkTableCreationOptions(const BSONElement& configElem) {
invariant(configElem.fieldNameStringData() == "configString");
if (configElem.type() != String) {
return {ErrorCodes::TypeMismatch, "'configString' must be a string."};
}
std::vector<std::string> errors;
ErrorAccumulator eventHandler(&errors);
StringData config = configElem.valueStringData();
// Do NOT allow embedded null characters
if (config.size() != strlen(config.rawData())) {
return {ErrorCodes::FailedToParse, "malformed 'configString' value."};
}
Status status = wtRCToStatus(
wiredtiger_config_validate(nullptr, &eventHandler, "WT_SESSION.create", config.rawData()));
if (!status.isOK()) {
StringBuilder errorMsg;
errorMsg << status.reason();
for (std::string error : errors) {
errorMsg << ". " << error;
}
errorMsg << ".";
return status.withReason(errorMsg.stringData());
}
return Status::OK();
}
示例4: logLockless
void Logstream::logLockless( const StringData& s ) {
if ( s.size() == 0 )
return;
if ( doneSetup == 1717 ) {
#if defined(_WIN32)
int fd = fileno( logfile );
if ( _isatty( fd ) ) {
fflush( logfile );
writeUtf8ToWindowsConsole( s.rawData(), s.size() );
return;
}
#else
if ( isSyslog ) {
syslog( LOG_INFO , "%s" , s.rawData() );
return;
}
#endif
if (fwrite(s.rawData(), s.size(), 1, logfile)) {
fflush(logfile);
}
else {
int x = errno;
cout << "Failed to write to logfile: " << errnoWithDescription(x) << endl;
}
}
else {
cout << s;
cout.flush();
}
}
示例5: createPasswordDigest
std::string createPasswordDigest(const StringData& username, const StringData& clearTextPassword) {
md5digest d;
{
md5_state_t st;
md5_init(&st);
md5_append(&st, (const md5_byte_t*)username.rawData(), username.size());
md5_append(&st, (const md5_byte_t*)":mongo:", 7);
md5_append(&st, (const md5_byte_t*)clearTextPassword.rawData(), clearTextPassword.size());
md5_finish(&st, d);
}
return digestToString(d);
}
示例6: versionCmp
int versionCmp(const StringData rhs, const StringData lhs) {
if (rhs == lhs) return 0;
// handle "1.2.3-" and "1.2.3-pre"
if (rhs.size() < lhs.size()) {
if (strncmp(rhs.rawData(), lhs.rawData(), rhs.size()) == 0 && lhs[rhs.size()] == '-') return +1;
}
else if (rhs.size() > lhs.size()) {
if (strncmp(rhs.rawData(), lhs.rawData(), lhs.size()) == 0 && rhs[lhs.size()] == '-') return -1;
}
return LexNumCmp::cmp(rhs, lhs, false);
}
示例7: deleteRecord
void DataFileMgr::deleteRecord(NamespaceDetails* d, const StringData& ns, Record *todelete,
const DiskLoc& dl, bool cappedOK, bool noWarn, bool doLog ) {
dassert( todelete == dl.rec() );
if ( d->isCapped() && !cappedOK ) {
out() << "failing remove on a capped ns " << ns << endl;
uassert( 10089 , "can't remove from a capped collection" , 0 );
return;
}
BSONObj obj = BSONObj::make( todelete );
Collection* collection = cc().database()->getCollection( ns );
verify( collection );
BSONObj toDelete;
collection->deleteDocument( dl, cappedOK, noWarn, doLog ? &toDelete : NULL );
if ( ! toDelete.isEmpty() ) {
// TODO: this is crazy, need to fix logOp
const char* raw = ns.rawData();
if ( strlen(raw) == ns.size() ) {
logOp( "d", raw, toDelete );
}
else {
string temp = ns.toString();
logOp( "d", temp.c_str(), toDelete );
}
}
}
示例8: readCStringWithNuls
/**
* scratch must be empty when passed in. It will be used if there is a NUL byte in the
* output string. In that case the returned StringData will point into scratch, otherwise
* it will point directly into the input buffer.
*/
StringData readCStringWithNuls(BufReader* reader, std::string* scratch) {
const StringData initial = readCString(reader);
if (reader->peek<unsigned char>() != 0xFF)
return initial; // Don't alloc or copy for simple case with no NUL bytes.
scratch->append(initial.rawData(), initial.size());
while (reader->peek<unsigned char>() == 0xFF) {
// Each time we enter this loop it means we hit a NUL byte encoded as "\x00\xFF".
*scratch += '\0';
reader->skip(1);
const StringData nextPart = readCString(reader);
scratch->append(nextPart.rawData(), nextPart.size());
}
return *scratch;
}
示例9: resetThread
/* resets the client for the current thread */
void Client::resetThread( const StringData& origThreadName ) {
verify( currentClient.get() != 0 );
// Detach all client info from thread
mongo::lastError.reset(NULL);
currentClient.get()->shutdown();
currentClient.reset(NULL);
setThreadName( origThreadName.rawData() );
}
示例10: reserialize
void FieldRef::reserialize() const {
std::string nextDotted;
// Reserve some space in the string. We know we will have, at minimum, a character for
// each component we are writing, and a dot for each component, less one. We don't want
// to reserve more, since we don't want to forfeit the SSO if it is applicable.
nextDotted.reserve((_size > 0) ? (_size * 2) - 1 : 0);
// Concatenate the fields to a new string
for (size_t i = 0; i != _size; ++i) {
if (i > 0)
nextDotted.append(1, '.');
const StringData part = getPart(i);
nextDotted.append(part.rawData(), part.size());
}
// Make the new string our contents
_dotted.swap(nextDotted);
// Before we reserialize, it's possible that _cachedSize != _size because parts were added or
// removed. This reserialization process reconciles the components in our cached string
// (_dotted) with the modified path.
_cachedSize = _size;
// Fixup the parts to refer to the new string
std::string::const_iterator where = _dotted.begin();
const std::string::const_iterator end = _dotted.end();
for (size_t i = 0; i != _size; ++i) {
boost::optional<StringView>& part =
(i < kReserveAhead) ? _fixed[i] : _variable[getIndex(i)];
const size_t size = part ? part->len : _replacements[i].size();
// There is one case where we expect to see the "where" iterator to be at "end" here: we
// are at the last part of the FieldRef and that part is the empty string. In that case, we
// need to make sure we do not dereference the "where" iterator.
invariant(where != end || (size == 0 && i == _size - 1));
if (!size) {
part = StringView{};
} else {
std::size_t offset = where - _dotted.begin();
part = StringView{offset, size};
}
where += size;
// skip over '.' unless we are at the end.
if (where != end) {
dassert(*where == '.');
++where;
}
}
// Drop any replacements
_replacements.clear();
}
示例11: generateSaltedPassword
// Iterate the hash function to generate SaltedPassword
void generateSaltedPassword(StringData hashedPassword,
const unsigned char* salt,
const int saltLen,
const int iterationCount,
unsigned char saltedPassword[hashSize]) {
// saltedPassword = Hi(hashedPassword, salt)
HMACIteration(reinterpret_cast<const unsigned char*>(hashedPassword.rawData()),
hashedPassword.size(),
salt,
saltLen,
iterationCount,
saltedPassword);
}
示例12: dottedField
std::string FieldRef::dottedField() const {
std::string res;
if (_size == 0) {
return res;
}
res.append(_fixed[0].rawData(), _fixed[0].size());
for (size_t i=1; i<_size; i++) {
res.append(1, '.');
StringData part = getPart(i);
res.append(part.rawData(), part.size());
}
return res;
}
示例13: stem
string Stemmer::stem( const StringData& word ) const {
if ( !_stemmer )
return word.toString();
const sb_symbol* sb_sym = sb_stemmer_stem( _stemmer,
(const sb_symbol*)word.rawData(),
word.size() );
if ( sb_sym == NULL ) {
// out of memory
abort();
}
return string( (const char*)(sb_sym), sb_stemmer_length( _stemmer ) );
}
示例14: hasIdent
bool MobileKVEngine::hasIdent(OperationContext* opCtx, StringData ident) const {
MobileSession* session = MobileRecoveryUnit::get(opCtx)->getSession(opCtx);
std::string findTableQuery = "SELECT * FROM sqlite_master WHERE type='table' AND name = ?;";
SqliteStatement findTableStmt(*session, findTableQuery);
findTableStmt.bindText(0, ident.rawData(), ident.size());
int status = findTableStmt.step();
if (status == SQLITE_DONE) {
return false;
}
checkStatus(status, SQLITE_ROW, "sqlite3_step");
return true;
}
示例15: dottedField
std::string FieldRef::dottedField( size_t offset ) const {
std::string res;
if (_size == 0 || offset >= numParts() ) {
return res;
}
for (size_t i=offset; i<_size; i++) {
if ( i > offset )
res.append(1, '.');
StringData part = getPart(i);
res.append(part.rawData(), part.size());
}
return res;
}