本文整理汇总了C++中folly::StringPiece::size方法的典型用法代码示例。如果您正苦于以下问题:C++ StringPiece::size方法的具体用法?C++ StringPiece::size怎么用?C++ StringPiece::size使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类folly::StringPiece
的用法示例。
在下文中一共展示了StringPiece::size方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: loadPrivateKeyFromBufferPEM
void SSLContext::loadPrivateKeyFromBufferPEM(folly::StringPiece pkey) {
if (pkey.data() == nullptr) {
throw std::invalid_argument("loadPrivateKey: <pkey> is nullptr");
}
ssl::BioUniquePtr bio(BIO_new(BIO_s_mem()));
if (bio == nullptr) {
throw std::runtime_error("BIO_new: " + getErrors());
}
int written = BIO_write(bio.get(), pkey.data(), pkey.size());
if (written <= 0 || static_cast<unsigned>(written) != pkey.size()) {
throw std::runtime_error("BIO_write: " + getErrors());
}
ssl::EvpPkeyUniquePtr key(
PEM_read_bio_PrivateKey(bio.get(), nullptr, nullptr, nullptr));
if (key == nullptr) {
throw std::runtime_error("PEM_read_bio_PrivateKey: " + getErrors());
}
if (SSL_CTX_use_PrivateKey(ctx_, key.get()) == 0) {
throw std::runtime_error("SSL_CTX_use_PrivateKey: " + getErrors());
}
}
示例2:
const std::vector<McrouterRouteHandlePtr>*
RouteHandleMap::getTargetsForKeyFast(folly::StringPiece prefix,
folly::StringPiece key) const {
// empty prefix => route to default route
if (prefix.empty()) {
return &getBySingleRoute(defaultRoute_, key);
}
// route to all routes
if (prefix == "/*/*/") {
return &allRoutes_->getTargetsForKey(key);
}
auto starPos = prefix.find("*");
if (starPos == std::string::npos) {
// no stars at all
return &getBySingleRoute(prefix, key);
}
if (prefix.endsWith("/*/") && starPos == prefix.size() - 2) {
// route to all clusters of some region (/region/*/)
auto region = prefix.subpiece(1, prefix.size() - 4);
auto it = byRegion_.find(region);
if (it == byRegion_.end()) {
return &emptyV_;
}
return &it->second->getTargetsForKey(key);
}
// no other types supported
return nullptr;
}
示例3: checkLogic
size_t WeightedCh3HashFunc::operator()(folly::StringPiece key) const {
auto n = weights_.size();
checkLogic(n && n <= furc_maximum_pool_size(), "Invalid pool size: {}", n);
size_t salt = 0;
size_t index = 0;
std::string saltedKey;
auto originalKey = key;
for (size_t i = 0; i < kNumTries; ++i) {
index = furc_hash(key.data(), key.size(), n);
/* Use 32-bit hash, but store in 64-bit ints so that
we don't have to deal with overflows */
uint64_t p = folly::hash::SpookyHashV2::Hash32(key.data(), key.size(),
kHashSeed);
assert(0 <= weights_[index] && weights_[index] <= 1.0);
uint64_t w = weights_[index] * std::numeric_limits<uint32_t>::max();
/* Rehash only if p is out of range */
if (LIKELY(p < w)) {
return index;
}
/* Change the key to rehash */
auto s = salt++;
saltedKey = originalKey.str();
do {
saltedKey.push_back(char(s % 10) + '0');
s /= 10;
} while (s > 0);
key = saltedKey;
}
return index;
}
示例4: loadCertificateFromBufferPEM
void SSLContext::loadCertificateFromBufferPEM(folly::StringPiece cert) {
if (cert.data() == nullptr) {
throw std::invalid_argument("loadCertificate: <cert> is nullptr");
}
ssl::BioUniquePtr bio(BIO_new(BIO_s_mem()));
if (bio == nullptr) {
throw std::runtime_error("BIO_new: " + getErrors());
}
int written = BIO_write(bio.get(), cert.data(), cert.size());
if (written <= 0 || static_cast<unsigned>(written) != cert.size()) {
throw std::runtime_error("BIO_write: " + getErrors());
}
ssl::X509UniquePtr x509(
PEM_read_bio_X509(bio.get(), nullptr, nullptr, nullptr));
if (x509 == nullptr) {
throw std::runtime_error("PEM_read_bio_X509: " + getErrors());
}
if (SSL_CTX_use_certificate(ctx_, x509.get()) == 0) {
throw std::runtime_error("SSL_CTX_use_certificate: " + getErrors());
}
}
示例5: if
const std::vector<McrouterRouteHandlePtr>*
RouteHandleMap::getTargetsForKeyFast(folly::StringPiece prefix,
folly::StringPiece key) const {
const std::vector<McrouterRouteHandlePtr>* result = nullptr;
if (prefix.empty()) {
// empty prefix => route to default route
result = &defaultRouteMap_->getTargetsForKey(key);
} else if (prefix == "/*/*/") {
// route to all routes
result = &allRoutes_->getTargetsForKey(key);
} else {
auto starPos = prefix.find("*");
if (starPos == std::string::npos) {
// no stars at all
auto it = byRoute_.find(prefix);
result = it == byRoute_.end()
? &emptyV_
: &it->second->getTargetsForKey(key);
} else if (prefix.endsWith("/*/") && starPos == prefix.size() - 2) {
// route to all clusters of some region (/region/*/)
auto region = prefix.subpiece(1, prefix.size() - 4);
auto it = byRegion_.find(region);
result = it == byRegion_.end()
? &emptyV_
: &it->second->getTargetsForKey(key);
}
}
if (sendInvalidRouteToDefault_ && result != nullptr && result->empty()) {
return &defaultRouteMap_->getTargetsForKey(key);
}
return result;
}
示例6: add
void HTTPHeaders::add(folly::StringPiece name, folly::StringPiece value) {
CHECK(name.size());
const HTTPHeaderCode code = HTTPCommonHeaders::hash(name.data(), name.size());
codes_.push_back(code);
headerNames_.push_back((code == HTTP_HEADER_OTHER)
? new std::string(name.data(), name.size())
: HTTPCommonHeaders::getPointerToHeaderName(code));
headerValues_.emplace_back(value.data(), value.size());
}
示例7: encodeLiteral
uint32_t HPACKEncodeBuffer::encodeLiteral(uint8_t instruction, uint8_t nbit,
folly::StringPiece literal) {
if (huffmanEnabled_) {
return encodeHuffman(instruction, nbit, literal);
}
// otherwise use simple layout
uint32_t count =
encodeInteger(literal.size(), instruction, nbit);
// copy the entire string
buf_.push((uint8_t*)literal.data(), literal.size());
count += literal.size();
return count;
}
示例8: skipPadding
// Skip over padding until sp.data() - start is a multiple of alignment
void skipPadding(folly::StringPiece& sp, const char* start, size_t alignment) {
size_t remainder = (sp.data() - start) % alignment;
if (remainder) {
FOLLY_SAFE_CHECK(alignment - remainder <= sp.size(), "invalid padding");
sp.advance(alignment - remainder);
}
}
示例9: operator
void operator ()(
T const &,
T const &,
folly::StringPiece path,
folly::StringPiece
) const {
out_.emplace_back(path.data(), path.size());
}
示例10: toUpper
std::string toUpper(folly::StringPiece s) {
std::string ret;
ret.reserve(s.size());
for (auto const c : s) {
ret += toupper(c);
}
return ret;
}
示例11: sizeof
typename std::enable_if<std::is_pod<T>::value, T>::type
read(folly::StringPiece& sp) {
FOLLY_SAFE_CHECK(sp.size() >= sizeof(T), "underflow");
T x;
memcpy(&x, sp.data(), sizeof(T));
sp.advance(sizeof(T));
return x;
}
示例12: readNullTerminated
// Read a null-terminated string
folly::StringPiece readNullTerminated(folly::StringPiece& sp) {
const char* p = static_cast<const char*>(
memchr(sp.data(), 0, sp.size()));
FOLLY_SAFE_CHECK(p, "invalid null-terminated string");
folly::StringPiece ret(sp.data(), p);
sp.assign(p + 1, sp.end());
return ret;
}
示例13: exists
bool HTTPHeaders::exists(folly::StringPiece name) const {
const HTTPHeaderCode code = HTTPCommonHeaders::hash(name.data(),
name.size());
if (code != HTTP_HEADER_OTHER) {
return exists(code);
} else {
ITERATE_OVER_STRINGS(name, { return true; });
return false;
}
示例14: initThread
void SwSwitch::initThread(folly::StringPiece name) {
// We need a null-terminated string to pass to folly::setThreadName().
// The pthread name can be at most 15 bytes long, so truncate it if necessary
// when creating the string.
size_t pthreadLength = std::min(name.size(), (size_t)15);
char pthreadName[pthreadLength + 1];
memcpy(pthreadName, name.begin(), pthreadLength);
pthreadName[pthreadLength] = '\0';
folly::setThreadName(pthreadName);
}
示例15: writeSP
void DebugProtocolWriter::writeSP(folly::StringPiece str) {
static constexpr size_t kStringLimit = 256;
static constexpr size_t kStringPrefixSize = 128;
std::string toShow = str.str();
if (toShow.length() > kStringLimit) {
toShow = str.subpiece(0, kStringPrefixSize).str();
folly::toAppend("[...](", str.size(), ")", &toShow);
}
writeItem("\"{}\"", folly::cEscape<std::string>(toShow));
}