From: John Spray Date: Tue, 25 Mar 2014 13:30:31 +0000 (+0000) Subject: common: Add write_stream(ostream) to bufferlist X-Git-Tag: v0.82~48^2~48 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=d4a250ca797165bf9c78514a806e67c16788d495;p=ceph.git common: Add write_stream(ostream) to bufferlist Enable C++ style file I/O when writing binary output from bufferlists. Signed-off-by: John Spray --- diff --git a/src/common/buffer.cc b/src/common/buffer.cc index bfafa31f7212..f2b1e0674322 100644 --- a/src/common/buffer.cc +++ b/src/common/buffer.cc @@ -1692,6 +1692,20 @@ __u32 buffer::list::crc32c(__u32 crc) const return crc; } + +/** + * Binary write all contents to a C++ stream + */ +void buffer::list::write_stream(std::ostream &out) const +{ + for (std::list::const_iterator p = _buffers.begin(); p != _buffers.end(); ++p) { + if (p->length() > 0) { + out.write(p->c_str(), p->length()); + } + } +} + + void buffer::list::hexdump(std::ostream &out) const { std::ios_base::fmtflags original_flags = out.flags(); diff --git a/src/include/buffer.h b/src/include/buffer.h index 5491105f9487..e5c1b5053584 100644 --- a/src/include/buffer.h +++ b/src/include/buffer.h @@ -429,6 +429,7 @@ public: void encode_base64(list& o); void decode_base64(list& o); + void write_stream(std::ostream &out) const; void hexdump(std::ostream &out) const; int read_file(const char *fn, std::string *error); ssize_t read_fd(int fd, size_t len);