Struct binary_data_schema::Bitfield [−][src]
A schema referencing some bits within a chunk of bytes.
Implementations
impl Bitfield
[src]
pub fn new(bytes: usize, bits: usize, offset: usize) -> Result<Self>
[src]
Create a new bitfield.
pub fn bits(&self) -> usize
[src]
Width of the bitfield in bits.
pub fn bytes(&self) -> usize
[src]
pub fn mask(&self) -> u64
[src]
Mask to select the bits covered by the bitfield.
pub fn read(&self, value: u64) -> u64
[src]
Read the value of the bitfield from bytes.
pub fn write(&self, value: u64, target: &mut u64)
[src]
Write the value to the described bitfield.
Example
use binary_data_schema::Bitfield; let bf = Bitfield::new(2, 3, 7)?; let mut buffer = 0; bf.write(21, &mut buffer); // 21 & 0b111 = 5; assert_eq!(buffer, (5 << 7));
Trait Implementations
impl Clone for Bitfield
[src]
impl Copy for Bitfield
[src]
impl Debug for Bitfield
[src]
impl Decoder for Bitfield
[src]
impl Default for Bitfield
[src]
impl Encoder for Bitfield
[src]
fn encode<W>(&self, target: &mut W, value: &Value) -> Result<usize> where
W: Write + WriteBytesExt,
[src]
W: Write + WriteBytesExt,
impl From<Bitfield> for IntegerSchema
[src]
impl From<Bitfield> for BooleanSchema
[src]
Auto Trait Implementations
impl RefUnwindSafe for Bitfield
[src]
impl Send for Bitfield
[src]
impl Sync for Bitfield
[src]
impl Unpin for Bitfield
[src]
impl UnwindSafe for Bitfield
[src]
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
pub fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> ToOwned for T where
T: Clone,
[src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
pub fn to_owned(&self) -> T
[src]
pub fn clone_into(&self, target: &mut T)
[src]
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
pub fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,