display a hexdump of the entire packet, not just the body

This commit is contained in:
Gered 2021-11-26 12:06:23 -05:00
parent ccd61e685b
commit 81b600c410
2 changed files with 13 additions and 5 deletions

View file

@ -347,11 +347,13 @@ pub fn analyze(path: &Path) -> Result<()> {
pso_packet.header.flags(),
pso_packet.header.size()
);
if pso_packet.body.is_empty() {
println!("<No data>");
} else {
println!("{:?}", pso_packet.body.hex_conf(hex_cfg));
}
// get full packet bytes for the hex dump since it is probably useful most
// of the time to include the header bytes alongside the body
// TODO: this feels sloppy ...
let mut packet_bytes = Vec::new();
pso_packet.write_bytes(&mut packet_bytes)?;
println!("{:?}", packet_bytes.hex_conf(hex_cfg));
println!();
}
}

View file

@ -90,6 +90,12 @@ impl GenericPacket {
})
}
pub fn write_bytes<T: WriteBytesExt>(&self, writer: &mut T) -> Result<(), PacketError> {
self.header.write_bytes(writer)?;
writer.write_all(self.body.as_ref())?;
Ok(())
}
pub fn size(&self) -> usize {
self.header.size as usize + self.body.len()
}