Trait bitlab::ExtractBitsFromVecU8 [] [src]

pub trait ExtractBitsFromVecU8 {
    fn get_u8(
        &self,
        byte_offset: usize,
        start: usize,
        length: usize
    ) -> Result<u8, &'static str>;
fn get_i8(
        &self,
        byte_offset: usize,
        start: usize,
        length: usize
    ) -> Result<i8, &'static str>;
fn get_u16(
        &self,
        byte_offset: usize,
        start: usize,
        length: usize
    ) -> Result<u16, &'static str>;
fn get_i16(
        &self,
        byte_offset: usize,
        start: usize,
        length: usize
    ) -> Result<i16, &'static str>;
fn get_u32(
        &self,
        byte_offset: usize,
        start: usize,
        length: usize
    ) -> Result<u32, &'static str>;
fn get_i32(
        &self,
        byte_offset: usize,
        start: usize,
        length: usize
    ) -> Result<i32, &'static str>; }

Defines a number of functions, which extract a range of bits from a Vec There is one function for each variable type to be returned Important: the contents of the vectored are assumed to be in big endian (network) order

Required Methods

Extracts a range of bits from a Vec and returns a Result object containing a 8 bit unsigned integer or an error message.

On success, the Result contains the desired value

On error, the Result contains an error message. This may happen if:

  • bit_offset > 7
  • length > 8
  • byte_offset * 8 + bit_offset + length > vector (source data) size in bits

Parameters:

  • byte_offset (usize) the number of bytes to skip in source
  • bit_offset (usize) the start position of the bits to be extracted. Zero is the most significant bit
  • length (usize) the number of bits to be extracted.

Extracts a range of bits from a Vec and returns a Result object containing a signed 8 bit integer or an error message.

On success, the Result contains the desired value

On error, the Result contains an error message. This may happen if:

  • bit_offset > 7
  • length > 8
  • byte_offset * 8 + bit_offset + length > vector (source data) size in bits

Parameters:

  • byte_offset (usize) the number of bytes to skip in source
  • bit_offset (usize) the start position of the bits to be extracted. Zero is the most significant bit
  • length (usize) the number of bits to be extracted.

Extracts a range of bits from a Vec and returns a Result object containing a 16 bit unsigned integer or an error message.

On success, the Result contains the desired value

On error, the Result contains an error message. This may happen if:

  • bit_offset > 7
  • length > 16
  • byte_offset * 8 + bit_offset + length > vector (source data) size in bits

Parameters:

  • byte_offset (usize) the number of bytes to skip in source
  • bit_offset (usize) the start position of the bits to be extracted. Zero is the most significant bit
  • length (usize) the number of bits to be extracted.

Extracts a range of bits from a Vec and returns a Result object containing a signed 16 bit integer or an error message.

On success, the Result contains the desired value

On error, the Result contains an error message. This may happen if:

  • bit_offset > 7
  • length > 16
  • byte_offset * 8 + bit_offset + length > vector (source data) size in bits

Parameters:

  • byte_offset (usize) the number of bytes to skip in source
  • bit_offset (usize) the start position of the bits to be extracted. Zero is the most significant bit
  • length (usize) the number of bits to be extracted.

Extracts a range of bits from a Vec and returns a Result object containing a 32 bit unsigned integer or an error message.

On success, the Result contains the desired value

On error, the Result contains an error message. This may happen if:

  • bit_offset > 7
  • length > 32
  • byte_offset * 8 + bit_offset + length > vector (source data) size in bits

Parameters:

  • byte_offset (usize) the number of bytes to skip in source
  • bit_offset (usize) the start position of the bits to be extracted. Zero is the most significant bit
  • length (usize) the number of bits to be extracted.

Extracts a range of bits from a Vec and returns a Result object containing a signed 32 bit integer or an error message.

On success, the Result contains the desired value

On error, the Result contains an error message. This may happen if:

  • bit_offset > 7
  • length > 32
  • byte_offset * 8 + bit_offset + length > vector (source data) size in bits

Parameters:

  • byte_offset (usize) the number of bytes to skip in source
  • bit_offset (usize) the start position of the bits to be extracted. Zero is the most significant bit
  • length (usize) the number of bits to be extracted.

Implementations on Foreign Types

impl ExtractBitsFromVecU8 for Vec<u8>
[src]

[src]

[src]

[src]

[src]

[src]

[src]

Implementors