mirror of
https://codeberg.org/icewind/bitbuffer.git
synced 2026-06-03 16:44:06 +02:00
new_owned
This commit is contained in:
parent
9f5a9c5391
commit
65f3280b1b
1 changed files with 29 additions and 1 deletions
|
|
@ -105,7 +105,7 @@ impl<'a, E> BitReadBuffer<'a, E>
|
||||||
where
|
where
|
||||||
E: Endianness,
|
E: Endianness,
|
||||||
{
|
{
|
||||||
/// Create a new BitBuffer from a byte vector
|
/// Create a new BitBuffer from a byte slice
|
||||||
///
|
///
|
||||||
/// # Examples
|
/// # Examples
|
||||||
///
|
///
|
||||||
|
|
@ -129,6 +129,34 @@ where
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl<E> BitReadBuffer<'static, E>
|
||||||
|
where
|
||||||
|
E: Endianness,
|
||||||
|
{
|
||||||
|
/// Create a new BitBuffer from a byte vector
|
||||||
|
///
|
||||||
|
/// # Examples
|
||||||
|
///
|
||||||
|
/// ```
|
||||||
|
/// use bitbuffer::{BitReadBuffer, LittleEndian};
|
||||||
|
///
|
||||||
|
/// let bytes = vec![
|
||||||
|
/// 0b1011_0101, 0b0110_1010, 0b1010_1100, 0b1001_1001,
|
||||||
|
/// 0b1001_1001, 0b1001_1001, 0b1001_1001, 0b1110_0111
|
||||||
|
/// ];
|
||||||
|
/// let buffer = BitReadBuffer::new_owned(bytes, LittleEndian);
|
||||||
|
/// ```
|
||||||
|
pub fn new_owned(bytes: Vec<u8>, _endianness: E) -> Self {
|
||||||
|
let byte_len = bytes.len();
|
||||||
|
|
||||||
|
BitReadBuffer {
|
||||||
|
bytes: Data::Owned(Rc::new(bytes)),
|
||||||
|
bit_len: byte_len * 8,
|
||||||
|
endianness: PhantomData,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
pub(crate) fn get_bits_from_usize<E: Endianness>(
|
pub(crate) fn get_bits_from_usize<E: Endianness>(
|
||||||
val: usize,
|
val: usize,
|
||||||
bit_offset: usize,
|
bit_offset: usize,
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue