mirror of
https://codeberg.org/icewind/bitbuffer.git
synced 2026-06-03 16:44:06 +02:00
remove seperate bitskip trait
This commit is contained in:
parent
88c9c21d74
commit
9596419833
2 changed files with 20 additions and 13 deletions
|
|
@ -62,7 +62,7 @@ pub use std::string::FromUtf8Error;
|
||||||
pub use bitstream_reader_derive::{BitRead, BitReadSized};
|
pub use bitstream_reader_derive::{BitRead, BitReadSized};
|
||||||
pub use buffer::BitBuffer;
|
pub use buffer::BitBuffer;
|
||||||
pub use endianness::*;
|
pub use endianness::*;
|
||||||
pub use read::{BitRead, BitReadSized, BitSkip, LazyBitRead, LazyBitReadSized};
|
pub use read::{BitRead, BitReadSized, LazyBitRead, LazyBitReadSized};
|
||||||
pub use stream::BitStream;
|
pub use stream::BitStream;
|
||||||
|
|
||||||
mod buffer;
|
mod buffer;
|
||||||
|
|
|
||||||
31
src/read.rs
31
src/read.rs
|
|
@ -100,25 +100,22 @@ pub trait BitRead<E: Endianness>: Sized {
|
||||||
Self::read(stream)
|
Self::read(stream)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// The number of bits that will be read or None if the number of bits will change depending
|
|
||||||
/// on the bit stream
|
|
||||||
#[inline(always)]
|
|
||||||
fn bit_size() -> Option<usize> {
|
|
||||||
return None;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Trait to allow skipping a type
|
|
||||||
///
|
|
||||||
/// This might be faster than trying to read it
|
|
||||||
pub trait BitSkip<E: Endianness>: BitRead<E> {
|
|
||||||
/// Skip the type
|
/// Skip the type
|
||||||
|
///
|
||||||
|
/// This might be faster than reading it if the size is known beforehand
|
||||||
fn skip(stream: &mut BitStream<E>) -> Result<()> {
|
fn skip(stream: &mut BitStream<E>) -> Result<()> {
|
||||||
match Self::bit_size() {
|
match Self::bit_size() {
|
||||||
Some(size) => stream.skip_bits(size),
|
Some(size) => stream.skip_bits(size),
|
||||||
None => Self::read(stream).map(|_| ()),
|
None => Self::read(stream).map(|_| ()),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// The number of bits that will be read or None if the number of bits will change depending
|
||||||
|
/// on the bit stream
|
||||||
|
#[inline(always)]
|
||||||
|
fn bit_size() -> Option<usize> {
|
||||||
|
return None;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
macro_rules! impl_read_int {
|
macro_rules! impl_read_int {
|
||||||
|
|
@ -403,6 +400,16 @@ pub trait BitReadSized<E: Endianness>: Sized {
|
||||||
Self::read(stream, size)
|
Self::read(stream, size)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Skip the type
|
||||||
|
///
|
||||||
|
/// This might be faster than reading it if the size is known beforehand
|
||||||
|
fn skip(stream: &mut BitStream<E>, size: usize) -> Result<()> {
|
||||||
|
match Self::bit_size_sized(size) {
|
||||||
|
Some(size) => stream.skip_bits(size),
|
||||||
|
None => Self::read(stream, size).map(|_| ()),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// The number of bits that will be read or None if the number of bits will change depending
|
/// The number of bits that will be read or None if the number of bits will change depending
|
||||||
/// on the bit stream
|
/// on the bit stream
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue