本文整理汇总了C++中folly::StringPiece::str方法的典型用法代码示例。如果您正苦于以下问题:C++ StringPiece::str方法的具体用法?C++ StringPiece::str怎么用?C++ StringPiece::str使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类folly::StringPiece
的用法示例。
在下文中一共展示了StringPiece::str方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: shorten
std::string shorten(folly::StringPiece s, size_t maxLength) {
if (s.size() <= maxLength || s.size() <= 3) {
return s.str();
}
return s.subpiece(0, maxLength - 3).str() + "...";
}
示例2: set
void MockMc::set(folly::StringPiece key, Item item) {
citems_.erase(key.str());
citems_.insert(std::make_pair(key.str(), CacheItem(std::move(item))));
}
示例3: inputPacket
void SessionTestHarness::inputPacket(folly::StringPiece p) {
savedInputs_.push_back(p.str());
flushSavedInputs();
}
示例4: operator
size_t operator()(folly::StringPiece key) const {
return std::stoi(key.str()) % n_;
}
示例5: initFromPrefix
RoutingPrefix::RoutingPrefix(folly::StringPiece prefix)
: prefix_(prefix.str()) {
initFromPrefix();
}
示例6: asynclog_delete
/** Adds an asynchronous request to the event log. */
void asynclog_delete(proxy_t* proxy,
const AccessPoint& ap,
folly::StringPiece key,
folly::StringPiece poolName) {
dynamic json = {};
const auto& host = ap.getHost();
const auto& port = proxy->router().opts().asynclog_port_override == 0
? ap.getPort()
: proxy->router().opts().asynclog_port_override;
if (proxy->router().opts().use_asynclog_version2) {
json = dynamic::object;
json["f"] = proxy->router().opts().flavor_name;
json["h"] = folly::sformat("[{}]:{}", host, port);
json["p"] = poolName.str();
json["k"] = key.str();
} else {
/* ["host", port, escaped_command] */
json.push_back(host);
json.push_back(port);
json.push_back(folly::sformat("delete {}\r\n", key));
}
auto fd = asynclog_open(proxy);
if (!fd) {
MC_LOG_FAILURE(proxy->router().opts(),
memcache::failure::Category::kSystemError,
"asynclog_open() failed (key {}, pool {})",
key, poolName);
return;
}
// ["AS1.0", 1289416829.836, "C", ["10.0.0.1", 11302, "delete foo\r\n"]]
// OR ["AS2.0", 1289416829.836, "C", {"f":"flavor","h":"[10.0.0.1]:11302",
// "p":"pool_name","k":"foo\r\n"}]
dynamic jsonOut = {};
if (proxy->router().opts().use_asynclog_version2) {
jsonOut.push_back(ASYNCLOG_MAGIC2);
} else {
jsonOut.push_back(ASYNCLOG_MAGIC);
}
struct timeval timestamp;
CHECK(gettimeofday(×tamp, nullptr) == 0);
auto timestamp_ms =
facebook::memcache::to<std::chrono::milliseconds>(timestamp).count();
jsonOut.push_back(1e-3 * timestamp_ms);
jsonOut.push_back(std::string("C"));
jsonOut.push_back(json);
auto jstr = folly::toJson(jsonOut) + "\n";
ssize_t size = folly::writeFull(fd->fd(), jstr.data(), jstr.size());
if (size == -1 || size_t(size) < jstr.size()) {
MC_LOG_FAILURE(proxy->router().opts(),
memcache::failure::Category::kSystemError,
"Error fully writing asynclog request (key {}, pool {})",
key, poolName);
}
}
示例7: openFlags
PcapFile::PcapFile(folly::StringPiece path,
bool overwriteExisting)
: file_(path.str().c_str(), openFlags(overwriteExisting), 0644) {
}