本文整理汇总了C++中folly类的典型用法代码示例。如果您正苦于以下问题:C++ folly类的具体用法?C++ folly怎么用?C++ folly使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了folly类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。
示例1: parseJson
void WedgeProductInfo::parse(std::string data) {
try {
dynamic info = parseJson(data)[kInfo];
productInfo_.oem = folly::to<std::string>(info[kSysMfg].asString());
productInfo_.product = folly::to<std::string>(info[kProdName].asString());
productInfo_.serial = folly::to<std::string>(info[kSerialNum].asString());
productInfo_.mfgDate = folly::to<std::string>(info[kSysMfgDate].asString());
productInfo_.systemPartNumber =
folly::to<std::string>(info[kSysAmbPartNum].asString());
productInfo_.assembledAt = folly::to<std::string>(info[kAmbAt].asString());
productInfo_.pcbManufacturer =
folly::to<std::string>(info[kPcbMfg].asString());
productInfo_.assetTag =
folly::to<std::string>(info[kProdAssetTag].asString());
productInfo_.partNumber =
folly::to<std::string>(info[kProdPartNum].asString());
productInfo_.odmPcbPartNumber = folly::to<std::string>
(info[kOdmPcbPartNum].asString());
productInfo_.odmPcbSerial = folly::to<std::string>
(info[kOdmPcbSerialNum].asString());
productInfo_.fbPcbPartNumber = folly::to<std::string>
(info[kFbPcbPartNum].asString());
productInfo_.version = info[kVersion].asInt();
productInfo_.subVersion = info[kSubVersion].asInt();
productInfo_.productionState = info[kProductionState].asInt();
productInfo_.productVersion = info[kProdVersion].asInt();
productInfo_.bmcMac = folly::to<std::string>(info[kLocalMac].asString());
productInfo_.mgmtMac = folly::to<std::string>(info[kExtMacBase].asString());
auto macBase = MacAddress(info[kExtMacBase].asString()).u64HBO() + 1;
productInfo_.macRangeStart = MacAddress::fromHBO(macBase).toString();
productInfo_.macRangeSize = info[kExtMacSize].asInt() - 1;
} catch (const std::exception& err) {
LOG(ERROR) << err.what();
}
}
开发者ID:superchild,项目名称:fboss,代码行数:35,代码来源:WedgeProductInfo.cpp
示例2: TEST
TEST(Json, SortKeys) {
folly::json::serialization_opts opts_on, opts_off;
opts_on.sort_keys = true;
opts_off.sort_keys = false;
dynamic value = dynamic::object
("foo", "bar")
("junk", 12)
("another", 32.2)
("a",
{
dynamic::object("a", "b")
("c", "d"),
12.5,
"Yo Dawg",
{ "heh" },
nullptr
}
)
;
std::string sorted_keys =
R"({"a":[{"a":"b","c":"d"},12.5,"Yo Dawg",["heh"],null],)"
R"("another":32.2,"foo":"bar","junk":12})";
EXPECT_EQ(value, parseJson(folly::json::serialize(value, opts_on)));
EXPECT_EQ(value, parseJson(folly::json::serialize(value, opts_off)));
EXPECT_EQ(sorted_keys, folly::json::serialize(value, opts_on));
}
开发者ID:AurelC2G,项目名称:folly,代码行数:30,代码来源:JsonTest.cpp
示例3: open
bool MmapFile::init() {
int fd = open(path_.c_str(), O_RDONLY);
if (fd < 0) {
Logger::Error(format("Unable to open {}: {}",
path_, folly::errnoStr(errno)).str());
return false;
}
struct stat fs;
if (fstat(fd, &fs) != 0) {
Logger::Error(format("Unable to fstat {}: {}",
path_, folly::errnoStr(errno)).str());
close(fd);
return false;
}
backing_fd_ = fd;
backing_mem_size_ = fs.st_size;
backing_mem_ = mmap(nullptr, backing_mem_size_, PROT_READ, MAP_PRIVATE,
backing_fd_, 0);
if (backing_mem_ == (void*) -1) {
Logger::Error(format("Unable to mmap {}: {}",
path_, folly::errnoStr(errno)).str());
close(backing_fd_);
return false;
}
backing_mem_end_ = (char*) backing_mem_ + backing_mem_size_;
read_ptr_ = static_cast<char*>(backing_mem_);
initialized_ = true;
return true;
}
开发者ID:AmineCherrai,项目名称:hhvm,代码行数:35,代码来源:mmap-file.cpp
示例4: makeUnicastRoute
std::unique_ptr<UnicastRoute>
makeUnicastRoute(std::string prefixStr, std::string nxtHop,
AdminDistance distance=AdminDistance::MAX_ADMIN_DISTANCE) {
std::vector<std::string> vec;
folly::split("/", prefixStr, vec);
EXPECT_EQ(2, vec.size());
auto nr = std::make_unique<UnicastRoute>();
nr->dest.ip = toBinaryAddress(IPAddress(vec.at(0)));
nr->dest.prefixLength = folly::to<uint8_t>(vec.at(1));
nr->nextHopAddrs.push_back(toBinaryAddress(IPAddress(nxtHop)));
nr->adminDistance = distance;
nr->__isset.adminDistance = true;
return nr;
}
开发者ID:iotvietmember,项目名称:fboss,代码行数:14,代码来源:ThriftTest.cpp
示例5: TEST
TEST(GitBlob, testDeserializeManaged) {
string blobHash("3a8f8eb91101860fd8484154885838bf322964d0");
Hash hash(blobHash);
string contents("{\n \"breakConfig\": true\n}\n");
auto buf = IOBuf::create(1024);
folly::io::Appender appender(buf.get(), 0);
appender.printf("blob %zu", contents.size());
appender.write<uint8_t>(0);
appender.push(StringPiece(contents));
// Sanity check that we are the only user of the newly-created IOBuf
EXPECT_FALSE(buf->isShared()) << "newly created IOBuf should not be shared";
auto blob = deserializeGitBlob(hash, buf.get());
EXPECT_EQ(hash, blob->getHash());
EXPECT_TRUE(buf->isShared())
<< "deserializeGitBlob() should return a blob that shares the same "
<< "IOBuf data, instead of copying it";
EXPECT_EQ(contents, StringPiece{blob->getContents().clone()->coalesce()});
// Make sure the blob contents are still valid after freeing
// our copy of the IOBuf
buf.reset();
EXPECT_EQ(contents, StringPiece{blob->getContents().clone()->coalesce()});
}
开发者ID:facebookexperimental,项目名称:eden,代码行数:25,代码来源:GitBlobTest.cpp
示例6: process
virtual void process(std::unique_ptr<ResponseChannel::Request> req,
std::unique_ptr<folly::IOBuf> buf,
protocol::PROTOCOL_TYPES protType,
Cpp2RequestContext* context,
async::TEventBase* eb,
concurrency::ThreadManager* tm) {
assert(iface_);
auto reqd = makeMoveWrapper(std::move(req));
auto bufd = makeMoveWrapper(std::move(buf));
tm->add(FunctionRunner::create([=] () mutable {
(*bufd)->coalesce();
uint64_t resp;
char* data;
iface_->process(
(*reqd).release(), eb, (*bufd)->writableData(),
(*bufd)->length(), protType);
}));
}
开发者ID:Hsin,项目名称:fbthrift,代码行数:18,代码来源:thriftserver.cpp
示例7: always_assert
bool CacheSaver::writeString(const string& str) const {
if (!writeUInt64(str.length())) {
return false;
}
ssize_t write_len = str.length();
always_assert(write_len >= 0);
ssize_t ret = writeFull(fd_, (const void*) str.data(), write_len);
if (ret < 0) {
Logger::Error(format("Unable to write string: {}",
folly::errnoStr(errno)).str());
return false;
}
return ret == write_len;
}
开发者ID:360buyliulei,项目名称:hiphop-php,代码行数:18,代码来源:cache-saver.cpp
示例8: ds
TEST(Dynamic, GetDefault) {
const auto s = make_long_string();
dynamic ds(s);
dynamic tmp(s);
dynamic d1 = dynamic::object("key1", s);
dynamic d2 = dynamic::object("key2", s);
dynamic d3 = dynamic::object("key3", s);
dynamic d4 = dynamic::object("key4", s);
// lvalue - lvalue
dynamic ayy("ayy");
EXPECT_EQ(ds, d1.getDefault("key1", ayy));
EXPECT_EQ(ds, d1.getDefault("key1", ayy));
EXPECT_EQ(ds, d1.getDefault("not-a-key", tmp));
EXPECT_EQ(ds, tmp);
// lvalue - rvalue
EXPECT_EQ(ds, d1.getDefault("key1", "ayy"));
EXPECT_EQ(ds, d1.getDefault("key1", "ayy"));
EXPECT_EQ(ds, d1.getDefault("not-a-key", std::move(tmp)));
EXPECT_NE(ds, tmp);
// rvalue - lvalue
tmp = s;
EXPECT_EQ(ds, std::move(d1).getDefault("key1", ayy));
EXPECT_NE(ds, d1["key1"]);
EXPECT_EQ(ds, std::move(d2).getDefault("not-a-key", tmp));
EXPECT_EQ(dynamic(dynamic::object("key2", s)), d2);
EXPECT_EQ(ds, tmp);
// rvalue - rvalue
EXPECT_EQ(ds, std::move(d3).getDefault("key3", std::move(tmp)));
EXPECT_NE(ds, d3["key3"]);
EXPECT_EQ(ds, tmp);
EXPECT_EQ(ds, std::move(d4).getDefault("not-a-key", std::move(tmp)));
EXPECT_EQ(dynamic(dynamic::object("key4", s)), d4);
EXPECT_NE(ds, tmp);
}
开发者ID:charsyam,项目名称:folly,代码行数:34,代码来源:DynamicTest.cpp
示例9: MacAddress
TEST(MacAddress, toString) {
EXPECT_EQ("12:34:56:78:9a:bc",
MacAddress::fromHBO(0x123456789abc).toString());
EXPECT_EQ("12:34:56:78:9a:bc", MacAddress("12:34:56:78:9a:bc").toString());
EXPECT_EQ("01:23:45:67:89:ab", MacAddress("01-23-45-67-89-ab").toString());
EXPECT_EQ("01:23:45:67:89:ab", MacAddress("0123456789ab").toString());
}
开发者ID:charsyam,项目名称:folly,代码行数:7,代码来源:MacAddressTest.cpp
示例10: main
int main(int argc, char* argv[]) {
gflags::ParseCommandLineFlags(&argc, &argv, true);
google::InitGoogleLogging(argv[0]);
google::InstallFailureSignalHandler();
std::vector<HTTPServer::IPConfig> IPs = {
{SocketAddress(FLAGS_ip, FLAGS_http_port, true), Protocol::HTTP},
{SocketAddress(FLAGS_ip, FLAGS_spdy_port, true), Protocol::SPDY},
};
if (FLAGS_threads <= 0) {
FLAGS_threads = sysconf(_SC_NPROCESSORS_ONLN);
CHECK(FLAGS_threads > 0);
}
HTTPServerOptions options;
options.threads = static_cast<size_t>(FLAGS_threads);
options.idleTimeout = std::chrono::milliseconds(60000);
options.shutdownOn = {SIGINT, SIGTERM};
options.enableContentCompression = true;
options.handlerFactories = RequestHandlerChain()
.addThen<HangmanHandlerFactory>()
.build();
HTTPServer server(std::move(options));
server.bind(IPs);
// Start HTTPServer mainloop in a separate thread
std::thread t([&] () {
server.start();
});
t.join();
return 0;
}
开发者ID:faisalhabib2002,项目名称:hangman,代码行数:35,代码来源:HangmanServer.cpp
示例11: createChannel
TEST_F(FuseChannelTest, testDestroyWithPendingRequests) {
auto channel = createChannel();
auto completeFuture = performInit(channel.get());
// Send several lookup requests
auto id1 = fuse_.sendLookup(FUSE_ROOT_ID, "foobar");
auto id2 = fuse_.sendLookup(FUSE_ROOT_ID, "some_file.txt");
auto id3 = fuse_.sendLookup(FUSE_ROOT_ID, "main.c");
auto req1 = dispatcher_.waitForLookup(id1);
auto req2 = dispatcher_.waitForLookup(id2);
auto req3 = dispatcher_.waitForLookup(id3);
// Destroy the channel object
channel.reset();
// The completion future still should not be ready, since the lookup
// requests are still pending.
EXPECT_FALSE(completeFuture.isReady());
auto checkLookupResponse = [](const FakeFuse::Response& response,
uint64_t requestID,
fuse_entry_out expected) {
EXPECT_EQ(requestID, response.header.unique);
EXPECT_EQ(0, response.header.error);
EXPECT_EQ(
sizeof(fuse_out_header) + sizeof(fuse_entry_out), response.header.len);
EXPECT_EQ(
ByteRange(
reinterpret_cast<const uint8_t*>(&expected), sizeof(expected)),
ByteRange(response.body.data(), response.body.size()));
};
// Respond to the lookup requests
auto response1 = genRandomLookupResponse(9);
req1.promise.setValue(response1);
auto received = fuse_.recvResponse();
checkLookupResponse(received, id1, response1);
// We don't have to respond in order; respond to request 3 before 2
auto response3 = genRandomLookupResponse(19);
req3.promise.setValue(response3);
received = fuse_.recvResponse();
checkLookupResponse(received, id3, response3);
// The completion future still shouldn't be ready since there is still 1
// request outstanding.
EXPECT_FALSE(completeFuture.isReady());
auto response2 = genRandomLookupResponse(12);
req2.promise.setValue(response2);
received = fuse_.recvResponse();
checkLookupResponse(received, id2, response2);
// The completion future should be ready now that the last request
// is done.
EXPECT_TRUE(completeFuture.isReady());
std::move(completeFuture).get(kTimeout);
}
开发者ID:facebookexperimental,项目名称:eden,代码行数:59,代码来源:FuseChannelTest.cpp
示例12: parseJson
BENCHMARK(toJson, iters) {
dynamic something = parseJson(
"{\"old_value\":40,\"changed\":true,\"opened\":false,\"foo\":[1,2,3,4,5,6]}"
);
for (size_t i = 0; i < iters; i++) {
toJson(something);
}
}
开发者ID:AurelC2G,项目名称:folly,代码行数:9,代码来源:JsonTest.cpp
示例13: ds
TEST(Dynamic, At) {
const dynamic cd = dynamic::object("key1", make_long_string());
dynamic dd = dynamic::object("key1", make_long_string());
dynamic md = dynamic::object("key1", make_long_string());
dynamic ds(make_long_string());
EXPECT_EQ(ds, cd.at("key1"));
EXPECT_EQ(ds, cd.at("key1"));
dd.at("key1").getString() += " hello";
EXPECT_EQ(dynamic(make_long_string() + " hello"), dd.at("key1"));
EXPECT_EQ(dynamic(make_long_string() + " hello"), dd.at("key1"));
EXPECT_EQ(ds, std::move(md).at("key1"));
EXPECT_NE(ds, md.at("key1"));
}
开发者ID:jianw851,项目名称:folly,代码行数:16,代码来源:DynamicTest.cpp
示例14: decltype
TEST(make_array, deduced_common_type) {
auto arr = make_array(1.0, 2.5f, 3, 4, 5);
static_assert(
is_same<typename decltype(arr)::value_type, double>::value,
"Wrong array type");
EXPECT_EQ(arr.size(), 5);
}
开发者ID:GYGit,项目名称:folly,代码行数:7,代码来源:ArrayTest.cpp
示例15: parseJson
TEST(OpenRTB, DeviceTest) {
dynamic deviceObj = parseJson(readFile("testdata/device.json"));
Device device;
device.deserialize(deviceObj);
std::function<void()> checkFunction = [&](){
EXPECT_EQ(device.ip, deviceObj.at("ip").asString().toStdString());
EXPECT_EQ(device.language.get(), deviceObj.at("language").asString().toStdString());
EXPECT_EQ(device.carrier.get(), deviceObj.at("carrier").asString().toStdString());
EXPECT_EQ(device.model.get(), deviceObj.at("model").asString().toStdString());
EXPECT_EQ(device.os.get(), deviceObj.at("os").asString().toStdString());
EXPECT_EQ(device.osv.get(), deviceObj.at("osv").asString().toStdString());
EXPECT_EQ(device.make.get(), deviceObj.at("make").asString().toStdString());
//geo
EXPECT_EQ(device.geo.get().city, deviceObj.at("geo").at("city").asString().toStdString());
EXPECT_EQ(device.geo.get().country, deviceObj.at("geo").at("country").asString().toStdString());
EXPECT_EQ(device.geo.get().metro, deviceObj.at("geo").at("metro").asString().toStdString());
EXPECT_EQ(device.geo.get().region, deviceObj.at("geo").at("region").asString().toStdString());
EXPECT_EQ(device.geo.get().zip, deviceObj.at("geo").at("zip").asString().toStdString());
};
checkFunction();
//serialize object
deviceObj = device.serialize();
//check again with new serialized device object
checkFunction();
}
开发者ID:poseidon1214,项目名称:rtbxegen,代码行数:32,代码来源:openrtb_test.cpp
示例16: fn
// Using ScopeGuard to invoke a std::function
BENCHMARK(scope_guard_std_function, iters) {
std::function<void()> fn(doNothing);
for (size_t n = 0; n < iters; ++n) {
auto g = makeGuard(fn);
(void)g;
}
}
开发者ID:SocialExplorerFork,项目名称:folly,代码行数:8,代码来源:main.cpp
示例17: sfpString
StringPiece sfpString(const uint8_t* buf, size_t offset, size_t len) {
const uint8_t* start = buf + offset;
while (len > 0 && start[len - 1] == ' ') {
--len;
}
return StringPiece(reinterpret_cast<const char*>(start), len);
}
开发者ID:XPliant,项目名称:fboss,代码行数:7,代码来源:wedge_qsfp_util.cpp
示例18: vlanID
TEST(ArpTest, ArpTableSerialization) {
auto sw = setupSwitch();
VlanID vlanID(1);
IPAddressV4 senderIP = IPAddressV4("10.0.0.1");
IPAddressV4 targetIP = IPAddressV4("10.0.0.2");
EXPECT_HW_CALL(sw, stateChanged(_)).Times(0);
auto vlan = sw->getState()->getVlans()->getVlanIf(vlanID);
EXPECT_NE(vlan, nullptr);
auto arpTable = vlan->getArpTable();
EXPECT_NE(arpTable, nullptr);
EXPECT_EQ(arpTable->hasPendingEntries(), false);
auto serializedArpTable = arpTable->toFollyDynamic();
auto unserializedArpTable = arpTable->fromFollyDynamic(serializedArpTable);
EXPECT_EQ(unserializedArpTable->hasPendingEntries(), false);
waitForStateUpdates(sw.get());
// Cache the current stats
CounterCache counters(sw.get());
testSendArpRequest(sw, vlanID, senderIP, targetIP);
waitForStateUpdates(sw.get());
counters.update();
counters.checkDelta(SwitchStats::kCounterPrefix + "arp.request.tx.sum", 1);
counters.checkDelta(SwitchStats::kCounterPrefix + "arp.request.rx.sum", 0);
counters.checkDelta(SwitchStats::kCounterPrefix + "arp.reply.tx.sum", 0);
counters.checkDelta(SwitchStats::kCounterPrefix + "arp.reply.rx.sum", 0);
vlan = sw->getState()->getVlans()->getVlanIf(vlanID);
EXPECT_NE(vlan, nullptr);
arpTable = vlan->getArpTable();
EXPECT_NE(arpTable, nullptr);
EXPECT_EQ(arpTable->hasPendingEntries(), true);
serializedArpTable = arpTable->toFollyDynamic();
unserializedArpTable = arpTable->fromFollyDynamic(serializedArpTable);
// Pending flag should still be set
EXPECT_EQ(unserializedArpTable->hasPendingEntries(), true);
// Should also see a pending entry
auto entry = sw->getState()->getVlans()->getVlanIf(vlanID)->getArpTable()
->getEntryIf(targetIP);
EXPECT_NE(sw, nullptr);
}
开发者ID:jaymzh,项目名称:fboss,代码行数:47,代码来源:ArpTest.cpp
示例19:
TEST(Dynamic, GetPtr) {
dynamic array = { 1, 2, "three" };
EXPECT_TRUE(array.get_ptr(0));
EXPECT_FALSE(array.get_ptr(3));
EXPECT_EQ(dynamic("three"), *array.get_ptr(2));
const dynamic& carray = array;
EXPECT_EQ(dynamic("three"), *carray.get_ptr(2));
dynamic object = dynamic::object("one", 1)("two", 2);
EXPECT_TRUE(object.get_ptr("one"));
EXPECT_FALSE(object.get_ptr("three"));
EXPECT_EQ(dynamic(2), *object.get_ptr("two"));
*object.get_ptr("one") = 11;
EXPECT_EQ(dynamic(11), *object.get_ptr("one"));
const dynamic& cobject = object;
EXPECT_EQ(dynamic(2), *cobject.get_ptr("two"));
}
开发者ID:AddictXQ,项目名称:folly,代码行数:17,代码来源:DynamicTest.cpp
示例20: dynamic
TEST(Dynamic, FormattedIO) {
std::ostringstream out;
dynamic doubl = 123.33;
dynamic dint = 12;
out << "0x" << std::hex << ++dint << ' ' << std::setprecision(1)
<< doubl << '\n';
EXPECT_EQ(out.str(), "0xd 1e+02\n");
out.str("");
dynamic arrr = { 1, 2, 3 };
out << arrr;
EXPECT_EQ(out.str(), "[1,2,3]");
out.str("");
dynamic objy = dynamic::object("a", 12);
out << objy;
EXPECT_EQ(out.str(), R"({"a":12})");
out.str("");
dynamic objy2 = { objy, dynamic::object(12, "str"),
dynamic::object(true, false) };
out << objy2;
EXPECT_EQ(out.str(), R"([{"a":12},{12:"str"},{true:false}])");
}
TEST(Dynamic, GetSetDefaultTest) {
dynamic d1 = dynamic::object("foo", "bar");
EXPECT_EQ(d1.getDefault("foo", "baz"), "bar");
EXPECT_EQ(d1.getDefault("quux", "baz"), "baz");
dynamic d2 = dynamic::object("foo", "bar");
EXPECT_EQ(d2.setDefault("foo", "quux"), "bar");
d2.setDefault("bar", dynamic({})).push_back(42);
EXPECT_EQ(d2["bar"][0], 42);
dynamic d3 = dynamic::object, empty = dynamic::object;
EXPECT_EQ(d3.getDefault("foo"), empty);
d3.setDefault("foo")["bar"] = "baz";
EXPECT_EQ(d3["foo"]["bar"], "baz");
// we do not allow getDefault/setDefault on arrays
dynamic d4 = dynamic({});
EXPECT_ANY_THROW(d4.getDefault("foo", "bar"));
EXPECT_ANY_THROW(d4.setDefault("foo", "bar"));
}
开发者ID:Abioy,项目名称:folly,代码行数:45,代码来源:DynamicTest.cpp
注:本文中的folly类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论