chainLength_ = 0;
}
+void IOBufQueue::appendToString(std::string& out) const {
+ if (!head_) {
+ return;
+ }
+ auto len =
+ options_.cacheChainLength ? chainLength_ : head_->computeChainDataLength();
+ out.reserve(out.size() + len);
+
+ for (auto range : *head_) {
+ out.append(reinterpret_cast<const char*>(range.data()), range.size());
+ }
+}
+
} // folly
*/
void clear();
+ /**
+ * Append the queue to a std::string. Non-destructive.
+ */
+ void appendToString(std::string& out) const;
+
/** Movable */
IOBufQueue(IOBufQueue&&) noexcept;
IOBufQueue& operator=(IOBufQueue&&);
EXPECT_EQ(0, queue.chainLength());
}
+TEST(IOBufQueue, AppendToString) {
+ IOBufQueue queue;
+ queue.append("hello ", 6);
+ queue.append("world", 5);
+ std::string s;
+ queue.appendToString(s);
+ EXPECT_EQ("hello world", s);
+}
+
int main(int argc, char** argv) {
testing::InitGoogleTest(&argc, argv);
gflags::ParseCommandLineFlags(&argc, &argv, true);