#[macro_export]
macro_rules! rhexdump {
($data:expr) => {{
$crate::INSTANCE.with(|i|
$crate::hexdump::RhexdumpStdout::with_config(*i.borrow()).hexdump_bytes($data)
)
}};
($data:expr, $offset:expr) => {{
$crate::INSTANCE.with(|i|
$crate::hexdump::RhexdumpStdout::with_config(*i.borrow()).hexdump_bytes_offset($data, $offset)
)
}};
}
#[macro_export]
macro_rules! rhexdumps {
($data:expr) => {{
$crate::INSTANCE.with(|i|
$crate::hexdump::RhexdumpString::with_config(*i.borrow()).hexdump_bytes($data)
)
}};
($data:expr, $offset:expr) => {{
$crate::INSTANCE.with(|i|
$crate::hexdump::RhexdumpString::with_config(*i.borrow()).hexdump_bytes_offset($data, $offset)
)
}};
}
#[macro_export]
macro_rules! rhexdump_install {
($config:expr) => {{
$crate::INSTANCE.with(|i| {
*i.borrow_mut() = $config;
});
}};
}
#[cfg(test)]
mod tests {
use crate::prelude::*;
#[test]
fn rhx_macro_rhexdump() {
let v = (0..0x14).collect::<Vec<u8>>();
rhexdump!(&v);
rhexdump!(&v, 0x12340000);
}
#[test]
fn rhx_macro_rhexdumps() {
let v = (0..0x14).collect::<Vec<u8>>();
let output = rhexdumps!(&v);
assert_eq!(
&output,
"00000000: 00 01 02 03 04 05 06 07 08 09 0a 0b 0c 0d 0e 0f ................\n\
00000010: 10 11 12 13 ....\n"
);
let output = rhexdumps!(&v, 0x12340000);
assert_eq!(
&output,
"12340000: 00 01 02 03 04 05 06 07 08 09 0a 0b 0c 0d 0e 0f ................\n\
12340010: 10 11 12 13 ....\n"
);
}
#[test]
fn rhx_macro_install() {
let v = (0..0x14).collect::<Vec<u8>>();
let output = rhexdumps!(&v);
assert_eq!(
&output,
"00000000: 00 01 02 03 04 05 06 07 08 09 0a 0b 0c 0d 0e 0f ................\n\
00000010: 10 11 12 13 ....\n"
);
let config = RhexdumpBuilder::new()
.base(Base::Oct)
.bit_width(BitWidth::BW64)
.group_size(GroupSize::Word)
.groups_per_line(4)
.config();
rhexdump_install!(config);
let output = rhexdumps!(&v);
assert_eq!(
&output,
"0000000000000000: 000400 001402 002404 003406 ........\n\
0000000000000008: 004410 005412 006414 007416 ........\n\
0000000000000010: 010420 011422 ....\n"
);
}
}