Commit 15a9e67 1 parent 9ef5b54 commit 15a9e67 Copy full SHA for 15a9e67
File tree 2 files changed +19
-1
lines changed
2 files changed +19
-1
lines changed Original file line number Diff line number Diff line change @@ -62,6 +62,8 @@ pub struct HexConfig {
62
62
pub chunk : usize ,
63
63
/// Maximum bytes to print.
64
64
pub max_bytes : usize ,
65
+ /// Offset added to displayed address prefix
66
+ pub display_offset : usize ,
65
67
}
66
68
67
69
/// Default configuration with `title`, `ascii`, 16 source bytes `width` grouped to 4 separate
@@ -75,6 +77,7 @@ impl Default for HexConfig {
75
77
group : 4 ,
76
78
chunk : 1 ,
77
79
max_bytes : usize:: MAX ,
80
+ display_offset : 0 ,
78
81
}
79
82
}
80
83
}
@@ -136,7 +139,7 @@ where
136
139
let lines_len = lines. len ( ) ;
137
140
for ( i, row) in lines. enumerate ( ) {
138
141
if cfg. width > 0 {
139
- write ! ( writer, "{:04x}: " , i * cfg. width) ?;
142
+ write ! ( writer, "{:04x}: " , i * cfg. width + cfg . display_offset ) ?;
140
143
}
141
144
for ( i, x) in row. as_ref ( ) . iter ( ) . enumerate ( ) {
142
145
write ! ( writer, "{}{:02x}" , cfg. delimiter( i) , x) ?;
Original file line number Diff line number Diff line change @@ -57,6 +57,7 @@ fn test_config() {
57
57
group : 0 ,
58
58
chunk : 0 ,
59
59
max_bytes : usize:: MAX ,
60
+ display_offset : 0
60
61
} ;
61
62
assert ! ( config_hex( & vec![ ] , cfg) . is_empty( ) ) ;
62
63
assert_eq ! ( "2425262728" , config_hex( & "$%&'(" , cfg) ) ;
@@ -95,6 +96,18 @@ fn test_config() {
95
96
0010: 89d5 cf90 2367 4b48 dbb1 bc35 bfee"
96
97
) ;
97
98
99
+ assert_eq ! (
100
+ config_hex( & v,
101
+ HexConfig {
102
+ ascii: false ,
103
+ display_offset: 0x200 ,
104
+ ..cfg
105
+ }
106
+ ) ,
107
+ "0200: 6b 4e 1a c3 af 03 d2 1e 7e 73 ba c8 bd 84 0f 83\n \
108
+ 0210: 89 d5 cf 90 23 67 4b 48 db b1 bc 35 bf ee"
109
+ ) ;
110
+
98
111
let v: Vec < u8 > = ( 0 ..21 ) . collect ( ) ;
99
112
let want = r##"Length: 21 (0x15) bytes
100
113
0000: 00 01 02 03 04 05 06 07 08 09 0a 0b 0c 0d 0e 0f ................
@@ -111,6 +124,7 @@ fn test_config() {
111
124
group: 2 ,
112
125
chunk: 3 ,
113
126
max_bytes: usize :: MAX ,
127
+ display_offset: 0
114
128
} ) ,
115
129
"0000: 000102 030405 060708 090a ...........\n \
116
130
000b: 0b0c .."
@@ -126,6 +140,7 @@ fn test_config() {
126
140
group: 3 ,
127
141
chunk: 3 ,
128
142
max_bytes: usize :: MAX ,
143
+ display_offset: 0
129
144
}
130
145
) ,
131
146
"0000: 000102 030405 060708 090a0b 0c0d0e 0f ................\n \
You can’t perform that action at this time.
0 commit comments