diff --git a/src/to-json/src/ffi.rs b/src/to-json/src/ffi.rs new file mode 100644 index 0000000..fef3e3a --- /dev/null +++ b/src/to-json/src/ffi.rs @@ -0,0 +1,18 @@ +use std::ffi::{c_char, CStr, CString}; + +#[no_mangle] +pub unsafe extern "C" fn free_rust_string(string: *const c_char) { + let _ = CString::from_raw(string as *mut _); +} + +#[no_mangle] +pub unsafe extern "C" fn to_json_rust(content: *const c_char) -> *const c_char { + let content: &str = CStr::from_ptr(content).to_str().unwrap(); + + // TODO: remove test code + println!("Raw content -> {}", content); + + // TODO: convert to JSON format + + CString::new(content).unwrap().into_raw() +} diff --git a/src/to-json/src/lib.rs b/src/to-json/src/lib.rs index 1ece23a..57ae9b9 100644 --- a/src/to-json/src/lib.rs +++ b/src/to-json/src/lib.rs @@ -1,15 +1 @@ -use std::ffi::{c_char, CStr, CString}; - -#[no_mangle] -pub unsafe extern "C" fn to_json_rust(content: *const c_char) -> *const c_char { - let content: &str = CStr::from_ptr(content).to_str().unwrap(); - - println!("Raw content -> {}", content); - - CString::new(content).unwrap().into_raw() -} - -#[no_mangle] -pub unsafe extern "C" fn free_rust_string(string: *const c_char) { - let _ = CString::from_raw(string as *mut _); -} +mod ffi;