Skip to content

having a field with 12 bits #29

Description

@delfick

Hi,

I have a struct that looks like

#[derive(PackedStruct, Debug, Copy, Clone, PartialEq, Default)]
#[packed_struct(bit_numbering = "lsb0", size_bytes = "8")]
pub struct Header {
    #[packed_field(bits = "15:0", endian = "lsb")]
    pub size: u16,
    #[packed_field(bits = "27:16", endian = "lsb")]
    pub protocol: u16,
    #[packed_field(bits = "28:28", endian = "lsb")]
    pub addressable: bool,
    #[packed_field(bits = "29:29", endian = "lsb")]
    pub tagged: bool,
    #[packed_field(bits = "31:30", endian = "lsb")]
    _reserved1: ReservedZero<packed_bits::Bits2>,
    #[packed_field(bits = "63:32", endian = "lsb")]
    pub source: u32,
}

The problem though is I get this errors

error[E0277]: the trait bound `packed_struct::types::bits::Bits12: packed_struct::types::bits::BitsFullBytes` is not satisfied
 --> src/header.rs:3:10
  |
3 | #[derive(PackedStruct, Debug, Copy, Clone, PartialEq, Default)]
  |          ^^^^^^^^^^^^ the trait `packed_struct::types::bits::BitsFullBytes` is not implemented for `packed_struct::types::bits::Bits12`
  |
  = note: required because of the requirements on the impl of `packed_struct::PackedStruct<[u8; 2]>` for `packed_struct::types::LsbInteger<u16, packed_struct::types::bits::Bits12, packed_struct::types::Integer<u16, packed_struct::types::bits::Bits12>>`

error[E0277]: the trait bound `packed_struct::types::bits::Bits12: packed_struct::types::bits::BitsFullBytes` is not satisfied
 --> src/header.rs:3:10
  |
3 | #[derive(PackedStruct, Debug, Copy, Clone, PartialEq, Default)]
  |          ^^^^^^^^^^^^ the trait `packed_struct::types::bits::BitsFullBytes` is not implemented for `packed_struct::types::bits::Bits12`
  |
  = note: required because of the requirements on the impl of `packed_struct::PackedStruct<[u8; 2]>` for `packed_struct::types::LsbInteger<u16, packed_struct::types::bits::Bits12, packed_struct::types::Integer<u16, packed_struct::types::bits::Bits12>>`
  = note: required by `packed_struct::PackedStruct::unpack`

error[E0614]: type `packed_struct::types::LsbInteger<u16, packed_struct::types::bits::Bits12, packed_struct::types::Integer<u16, packed_struct::types::bits::Bits12>>` cannot be dereferenced
 --> src/header.rs:3:10
  |
3 | #[derive(PackedStruct, Debug, Copy, Clone, PartialEq, Default)]
  |          ^^^^^^^^^^^^

It seems the problem is because the second two bytes are split over 4 fields (12 bits, 1 bit, 1 bit, 2 bits)

is it possible at all to have a PackedStruct with BitsPartialBytes fields ?

Thanks

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions