• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 #![allow(
2     dead_code,
3     non_snake_case,
4     non_camel_case_types,
5     non_upper_case_globals
6 )]
7 
8 #[repr(C)]
9 #[derive(Copy, Clone, Debug, Default, Eq, Hash, Ord, PartialEq, PartialOrd)]
10 pub struct __BindgenBitfieldUnit<Storage> {
11     storage: Storage,
12 }
13 impl<Storage> __BindgenBitfieldUnit<Storage> {
14     #[inline]
new(storage: Storage) -> Self15     pub const fn new(storage: Storage) -> Self {
16         Self { storage }
17     }
18 }
19 impl<Storage> __BindgenBitfieldUnit<Storage>
20 where
21     Storage: AsRef<[u8]> + AsMut<[u8]>,
22 {
23     #[inline]
get_bit(&self, index: usize) -> bool24     pub fn get_bit(&self, index: usize) -> bool {
25         debug_assert!(index / 8 < self.storage.as_ref().len());
26         let byte_index = index / 8;
27         let byte = self.storage.as_ref()[byte_index];
28         let bit_index = if cfg!(target_endian = "big") {
29             7 - (index % 8)
30         } else {
31             index % 8
32         };
33         let mask = 1 << bit_index;
34         byte & mask == mask
35     }
36     #[inline]
set_bit(&mut self, index: usize, val: bool)37     pub fn set_bit(&mut self, index: usize, val: bool) {
38         debug_assert!(index / 8 < self.storage.as_ref().len());
39         let byte_index = index / 8;
40         let byte = &mut self.storage.as_mut()[byte_index];
41         let bit_index = if cfg!(target_endian = "big") {
42             7 - (index % 8)
43         } else {
44             index % 8
45         };
46         let mask = 1 << bit_index;
47         if val {
48             *byte |= mask;
49         } else {
50             *byte &= !mask;
51         }
52     }
53     #[inline]
get(&self, bit_offset: usize, bit_width: u8) -> u6454     pub fn get(&self, bit_offset: usize, bit_width: u8) -> u64 {
55         debug_assert!(bit_width <= 64);
56         debug_assert!(bit_offset / 8 < self.storage.as_ref().len());
57         debug_assert!(
58             (bit_offset + (bit_width as usize)) / 8 <=
59                 self.storage.as_ref().len()
60         );
61         let mut val = 0;
62         for i in 0..(bit_width as usize) {
63             if self.get_bit(i + bit_offset) {
64                 let index = if cfg!(target_endian = "big") {
65                     bit_width as usize - 1 - i
66                 } else {
67                     i
68                 };
69                 val |= 1 << index;
70             }
71         }
72         val
73     }
74     #[inline]
set(&mut self, bit_offset: usize, bit_width: u8, val: u64)75     pub fn set(&mut self, bit_offset: usize, bit_width: u8, val: u64) {
76         debug_assert!(bit_width <= 64);
77         debug_assert!(bit_offset / 8 < self.storage.as_ref().len());
78         debug_assert!(
79             (bit_offset + (bit_width as usize)) / 8 <=
80                 self.storage.as_ref().len()
81         );
82         for i in 0..(bit_width as usize) {
83             let mask = 1 << i;
84             let val_bit_is_set = val & mask == mask;
85             let index = if cfg!(target_endian = "big") {
86                 bit_width as usize - 1 - i
87             } else {
88                 i
89             };
90             self.set_bit(index + bit_offset, val_bit_is_set);
91         }
92     }
93 }
94 #[repr(C, packed)]
95 #[derive(Debug, Default, Copy, Clone)]
96 pub struct Foo {
97     pub _bitfield_align_1: [u8; 0],
98     pub _bitfield_1: __BindgenBitfieldUnit<[u8; 1usize]>,
99 }
100 #[test]
bindgen_test_layout_Foo()101 fn bindgen_test_layout_Foo() {
102     assert_eq!(
103         ::std::mem::size_of::<Foo>(),
104         1usize,
105         concat!("Size of: ", stringify!(Foo))
106     );
107     assert_eq!(
108         ::std::mem::align_of::<Foo>(),
109         1usize,
110         concat!("Alignment of ", stringify!(Foo))
111     );
112 }
113 extern "C" {
114     #[link_name = "\u{1}_ZN3Foo4typeEv"]
Foo_type(this: *mut Foo) -> ::std::os::raw::c_char115     pub fn Foo_type(this: *mut Foo) -> ::std::os::raw::c_char;
116 }
117 extern "C" {
118     #[link_name = "\u{1}_ZN3Foo9set_type_Ec"]
Foo_set_type_(this: *mut Foo, c: ::std::os::raw::c_char)119     pub fn Foo_set_type_(this: *mut Foo, c: ::std::os::raw::c_char);
120 }
121 extern "C" {
122     #[link_name = "\u{1}_ZN3Foo8set_typeEc"]
Foo_set_type(this: *mut Foo, c: ::std::os::raw::c_char)123     pub fn Foo_set_type(this: *mut Foo, c: ::std::os::raw::c_char);
124 }
125 impl Foo {
126     #[inline]
type__bindgen_bitfield(&self) -> ::std::os::raw::c_char127     pub fn type__bindgen_bitfield(&self) -> ::std::os::raw::c_char {
128         unsafe {
129             ::std::mem::transmute(self._bitfield_1.get(0usize, 3u8) as u8)
130         }
131     }
132     #[inline]
set_type__bindgen_bitfield(&mut self, val: ::std::os::raw::c_char)133     pub fn set_type__bindgen_bitfield(&mut self, val: ::std::os::raw::c_char) {
134         unsafe {
135             let val: u8 = ::std::mem::transmute(val);
136             self._bitfield_1.set(0usize, 3u8, val as u64)
137         }
138     }
139     #[inline]
new_bitfield_1( type__bindgen_bitfield: ::std::os::raw::c_char, ) -> __BindgenBitfieldUnit<[u8; 1usize]>140     pub fn new_bitfield_1(
141         type__bindgen_bitfield: ::std::os::raw::c_char,
142     ) -> __BindgenBitfieldUnit<[u8; 1usize]> {
143         let mut __bindgen_bitfield_unit: __BindgenBitfieldUnit<[u8; 1usize]> =
144             Default::default();
145         __bindgen_bitfield_unit.set(0usize, 3u8, {
146             let type__bindgen_bitfield: u8 =
147                 unsafe { ::std::mem::transmute(type__bindgen_bitfield) };
148             type__bindgen_bitfield as u64
149         });
150         __bindgen_bitfield_unit
151     }
152     #[inline]
type_(&mut self) -> ::std::os::raw::c_char153     pub unsafe fn type_(&mut self) -> ::std::os::raw::c_char {
154         Foo_type(self)
155     }
156     #[inline]
set_type_(&mut self, c: ::std::os::raw::c_char)157     pub unsafe fn set_type_(&mut self, c: ::std::os::raw::c_char) {
158         Foo_set_type_(self, c)
159     }
160     #[inline]
set_type(&mut self, c: ::std::os::raw::c_char)161     pub unsafe fn set_type(&mut self, c: ::std::os::raw::c_char) {
162         Foo_set_type(self, c)
163     }
164 }
165