MCPcopy Create free account
hub / github.com/facebook/CacheLib / writeToBuffer

Method writeToBuffer

cachelib/common/Serialization.cpp:32–49  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

30}
31
32size_t Serializer::writeToBuffer(std::unique_ptr<folly::IOBuf> ioBuf) {
33 XDCHECK_LT(reinterpret_cast<uintptr_t>(curr_),
34 reinterpret_cast<uintptr_t>(end_));
35 if (!ioBuf) {
36 throw std::invalid_argument("IOBuf is nullptr");
37 }
38 ioBuf->coalesce(); // coalesece the chain of IOBufs into one single IOBuf
39 const auto length = ioBuf->length();
40 if (bytesRemaining() < length) {
41 throw std::length_error(
42 fmt::format("Buffer insufficient for serialization."
43 "Has {} bytes left. Need {} bytes.",
44 bytesRemaining(), length));
45 }
46 memcpy(curr_, ioBuf->data(), length);
47 curr_ += length;
48 return length;
49}
50
51Deserializer::Deserializer(const uint8_t* begin, const uint8_t* const end)
52 : curr_(begin), end_(end) {}

Callers 4

saveRamCacheMethod · 0.80
persistMethod · 0.80
TESTFunction · 0.80
resetMethod · 0.80

Calls 1

dataMethod · 0.45

Tested by 1

TESTFunction · 0.64