@
freehere 我的这一步会出错,CStr::from_ptr(raw).to_str(), 你的出错吗?
#[no_mangle]
pub extern "C" fn decode(raw: *const libc::c_char) -> *mut u32 {
if raw.is_null() {
return ptr::null_mut();
}
if let Ok(str_raw) = unsafe { CStr::from_ptr(raw).to_str() } {
println!("str_raw: {:?}", str_raw);
let bytes_raw = hex::decode(str_raw).unwrap();
let mut u8_fixed: [u32; 6] = Decode::decode(&mut &bytes_raw[..]).unwrap();
let ptr = u8_fixed.as_mut_ptr();
std::mem::forget(u8_fixed);
ptr
} else {
println!("str_raw fail");
return ptr::null_mut();
}
}
pub fn main() {
let raw = "010000000200000003000000040000000500000006000000";
let aa = decode(raw.as_ptr() as *const i8);
println!("{:?}", aa);
}