mirror of
https://codeberg.org/icewind/bitbuffer.git
synced 2026-06-03 16:44:06 +02:00
implement Debug
This commit is contained in:
parent
29ca7e359e
commit
6e36d00c1e
6 changed files with 48 additions and 14 deletions
|
|
@ -1,12 +1,16 @@
|
|||
use crate::endianness::Endianness;
|
||||
use crate::is_signed::IsSigned;
|
||||
use crate::{ReadError, Result};
|
||||
use num_traits::{Float, PrimInt};
|
||||
use std::cmp::min;
|
||||
use std::fmt;
|
||||
use std::fmt::Debug;
|
||||
use std::marker::PhantomData;
|
||||
use std::mem::size_of;
|
||||
use std::ops::BitOrAssign;
|
||||
|
||||
use num_traits::{Float, PrimInt};
|
||||
|
||||
use crate::endianness::Endianness;
|
||||
use crate::is_signed::IsSigned;
|
||||
use crate::{ReadError, Result};
|
||||
|
||||
const USIZE_SIZE: usize = size_of::<usize>();
|
||||
|
||||
/// Buffer that allows reading integers of arbitrary bit length and non byte-aligned integers
|
||||
|
|
@ -290,7 +294,7 @@ where
|
|||
let usable_bytes = if E::is_le() {
|
||||
&bytes[0..read]
|
||||
} else {
|
||||
&bytes[8-read..8]
|
||||
&bytes[8 - read..8]
|
||||
};
|
||||
data.extend_from_slice(usable_bytes);
|
||||
byte_left -= read;
|
||||
|
|
@ -406,3 +410,18 @@ impl<E: Endianness> From<Vec<u8>> for BitBuffer<E> {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<E: Endianness> Debug for BitBuffer<E> {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
write!(
|
||||
f,
|
||||
"BitBuffer {{ bit_len: {}, endianness: {} }}",
|
||||
self.bit_len,
|
||||
if E::is_le() {
|
||||
"LittleEndian"
|
||||
} else {
|
||||
"BigEndian"
|
||||
}
|
||||
)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -7,9 +7,11 @@ pub trait Endianness {
|
|||
}
|
||||
|
||||
/// Marks the buffer or stream as big endian
|
||||
#[derive(Debug)]
|
||||
pub struct BigEndian;
|
||||
|
||||
/// Marks the buffer or stream as little endian
|
||||
#[derive(Debug)]
|
||||
pub struct LittleEndian;
|
||||
|
||||
macro_rules! impl_endianness {
|
||||
|
|
|
|||
|
|
@ -25,6 +25,7 @@ use crate::{BitRead, BitReadSized, ReadError, Result};
|
|||
/// ```
|
||||
///
|
||||
/// [`BitBuffer`]: struct.BitBuffer.html
|
||||
#[derive(Debug)]
|
||||
pub struct BitStream<E>
|
||||
where
|
||||
E: Endianness,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue