]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
common: Add write_stream(ostream) to bufferlist
authorJohn Spray <john.spray@inktank.com>
Tue, 25 Mar 2014 13:30:31 +0000 (13:30 +0000)
committerJohn Spray <john.spray@inktank.com>
Sun, 18 May 2014 10:21:28 +0000 (11:21 +0100)
Enable C++ style file I/O when writing binary output
from bufferlists.

Signed-off-by: John Spray <john.spray@inktank.com>
src/common/buffer.cc
src/include/buffer.h

index bfafa31f7212fa283a2aed80f74b914b597f5d81..f2b1e06743222b281a8ca7b56bd90fc6adc69c46 100644 (file)
@@ -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<ptr>::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();
index 5491105f948747e5cfc48894295e0fc271e0219b..e5c1b5053584408b14634f69ca84646b07cf7a4d 100644 (file)
@@ -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);