1 #![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] 2 #[repr(C)] 3 #[derive(Copy, Clone, Debug, Default, Eq, Hash, Ord, PartialEq, PartialOrd)] 4 pub struct __BindgenBitfieldUnit<Storage> { 5 storage: Storage, 6 } 7 impl<Storage> __BindgenBitfieldUnit<Storage> { 8 #[inline] new(storage: Storage) -> Self9 pub const fn new(storage: Storage) -> Self { 10 Self { storage } 11 } 12 } 13 impl<Storage> __BindgenBitfieldUnit<Storage> 14 where 15 Storage: AsRef<[u8]> + AsMut<[u8]>, 16 { 17 #[inline] get_bit(&self, index: usize) -> bool18 pub fn get_bit(&self, index: usize) -> bool { 19 debug_assert!(index / 8 < self.storage.as_ref().len()); 20 let byte_index = index / 8; 21 let byte = self.storage.as_ref()[byte_index]; 22 let bit_index = if cfg!(target_endian = "big") { 23 7 - (index % 8) 24 } else { 25 index % 8 26 }; 27 let mask = 1 << bit_index; 28 byte & mask == mask 29 } 30 #[inline] set_bit(&mut self, index: usize, val: bool)31 pub fn set_bit(&mut self, index: usize, val: bool) { 32 debug_assert!(index / 8 < self.storage.as_ref().len()); 33 let byte_index = index / 8; 34 let byte = &mut self.storage.as_mut()[byte_index]; 35 let bit_index = if cfg!(target_endian = "big") { 36 7 - (index % 8) 37 } else { 38 index % 8 39 }; 40 let mask = 1 << bit_index; 41 if val { 42 *byte |= mask; 43 } else { 44 *byte &= !mask; 45 } 46 } 47 #[inline] get(&self, bit_offset: usize, bit_width: u8) -> u6448 pub fn get(&self, bit_offset: usize, bit_width: u8) -> u64 { 49 debug_assert!(bit_width <= 64); 50 debug_assert!(bit_offset / 8 < self.storage.as_ref().len()); 51 debug_assert!( 52 (bit_offset + (bit_width as usize)) / 8 <= self.storage.as_ref().len(), 53 ); 54 let mut val = 0; 55 for i in 0..(bit_width as usize) { 56 if self.get_bit(i + bit_offset) { 57 let index = if cfg!(target_endian = "big") { 58 bit_width as usize - 1 - i 59 } else { 60 i 61 }; 62 val |= 1 << index; 63 } 64 } 65 val 66 } 67 #[inline] set(&mut self, bit_offset: usize, bit_width: u8, val: u64)68 pub fn set(&mut self, bit_offset: usize, bit_width: u8, val: u64) { 69 debug_assert!(bit_width <= 64); 70 debug_assert!(bit_offset / 8 < self.storage.as_ref().len()); 71 debug_assert!( 72 (bit_offset + (bit_width as usize)) / 8 <= self.storage.as_ref().len(), 73 ); 74 for i in 0..(bit_width as usize) { 75 let mask = 1 << i; 76 let val_bit_is_set = val & mask == mask; 77 let index = if cfg!(target_endian = "big") { 78 bit_width as usize - 1 - i 79 } else { 80 i 81 }; 82 self.set_bit(index + bit_offset, val_bit_is_set); 83 } 84 } 85 } 86 #[repr(C)] 87 #[repr(align(4))] 88 #[derive(Debug, Default, Copy, Clone)] 89 pub struct my_struct1 { 90 _bitfield_align_1: [u8; 0], 91 _bitfield_1: __BindgenBitfieldUnit<[u8; 1usize]>, 92 __bindgen_padding_0: [u8; 3usize], 93 } 94 #[allow(clippy::unnecessary_operation, clippy::identity_op)] 95 const _: () = { 96 ["Size of my_struct1"][::std::mem::size_of::<my_struct1>() - 4usize]; 97 ["Alignment of my_struct1"][::std::mem::align_of::<my_struct1>() - 4usize]; 98 }; 99 impl my_struct1 { 100 #[inline] a(&self) -> ::std::os::raw::c_int101 fn a(&self) -> ::std::os::raw::c_int { 102 unsafe { ::std::mem::transmute(self._bitfield_1.get(0usize, 1u8) as u32) } 103 } 104 #[inline] set_a(&mut self, val: ::std::os::raw::c_int)105 fn set_a(&mut self, val: ::std::os::raw::c_int) { 106 unsafe { 107 let val: u32 = ::std::mem::transmute(val); 108 self._bitfield_1.set(0usize, 1u8, val as u64) 109 } 110 } 111 #[inline] new_bitfield_1(a: ::std::os::raw::c_int) -> __BindgenBitfieldUnit<[u8; 1usize]>112 fn new_bitfield_1(a: ::std::os::raw::c_int) -> __BindgenBitfieldUnit<[u8; 1usize]> { 113 let mut __bindgen_bitfield_unit: __BindgenBitfieldUnit<[u8; 1usize]> = Default::default(); 114 __bindgen_bitfield_unit 115 .set( 116 0usize, 117 1u8, 118 { 119 let a: u32 = unsafe { ::std::mem::transmute(a) }; 120 a as u64 121 }, 122 ); 123 __bindgen_bitfield_unit 124 } 125 } 126 #[repr(C)] 127 #[repr(align(4))] 128 #[derive(Debug, Default, Copy, Clone)] 129 pub struct my_struct2 { 130 pub _bitfield_align_1: [u8; 0], 131 pub _bitfield_1: __BindgenBitfieldUnit<[u8; 1usize]>, 132 pub __bindgen_padding_0: [u8; 3usize], 133 } 134 #[allow(clippy::unnecessary_operation, clippy::identity_op)] 135 const _: () = { 136 ["Size of my_struct2"][::std::mem::size_of::<my_struct2>() - 4usize]; 137 ["Alignment of my_struct2"][::std::mem::align_of::<my_struct2>() - 4usize]; 138 }; 139 impl my_struct2 { 140 #[inline] a(&self) -> ::std::os::raw::c_int141 pub fn a(&self) -> ::std::os::raw::c_int { 142 unsafe { ::std::mem::transmute(self._bitfield_1.get(0usize, 1u8) as u32) } 143 } 144 #[inline] set_a(&mut self, val: ::std::os::raw::c_int)145 pub fn set_a(&mut self, val: ::std::os::raw::c_int) { 146 unsafe { 147 let val: u32 = ::std::mem::transmute(val); 148 self._bitfield_1.set(0usize, 1u8, val as u64) 149 } 150 } 151 #[inline] new_bitfield_1( a: ::std::os::raw::c_int, ) -> __BindgenBitfieldUnit<[u8; 1usize]>152 pub fn new_bitfield_1( 153 a: ::std::os::raw::c_int, 154 ) -> __BindgenBitfieldUnit<[u8; 1usize]> { 155 let mut __bindgen_bitfield_unit: __BindgenBitfieldUnit<[u8; 1usize]> = Default::default(); 156 __bindgen_bitfield_unit 157 .set( 158 0usize, 159 1u8, 160 { 161 let a: u32 = unsafe { ::std::mem::transmute(a) }; 162 a as u64 163 }, 164 ); 165 __bindgen_bitfield_unit 166 } 167 } 168