From 46522cf0d27ad7d236f61bf132c915210754a0f4 Mon Sep 17 00:00:00 2001 From: Sage Weil Date: Fri, 20 May 2016 10:28:52 -0400 Subject: [PATCH] buffer: add no-newline hexdump option Signed-off-by: Sage Weil --- src/common/buffer.cc | 12 ++++++++---- src/include/buffer.h | 2 +- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/src/common/buffer.cc b/src/common/buffer.cc index baf97828091..b809d92621f 100644 --- a/src/common/buffer.cc +++ b/src/common/buffer.cc @@ -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); } diff --git a/src/include/buffer.h b/src/include/buffer.h index 9441cd583d2..a4e89005a5c 100644 --- a/src/include/buffer.h +++ b/src/include/buffer.h @@ -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); -- 2.39.5