pub unsafe fn libusb_get_string_descriptor(
dev_handle: *mut libusb_device_handle,
desc_index: u8,
langid: u16,
data: *mut c_uchar,
length: c_int,
) -> c_intExamples found in repository?
examples/read_device.rs (line 110)
108fn get_language_ids(handle: *mut ::ffi::libusb_device_handle) -> Vec<u16> {
109 let mut buf = Vec::<u8>::with_capacity(255);
110 let len = unsafe { ::ffi::libusb_get_string_descriptor(handle, 0, 0, (&mut buf[..]).as_mut_ptr() as *mut c_uchar, buf.capacity() as c_int) };
111
112 let mut languages = Vec::<u16>::new();
113
114 if len >= 0 {
115 unsafe { buf.set_len(len as usize) };
116
117 if buf.len() >= 2 {
118 let num_languages = (buf.len() - 2) / 2;
119 languages.reserve(num_languages);
120
121 let mut cursor = Cursor::new(buf);
122 cursor.set_position(2);
123
124 for _ in 0..num_languages {
125 let mut bytes = Vec::<u8>::with_capacity(2);
126
127 match cursor.read(unsafe { slice::from_raw_parts_mut((&mut bytes[..]).as_mut_ptr(), bytes.capacity()) }) {
128 Ok(len) => {
129 if len == 2 {
130 unsafe { bytes.set_len(len) };
131
132 let langid = (bytes[1] as u16) << 8 | (bytes[0] as u16);
133 languages.push(langid)
134 }
135 else {
136 return languages;
137 }
138 },
139 Err(_) => return languages
140 }
141 }
142 }
143 }
144 else {
145 println!("libusb_get_string_descriptor: {}", len);
146 }
147
148 languages
149}