From ede39aee7e00c40a43b67ca18dd8ab80ee863d85 Mon Sep 17 00:00:00 2001 From: Mason Reed Date: Tue, 26 Aug 2025 23:59:38 -0400 Subject: [WARP] Enhanced network support --- plugins/warp/src/plugin/ffi/file.rs | 38 +++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 plugins/warp/src/plugin/ffi/file.rs (limited to 'plugins/warp/src/plugin/ffi/file.rs') diff --git a/plugins/warp/src/plugin/ffi/file.rs b/plugins/warp/src/plugin/ffi/file.rs new file mode 100644 index 00000000..951b5eb2 --- /dev/null +++ b/plugins/warp/src/plugin/ffi/file.rs @@ -0,0 +1,38 @@ +use std::ffi::c_char; +use std::sync::Arc; +use warp::WarpFile; + +pub type BNWARPFile = WarpFile<'static>; + +// TODO: At some point we may want to expose chunks directly. For now we will just enumerate all of them. +// pub type BNWARPChunk = warp::chunk::Chunk<'static>; + +// TODO: From bytes as well. +#[no_mangle] +pub unsafe extern "C" fn BNWARPNewFileFromPath(path: *mut c_char) -> *mut BNWARPFile { + let path_cstr = unsafe { std::ffi::CStr::from_ptr(path) }; + let Ok(path) = path_cstr.to_str() else { + return std::ptr::null_mut(); + }; + let Ok(bytes) = std::fs::read(path) else { + return std::ptr::null_mut(); + }; + let Some(file) = WarpFile::from_owned_bytes(bytes) else { + return std::ptr::null_mut(); + }; + Arc::into_raw(Arc::new(file)) as *mut BNWARPFile +} + +#[no_mangle] +pub unsafe extern "C" fn BNWARPNewFileReference(file: *mut BNWARPFile) -> *mut BNWARPFile { + Arc::increment_strong_count(file); + file +} + +#[no_mangle] +pub unsafe extern "C" fn BNWARPFreeFileReference(file: *mut BNWARPFile) { + if file.is_null() { + return; + } + Arc::decrement_strong_count(file); +} -- cgit v1.3.1