proto_tower_util/
debug.rs

1/// Display the data in hex format
2/// with rows of 16 bytes (2 columns of 8 bytes)
3pub fn debug_hex(data: &[u8]) -> String {
4    let mut result = String::new();
5    // Print header
6    result.push_str("    0  1  2  3  4  5  6  7   8  9  a  b  c  d  e  f\n");
7    for (row_num, chunk) in data.chunks(16).enumerate() {
8        if row_num > 0 {
9            result.push('\n');
10        }
11        result.push_str(&format!("{:02x} ", (row_num % 16) * 16));
12        for (col_num, byte) in chunk.iter().enumerate() {
13            if col_num > 0 {
14                result.push(' ');
15            }
16            if col_num == 8 {
17                result.push(' ');
18            }
19            result.push_str(&format!("{:02x}", byte));
20        }
21    }
22    result
23}