diff options
Diffstat (limited to 'unpacker')
-rw-r--r-- | unpacker/Cargo.lock | 7 | ||||
-rw-r--r-- | unpacker/Cargo.toml | 8 | ||||
-rw-r--r-- | unpacker/src/lib.rs | 44 | ||||
-rw-r--r-- | unpacker/src/main.rs | 31 |
4 files changed, 0 insertions, 90 deletions
diff --git a/unpacker/Cargo.lock b/unpacker/Cargo.lock deleted file mode 100644 index 44d0a0f..0000000 --- a/unpacker/Cargo.lock +++ /dev/null @@ -1,7 +0,0 @@ -# This file is automatically @generated by Cargo. -# It is not intended for manual editing. -version = 3 - -[[package]] -name = "unpacker" -version = "0.1.0" diff --git a/unpacker/Cargo.toml b/unpacker/Cargo.toml deleted file mode 100644 index 147529a..0000000 --- a/unpacker/Cargo.toml +++ /dev/null @@ -1,8 +0,0 @@ -[package] -name = "unpacker" -version = "0.1.0" -edition = "2021" - -# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html - -[dependencies] diff --git a/unpacker/src/lib.rs b/unpacker/src/lib.rs deleted file mode 100644 index f649581..0000000 --- a/unpacker/src/lib.rs +++ /dev/null @@ -1,44 +0,0 @@ -#[derive(Debug)] -pub struct Unpacker { - pub out: Vec<u8>, - pub work: u16, - pub work_idx: usize, -} - -impl Unpacker { - pub fn new() -> Self { - Self { - out: vec![], - work: 0, - work_idx: 0, - } - } - - pub fn push(&mut self, byte: u8) { - self.work = self.work << 8; - self.work |= byte as u16; - self.work_idx += 8; - - //println!("[{work_idx}]"); - - if self.work_idx >= 10 { - let to_front = self.work_idx - 10; - let fronted = self.work >> to_front; - let masked = fronted & 0b000_000_111_11_111_11; - - let fixwork = fronted << to_front; - - self.out.extend(masked.to_le_bytes()); - self.work_idx -= 10; - self.work ^= fixwork; - } - } - - pub fn finish(&mut self) { - if self.work_idx > 0 { - let remain = 10 - self.work_idx; - let out = self.work << remain; - self.out.extend(out.to_le_bytes()) - } - } -} diff --git a/unpacker/src/main.rs b/unpacker/src/main.rs deleted file mode 100644 index 36d8131..0000000 --- a/unpacker/src/main.rs +++ /dev/null @@ -1,31 +0,0 @@ -use unpacker::Unpacker; - -fn main() { - // Four bits padding at the end. - let testdata = vec![ - 0b10000000, 0b00010000, 0b00000010, 0b00000000, 0b01000000, 0b00001000, 0b00000001, - 0b00000000, 0b00100000, 0b00000100, 0b00000000, 0b10000000, 0b00010000, - ]; - - let mut up = Unpacker { - out: vec![], - work: 0, - work_idx: 0, - }; - - let count = (10.0 as f32 * (10.0 / 8.0)).ceil() as usize; - for byte in testdata { - up.push(byte); - - if count == up.out.len() { - break; - } - } - if count > up.out.len() { - up.finish(); - } - - for chnk in up.out.chunks(2) { - println!("{:02b} {:08b}", chnk[1], chnk[0]); - } -} |