summaryrefslogtreecommitdiffstats
path: root/tool
diff options
context:
space:
mode:
authorJustus Winter <justus@sequoia-pgp.org>2019-04-11 13:19:11 +0200
committerJustus Winter <justus@sequoia-pgp.org>2019-04-12 12:41:51 +0200
commitecfae7e26d9b1bef7a35d671bce93a469ad28ac3 (patch)
tree7e8d5569e4cf019001483de3e9dc8a5e71545cd1 /tool
parent6b8e5c59d44047e4c462235c17753187254bf052 (diff)
tool: Support indenting hexdumps.
Diffstat (limited to 'tool')
-rw-r--r--tool/src/commands/dump.rs10
1 files changed, 6 insertions, 4 deletions
diff --git a/tool/src/commands/dump.rs b/tool/src/commands/dump.rs
index 8d7a5afb..2858b332 100644
--- a/tool/src/commands/dump.rs
+++ b/tool/src/commands/dump.rs
@@ -412,7 +412,7 @@ impl PacketDumper {
if let Some(map) = map {
writeln!(output)?;
- let mut hd = HexDumper::new();
+ let mut hd = HexDumper::new("");
for field in map.iter() {
hd.write(output, field.data, field.name)?;
}
@@ -561,12 +561,14 @@ impl PacketDumper {
}
pub struct HexDumper {
+ indent: String,
offset: usize,
}
impl HexDumper {
- pub fn new() -> Self {
+ pub fn new<I: AsRef<str>>(indent: I) -> Self {
HexDumper {
+ indent: indent.as_ref().into(),
offset: 0,
}
}
@@ -574,7 +576,7 @@ impl HexDumper {
pub fn write(&mut self, sink: &mut io::Write, buf: &[u8], msg: &str)
-> Result<()> {
let mut msg_printed = false;
- write!(sink, "{:08x} ", self.offset)?;
+ write!(sink, "{}{:08x} ", self.indent, self.offset)?;
for i in 0 .. self.offset % 16 {
if i != 7 {
write!(sink, " ")?;
@@ -593,7 +595,7 @@ impl HexDumper {
msg_printed = true;
}
- write!(sink, "\n{:08x} ", self.offset)?;
+ write!(sink, "\n{}{:08x} ", self.indent, self.offset)?;
},
8 => write!(sink, " ")?,
_ => (),