]> git.apps.os.sepia.ceph.com Git - ceph-ci.git/commitdiff
buffer: add no-newline hexdump option
authorSage Weil <sage@redhat.com>
Fri, 20 May 2016 14:28:52 +0000 (10:28 -0400)
committerSage Weil <sage@redhat.com>
Wed, 1 Jun 2016 15:38:53 +0000 (11:38 -0400)
Signed-off-by: Sage Weil <sage@redhat.com>
src/common/buffer.cc
src/include/buffer.h

index baf97828091a4ad1957822ec893f00190656a84c..b809d92621f327e2ed952593a4e8001570260474 100644 (file)
@@ -2339,7 +2339,7 @@ void buffer::list::write_stream(std::ostream &out) const
 }
 
 
-void buffer::list::hexdump(std::ostream &out) const
+void buffer::list::hexdump(std::ostream &out, bool trailing_newline) const
 {
   if (!length())
     return;
@@ -2377,7 +2377,8 @@ void buffer::list::hexdump(std::ostream &out) const
        did_star = false;
       }
     }
-
+    if (o)
+      out << "\n";
     out << std::hex << std::setw(8) << o << " ";
 
     unsigned i;
@@ -2400,9 +2401,12 @@ void buffer::list::hexdump(std::ostream &out) const
       else
        out << '.';
     }
-    out << '|' << std::dec << std::endl;
+    out << '|' << std::dec;
+  }
+  if (trailing_newline) {
+    out << "\n" << std::hex << std::setw(8) << length();
+    out << "\n";
   }
-  out << std::hex << std::setw(8) << length() << "\n";
 
   out.flags(original_flags);
 }
index 9441cd583d2313dca8bcb34d99c83dfd09c06162..a4e89005a5c466167443725046b8792fea543d45 100644 (file)
@@ -580,7 +580,7 @@ namespace buffer CEPH_BUFFER_API {
     void decode_base64(list& o);
 
     void write_stream(std::ostream &out) const;
-    void hexdump(std::ostream &out) const;
+    void hexdump(std::ostream &out, bool trailing_newline = true) const;
     int read_file(const char *fn, std::string *error);
     ssize_t read_fd(int fd, size_t len);
     int read_fd_zero_copy(int fd, size_t len);