first working attempt

This commit is contained in:
jan 2025-04-12 12:06:36 -07:00
commit e2ba1390c6

View file

@ -6,9 +6,44 @@ pub mod records;
pub mod elements;
pub mod library;
use crate::library::read_library;
use byteorder::{ByteOrder, BigEndian};
use std::mem::size_of;
use std::ffi::{CStr, OsStr, c_char};
use std::os::unix::ffi::OsStrExt;
use std::str;
use std::fs;
use std::path::Path;
use arrow::ffi::{to_ffi, FFI_ArrowArray, FFI_ArrowSchema};
use arrow::array::Array;
#[no_mangle]
pub unsafe extern "C" fn read_path(
cpath: *const c_char,
arr: *mut FFI_ArrowArray,
schema: *mut FFI_ArrowSchema,
) {
let cstr = unsafe { CStr::from_ptr(cpath) };
let path: &Path;
if cfg!(unix) {
let osstr = OsStr::from_bytes(cstr.to_bytes());
path = osstr.as_ref();
} else if cfg!(windows) {
let ustr = str::from_utf8(cstr.to_bytes()).expect("Non-UTF8 paths are not supported");
path = ustr.as_ref();
} else {
panic!("Unsupported OS");
}
let input = fs::read(path).expect("File read failed");
let (_input, struct_arr) = read_library(&input).expect("Read failed");
let (mut arr_v, mut schema_v) = to_ffi(&struct_arr.to_data()).unwrap();
*arr = arr_v;
*schema = schema_v;
}
macro_rules! impl_i16be {