Struct binary_data_schema::Bitfield[][src]

pub struct Bitfield { /* fields omitted */ }

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]

impl From<Bitfield> for IntegerSchema[src]

impl From<Bitfield> for BooleanSchema[src]

Auto Trait Implementations

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.