Skip to content

Commit 695ca28

Browse files
aligned copy, mut buf skip
1 parent a0703b8 commit 695ca28

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

src/lib.rs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,12 @@ impl<'a> BitBuf<'a> {
6060
}
6161
}
6262

63+
pub fn copy_aligned(&mut self, dst: &mut [u8]) -> Result<(), Insufficient> {
64+
Ok(for i in 0..dst.len() {
65+
dst[i] = self.byte_at_offset(i * 8).ok_or(Insufficient)?;
66+
})
67+
}
68+
6369
pub fn copy_to_slice(&mut self, dst: &mut [u8], bits: usize) -> Result<(), CopyError> {
6470
let bytes = bits / 8;
6571
let len = dst.len();
@@ -108,4 +114,15 @@ impl<'a> BitBufMut<'a> {
108114
pub fn new(data: &'a mut [u8]) -> Self {
109115
BitBufMut { data, prefix: 0 }
110116
}
117+
118+
pub fn skip(&'a mut self, bits: usize) -> Result<(), Insufficient> {
119+
self.prefix += (bits & 7) as u8;
120+
if self.prefix >= 8 {
121+
self.prefix -= 8;
122+
self.data = self.data.get_mut((bits / 8) + 1..).ok_or(Insufficient)?;
123+
} else {
124+
self.data = self.data.get_mut(bits / 8..).ok_or(Insufficient)?;
125+
}
126+
Ok(())
127+
}
111128
}

0 commit comments

Comments
 (0)