1 /// A wrapper for the output slice used when decompressing.
3 /// Using this rather than `Cursor` lets us implement the writing methods directly on
4 /// the buffer and lets us use a usize rather than u64 for the position which helps with
5 /// performance on 32-bit systems.
6 pub struct OutputBuffer
<'a
> {
11 impl<'a
> OutputBuffer
<'a
> {
13 pub fn from_slice_and_pos(slice
: &'a
mut [u8], position
: usize) -> OutputBuffer
<'a
> {
14 OutputBuffer { slice, position }
18 pub fn position(&self) -> usize {
23 pub fn set_position(&mut self, position
: usize) {
24 self.position
= position
;
27 /// Write a byte to the current position and increment
29 /// Assumes that there is space.
31 pub fn write_byte(&mut self, byte
: u8) {
32 self.slice
[self.position
] = byte
;
36 /// Write a slice to the current position and increment
38 /// Assumes that there is space.
40 pub fn write_slice(&mut self, data
: &[u8]) {
42 self.slice
[self.position
..self.position
+ len
].copy_from_slice(data
);
43 self.position
+= data
.len();
47 pub fn bytes_left(&self) -> usize {
48 self.slice
.len() - self.position
52 pub fn get_ref(&self) -> &[u8] {
57 pub fn get_mut(&mut self) -> &mut [u8] {