Compare commits
2 Commits
Author | SHA1 | Date | |
---|---|---|---|
0d0d7bacea | |||
c92e078531 |
27
src/lib.rs
27
src/lib.rs
@ -1,3 +1,4 @@
|
|||||||
|
#[inline(always)]
|
||||||
fn print_printable_or_dot(chunk: &[u8]) {
|
fn print_printable_or_dot(chunk: &[u8]) {
|
||||||
for (idx, byte) in chunk.iter().enumerate() {
|
for (idx, byte) in chunk.iter().enumerate() {
|
||||||
if idx > 0 && idx % 8 == 0 {
|
if idx > 0 && idx % 8 == 0 {
|
||||||
@ -12,16 +13,37 @@ fn print_printable_or_dot(chunk: &[u8]) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[inline(always)]
|
||||||
fn print_offset(offset: usize) {
|
fn print_offset(offset: usize) {
|
||||||
print!("{:08x} ", offset);
|
print!("{offset:08x} ");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[inline(always)]
|
||||||
fn print_data_hex(chunk: &[u8]) {
|
fn print_data_hex(chunk: &[u8]) {
|
||||||
for (idx, byte) in chunk.iter().enumerate() {
|
for (idx, byte) in chunk.iter().enumerate() {
|
||||||
if idx > 0 && idx % 8 == 0 {
|
if idx > 0 && idx % 8 == 0 {
|
||||||
print!(" ");
|
print!(" ");
|
||||||
}
|
}
|
||||||
print!("{:02x} ", byte);
|
print!("{byte:02x} ");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[inline(always)]
|
||||||
|
fn print_padding(chunk_len: usize) {
|
||||||
|
// only needs padding if we have less than 16 bytes to show
|
||||||
|
if chunk_len >= 16 {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// padding is 3 spaces per missing byte
|
||||||
|
for _ in 0..(16 - chunk_len) {
|
||||||
|
print!(" ");
|
||||||
|
}
|
||||||
|
|
||||||
|
// if 8 or more bytes are missing we also need pad the space between
|
||||||
|
// 8-bytes left and 8-bytes right
|
||||||
|
if chunk_len <= 8 {
|
||||||
|
print!(" ");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -33,6 +55,7 @@ pub fn print_hex(data: &[u8]) {
|
|||||||
for chunk in chunks {
|
for chunk in chunks {
|
||||||
print_offset(offset);
|
print_offset(offset);
|
||||||
print_data_hex(chunk);
|
print_data_hex(chunk);
|
||||||
|
print_padding(chunk.len());
|
||||||
print_printable_or_dot(chunk);
|
print_printable_or_dot(chunk);
|
||||||
println!();
|
println!();
|
||||||
offset += 16;
|
offset += 16;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user