-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
JNI for fs-storage
#90
Comments
I'm currently implementing the java bindings for fs-storage using the jni crate. Here are a few points and open question that will decide the design -
pub trait BaseStorage<K, V>: AsRef<BTreeMap<K, V>> {
/// Create or update an entry in the internal mapping.
fn set(&mut self, id: K, value: V);
/// Remove an entry from the internal mapping.
fn remove(&mut self, id: &K) -> Result<()>;
/// Check if the storage is up-to-date,
/// i.e. that the internal mapping is consistent
/// with the data in the filesystem.
fn is_storage_updated(&self) -> Result<bool>;
/// Scan and load the key-value mapping
/// from pre-configured location in the filesystem.
fn read_fs(&mut self) -> Result<BTreeMap<K, V>>;
/// Persist the internal key-value mapping
/// to pre-configured location in the filesystem.
fn write_fs(&mut self) -> Result<()>;
/// Remove all persisted data
/// by pre-configured location in the file-system.
fn erase(&self) -> Result<()>;
}
For e.g. pub extern "system" fn Java_FileStorage_create(
env: &mut JNIEnv,
_class: JClass,
label: JString,
path: JString,
key_type: JString,
value_type: JString,
) -> jlong {
let label: String = env.get_string(&label).unwrap().into();
let path: String = env.get_string(&path).unwrap().into();
let key_type: String = env.get_string(&label).unwrap().into();
let value_type: String = env.get_string(&path).unwrap().into();
// specialize FileStorage based on function arguments
if key_type == "string" && value_type == "score" {
let file_storage: FileStorage<String, Score> = FileStorage::new(label, Path::new(&path));
Box::into_raw(Box::new(file_storage)) as jlong
}
} The complexity can be reduced by removing the generic parameter K for Key because from the use cases I've seen keys are always strings. What are your thoughts on this? |
@twitu fixing the type parameter for keys to always be Probably we can just start with binding |
After this issue is completed:
fs-storage
: PortBaseStorage
abstraction from Kotlin ark-core#18We'll need to:
fs-storage
The text was updated successfully, but these errors were encountered: