Skip to content

Commit

Permalink
Added read + jump methods to file
Browse files Browse the repository at this point in the history
  • Loading branch information
Le0X8 committed Jul 12, 2024
1 parent 748f788 commit fc6fd21
Showing 1 changed file with 48 additions and 1 deletion.
49 changes: 48 additions & 1 deletion src/file.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ impl<'a> File<'a> {
}

pub fn readj_u8(&mut self) -> u8 {
// TODO: Apply this to all read methods
let data = self.read_u8();
self.jump(1);
data
Expand All @@ -67,45 +66,93 @@ impl<'a> File<'a> {
u16::from_le_bytes(buf)
}

pub fn readj_u16le(&mut self) -> u16 {
let data = self.read_u16le();
self.jump(2);
data
}

pub fn read_u16be(&mut self) -> u16 {
let mut buf = [0; 2];
self.read(&mut buf);
u16::from_be_bytes(buf)
}

pub fn readj_u16be(&mut self) -> u16 {
let data = self.read_u16be();
self.jump(2);
data
}

pub fn read_u32le(&mut self) -> u32 {
let mut buf = [0; 4];
self.read(&mut buf);
u32::from_le_bytes(buf)
}

pub fn readj_u32le(&mut self) -> u32 {
let data = self.read_u32le();
self.jump(4);
data
}

pub fn read_u32be(&mut self) -> u32 {
let mut buf = [0; 4];
self.read(&mut buf);
u32::from_be_bytes(buf)
}

pub fn readj_u32be(&mut self) -> u32 {
let data = self.read_u32be();
self.jump(4);
data
}

pub fn read_u64le(&mut self) -> u64 {
let mut buf = [0; 8];
self.read(&mut buf);
u64::from_le_bytes(buf)
}

pub fn readj_u64le(&mut self) -> u64 {
let data = self.read_u64le();
self.jump(8);
data
}

pub fn read_u64be(&mut self) -> u64 {
let mut buf = [0; 8];
self.read(&mut buf);
u64::from_be_bytes(buf)
}

pub fn readj_u64be(&mut self) -> u64 {
let data = self.read_u64be();
self.jump(8);
data
}

pub fn read_u128le(&mut self) -> u128 {
let mut buf = [0; 16];
self.read(&mut buf);
u128::from_le_bytes(buf)
}

pub fn readj_u128le(&mut self) -> u128 {
let data = self.read_u128le();
self.jump(16);
data
}

pub fn read_u128be(&mut self) -> u128 {
let mut buf = [0; 16];
self.read(&mut buf);
u128::from_be_bytes(buf)
}

pub fn readj_u128be(&mut self) -> u128 {
let data = self.read_u128be();
self.jump(16);
data
}
}

0 comments on commit fc6fd21

Please sign in to comment.