Compare commits

..

1 Commits

Author SHA1 Message Date
4e3387cef9
feat: implement a full SSV_LireConfig output parsing, using deku for a declarative bytes parsing
Co-authored-by: theo <t.lettermann@criteo.com>
2024-10-04 22:16:58 +02:00

View File

@ -122,30 +122,30 @@ impl SSV {
/// # Get the configuration of the SSV library
/// Implement: SSV_LireConfig
pub fn get_config(&self) -> Result<Data, Error> {
let mut buffer_ptr: *mut libc::c_void = ptr::null_mut();
let mut size: libc::size_t = 0;
let mut out_buffer_ptr: *mut libc::c_void = ptr::null_mut();
let mut out_buffer_size: libc::size_t = 0;
let result = match &self.library {
SsvLibraryVersion::V1_40_13(library) => {
unsafe { library.ssv_lire_config(&mut buffer_ptr, &mut size) }?
unsafe { library.ssv_lire_config(&mut out_buffer_ptr, &mut out_buffer_size) }?
},
SsvLibraryVersion::V1_40_14(library) => {
unsafe { library.ssv_lire_config(&mut buffer_ptr, &mut size) }?
unsafe { library.ssv_lire_config(&mut out_buffer_ptr, &mut out_buffer_size) }?
},
};
if result != 0 {
// Free memory
unsafe { libc::free(buffer_ptr) };
unsafe { libc::free(out_buffer_ptr) };
let error = SSVErrorCodes::from(result);
return Err(Error::SSVError(error));
}
// Print the buffer
let buffer = unsafe { std::slice::from_raw_parts(buffer_ptr as *const u8, size) };
// Parse the buffer into a Data struct
let buffer = unsafe { std::slice::from_raw_parts(out_buffer_ptr as *const u8, out_buffer_size) };
let (_rest, config_blocks) = Data::from_bytes((buffer, 0)).unwrap();
// Free memory
unsafe { libc::free(buffer_ptr) };
unsafe { libc::free(out_buffer_ptr) };
Ok(config_blocks)
}
}