Skip to content

Commit

Permalink
make swap_art_bytes usable as a library
Browse files Browse the repository at this point in the history
  • Loading branch information
DarkRTA committed Mar 30, 2024
1 parent aa58479 commit d9c9508
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 11 deletions.
9 changes: 9 additions & 0 deletions crates/swap_art_bytes/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
pub fn swap_art_bytes(buf: &mut [u8]) {
for i in (32..buf.len()).step_by(2) {
let byte1 = buf[i];
let byte2 = buf[i + 1];

buf[i] = byte2;
buf[i + 1] = byte1;
}
}
14 changes: 3 additions & 11 deletions crates/swap_art_bytes/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ use std::path::Path;

use clap::Parser;

use swap_art_bytes::swap_art_bytes;

#[derive(clap::Parser)]
struct Args {
input_file: Box<Path>,
Expand All @@ -11,18 +13,8 @@ struct Args {

fn main() -> Result<(), Box<dyn Error>> {
let args = Args::parse();

let mut buf = std::fs::read(args.input_file)?;

for i in (32..buf.len()).step_by(2) {
let byte1 = buf[i];
let byte2 = buf[i + 1];

buf[i] = byte2;
buf[i + 1] = byte1;
}

swap_art_bytes(&mut buf);
std::fs::write(args.output_file, buf)?;

Ok(())
}

0 comments on commit d9c9508

Please sign in to comment.