Skip to content

Commit 6638fe4

Browse files
committed
chore: small refactoring
1 parent 8f96aa4 commit 6638fe4

File tree

2 files changed

+12
-5
lines changed

2 files changed

+12
-5
lines changed

crates/signum/src/images/imc.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ pub struct ImcHeader {
3535
/// size of byte-stream
3636
size_of_data: u32,
3737
/// Final XOR
38-
final_xor: u16,
38+
final_xor: Bytes16,
3939
u4: Bytes16,
4040
u5: Bytes32,
4141
u6: Bytes32,
@@ -66,7 +66,7 @@ fn parse_imc_header(input: &[u8]) -> IResult<&[u8], ImcHeader> {
6666
let (input, size_of_bits) = be_u32(input)?;
6767
let (input, size_of_data) = be_u32(input)?;
6868

69-
let (input, s14) = be_u16(input)?;
69+
let (input, final_xor) = bytes16(input)?;
7070
let (input, u4) = bytes16(input)?;
7171
let (input, u5) = bytes32(input)?;
7272
let (input, u6) = bytes32(input)?;
@@ -79,7 +79,7 @@ fn parse_imc_header(input: &[u8]) -> IResult<&[u8], ImcHeader> {
7979
vchunks,
8080
size_of_bits,
8181
size_of_data,
82-
final_xor: s14,
82+
final_xor,
8383
u4,
8484
u5,
8585
u6,
@@ -261,8 +261,8 @@ pub fn decode_imc(src: &[u8]) -> IResult<&[u8], (ImcHeader, MonochromeScreen)> {
261261
dest = &mut dest[bytes_per_group..];
262262
}
263263

264-
if header.final_xor != 0 {
265-
let [a, b] = header.final_xor.to_be_bytes();
264+
if header.final_xor.0 != 0 {
265+
let [a, b] = header.final_xor.to_bytes();
266266
/*// subroutine K
267267
268268
state.proc_l(a, &mut buffer[..], header.s08, header.s0a);

crates/signum/src/util/bytes.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,13 @@ use serde::{Deserialize, Serialize};
77
#[serde(transparent)]
88
pub struct Bytes16(pub u16);
99

10+
impl Bytes16 {
11+
/// Return the bytes in big endian order
12+
pub fn to_bytes(&self) -> [u8; 2] {
13+
self.0.to_be_bytes()
14+
}
15+
}
16+
1017
impl fmt::Debug for Bytes16 {
1118
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
1219
write!(f, "0x{:04X}", self.0)

0 commit comments

Comments
 (0)