return _buffers.front().c_str(); // good, we're already contiguous.
}
+ string buffer::list::to_str() const {
+ string s;
+ s.reserve(length());
+ for (std::list<ptr>::const_iterator p = _buffers.begin();
+ p != _buffers.end();
+ ++p) {
+ if (p->length()) {
+ s.append(p->c_str(), p->length());
+ }
+ }
+ return s;
+ }
+
char *buffer::list::get_contiguous(unsigned orig_off, unsigned len)
{
if (orig_off + len > length())
*/
const char& operator[](unsigned n) const;
char *c_str();
+ std::string to_str() const;
+
void substr_of(const list& other, unsigned off, unsigned len);
/// return a pointer to a contiguous extent of the buffer,
ASSERT_EQ((unsigned)1, bl.get_num_buffers());
}
+TEST(BufferList, to_str) {
+ {
+ bufferlist bl;
+ bl.append("foo");
+ ASSERT_EQ(bl.to_str(), string("foo"));
+ }
+ {
+ bufferptr a("foobarbaz", 9);
+ bufferptr b("123456789", 9);
+ bufferptr c("ABCDEFGHI", 9);
+ bufferlist bl;
+ bl.append(a);
+ bl.append(b);
+ bl.append(c);
+ ASSERT_EQ(bl.to_str(), string("foobarbaz123456789ABCDEFGHI"));
+ }
+}
+
TEST(BufferList, get_contiguous) {
{
bufferptr a("foobarbaz", 9);