mirror of
https://codeberg.org/icewind/bitbuffer.git
synced 2026-06-03 16:44:06 +02:00
impl ReadSized for BitStream
This commit is contained in:
parent
af83f5e3b3
commit
4bf39b874d
3 changed files with 13 additions and 3 deletions
12
src/read.rs
12
src/read.rs
|
|
@ -84,7 +84,10 @@ impl<E: Endianness> BitRead<E> for String {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Trait for types that can be read from a stream wit requiring the size to be configured
|
/// Trait for types that can be read from a stream, requiring the size to be configured
|
||||||
|
///
|
||||||
|
/// The meaning of the set sized depends on the type being read (e.g, number of bits for integers,
|
||||||
|
/// number of bytes for strings, number of items for Vec's, etc)
|
||||||
pub trait BitReadSized<E: Endianness>: Sized {
|
pub trait BitReadSized<E: Endianness>: Sized {
|
||||||
/// Read the type from stream
|
/// Read the type from stream
|
||||||
fn read(stream: &mut BitStream<E>, size: usize) -> Result<Self>;
|
fn read(stream: &mut BitStream<E>, size: usize) -> Result<Self>;
|
||||||
|
|
@ -130,6 +133,13 @@ impl<E: Endianness, T: BitRead<E>> BitRead<E> for Option<T> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl<E: Endianness> BitReadSized<E> for BitStream<E> {
|
||||||
|
#[inline(always)]
|
||||||
|
fn read(stream: &mut BitStream<E>, size: usize) -> Result<Self> {
|
||||||
|
stream.read_bits(size)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// Read `T` `size` times and return as `Vec<T>`
|
/// Read `T` `size` times and return as `Vec<T>`
|
||||||
impl<E: Endianness, T: BitRead<E>> BitReadSized<E> for Vec<T> {
|
impl<E: Endianness, T: BitRead<E>> BitReadSized<E> for Vec<T> {
|
||||||
fn read(stream: &mut BitStream<E>, size: usize) -> Result<Self> {
|
fn read(stream: &mut BitStream<E>, size: usize) -> Result<Self> {
|
||||||
|
|
|
||||||
|
|
@ -7,7 +7,7 @@ use num_traits::{Float, PrimInt};
|
||||||
use crate::endianness::Endianness;
|
use crate::endianness::Endianness;
|
||||||
use crate::is_signed::IsSigned;
|
use crate::is_signed::IsSigned;
|
||||||
use crate::BitBuffer;
|
use crate::BitBuffer;
|
||||||
use crate::{BitRead, ReadError, BitReadSized, Result};
|
use crate::{BitRead, BitReadSized, ReadError, Result};
|
||||||
|
|
||||||
/// Stream that provides an easy way to iterate trough a [`BitBuffer`]
|
/// Stream that provides an easy way to iterate trough a [`BitBuffer`]
|
||||||
///
|
///
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
use bitstream_reader::{BigEndian, BitBuffer, BitStream, LittleEndian, BitRead};
|
use bitstream_reader::{BigEndian, BitBuffer, BitRead, BitStream, LittleEndian};
|
||||||
|
|
||||||
// for bench on nightly
|
// for bench on nightly
|
||||||
//use std::fs;
|
//use std::fs;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue