Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for reserved bit with arbitrary value #91

Open
iilyak opened this issue May 1, 2022 · 0 comments · May be fixed by #106
Open

Support for reserved bit with arbitrary value #91

iilyak opened this issue May 1, 2022 · 0 comments · May be fixed by #106

Comments

@iilyak
Copy link

iilyak commented May 1, 2022

Currently there is support for reserved bits sets to zero or one.

    #[packed_field(bits="0..=2")]
    _zeroes: ReservedZero<packed_bits::Bits::<3>>,
    #[packed_field(bits="3..=4")]
    _reserved_one: ReservedOne<packed_bits::Bits::<2>>,

However there is no (it seems) way to define a constant value for reserved bits.

I found two approaches to define it.

  1. use constructor
#[derive(PackedStruct, Debug, Clone, PartialEq)]
#[packed_struct(bit_numbering = "msb0", endian = "msb")]
pub struct Status {
    #[packed_field(bits = "0..=3")] // bit numbering is MSB
    _start_flag: Integer<u8, packed_bits::Bits<4>>, // MUST be 0b1100

....
pub const STATUS_FLAG: u8 = 0xA0;
impl Status {
    pub fn new() -> Status {
        Status {
            _start_flag: STATUS_FLAG.into(),
        }
    }
}
  1. define dummy fields for each bit (which makes constructor bigger)
pub struct Status {
     // next four bits represent a constant 0b1100
     _start_flag3: ReservedOne<packed_bits::Bits::<1>>,
     _start_flag2: ReservedOne<packed_bits::Bits::<1>>,
     _start_flag1: ReservedZero<packed_bits::Bits::<1>>,
     _start_flag0: ReservedZero<packed_bits::Bits::<1>>,

It would be amazing if I could pass a constant somehow (ReservedBits<0b1100, packet_bits::Bits<4>>?)

@JomerDev JomerDev linked a pull request Oct 13, 2023 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant