mirror of
https://codeberg.org/icewind/bitbuffer.git
synced 2026-06-03 16:44:06 +02:00
dont store bit_len seperatly for stream
This commit is contained in:
parent
dce12b6da1
commit
cfb4f37fc0
1 changed files with 4 additions and 8 deletions
|
|
@ -33,7 +33,6 @@ where
|
||||||
buffer: BitBuffer<E>,
|
buffer: BitBuffer<E>,
|
||||||
start_pos: usize,
|
start_pos: usize,
|
||||||
pos: usize,
|
pos: usize,
|
||||||
bit_len: usize,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<E> BitStream<E>
|
impl<E> BitStream<E>
|
||||||
|
|
@ -60,7 +59,6 @@ where
|
||||||
BitStream {
|
BitStream {
|
||||||
start_pos: 0,
|
start_pos: 0,
|
||||||
pos: 0,
|
pos: 0,
|
||||||
bit_len: buffer.bit_len(),
|
|
||||||
buffer,
|
buffer,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -315,7 +313,6 @@ where
|
||||||
buffer: self.buffer.get_sub_buffer(self.pos + count)?,
|
buffer: self.buffer.get_sub_buffer(self.pos + count)?,
|
||||||
start_pos: self.pos,
|
start_pos: self.pos,
|
||||||
pos: self.pos,
|
pos: self.pos,
|
||||||
bit_len: count,
|
|
||||||
};
|
};
|
||||||
self.pos += count;
|
self.pos += count;
|
||||||
Ok(result)
|
Ok(result)
|
||||||
|
|
@ -381,10 +378,10 @@ where
|
||||||
///
|
///
|
||||||
/// [`ReadError::IndexOutOfBounds`]: enum.ReadError.html#variant.IndexOutOfBounds
|
/// [`ReadError::IndexOutOfBounds`]: enum.ReadError.html#variant.IndexOutOfBounds
|
||||||
pub fn set_pos(&mut self, pos: usize) -> Result<()> {
|
pub fn set_pos(&mut self, pos: usize) -> Result<()> {
|
||||||
if pos > self.bit_len {
|
if pos > self.bit_len() {
|
||||||
return Err(ReadError::IndexOutOfBounds {
|
return Err(ReadError::IndexOutOfBounds {
|
||||||
pos,
|
pos,
|
||||||
size: self.bit_len,
|
size: self.bit_len(),
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
self.pos = pos + self.start_pos;
|
self.pos = pos + self.start_pos;
|
||||||
|
|
@ -411,7 +408,7 @@ where
|
||||||
/// # }
|
/// # }
|
||||||
/// ```
|
/// ```
|
||||||
pub fn bit_len(&self) -> usize {
|
pub fn bit_len(&self) -> usize {
|
||||||
self.bit_len
|
self.buffer.bit_len() - self.start_pos
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Get the current position in the stream
|
/// Get the current position in the stream
|
||||||
|
|
@ -461,7 +458,7 @@ where
|
||||||
/// # }
|
/// # }
|
||||||
/// ```
|
/// ```
|
||||||
pub fn bits_left(&self) -> usize {
|
pub fn bits_left(&self) -> usize {
|
||||||
self.bit_len - self.pos()
|
self.bit_len() - self.pos()
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Read a value based on the provided type
|
/// Read a value based on the provided type
|
||||||
|
|
@ -572,7 +569,6 @@ impl<E: Endianness> Clone for BitStream<E> {
|
||||||
buffer: self.buffer.clone(),
|
buffer: self.buffer.clone(),
|
||||||
start_pos: self.pos,
|
start_pos: self.pos,
|
||||||
pos: self.pos,
|
pos: self.pos,
|
||||||
bit_len: self.bit_len,
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue