Skip to content

Commit

Permalink
Implement Bulk case for Redis to Java value transform
Browse files Browse the repository at this point in the history
  • Loading branch information
jonathanl-bq committed Oct 24, 2023
1 parent ceca27e commit 478c107
Showing 1 changed file with 15 additions and 17 deletions.
32 changes: 15 additions & 17 deletions java/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
use babushka::start_socket_listener;

use jni::objects::{JClass, JObject, JValue};
use jni::JNIEnv;
use jni::sys::jlong;
use jni::sys::jint;
use jni::{
JNIEnv,
sys::jlong,
objects::{JClass, JObject}
};
use std::sync::mpsc;

use redis::Value;

fn redis_value_to_java<'local>(mut env: JNIEnv<'local>, val: Value) -> JObject<'local> {
fn redis_value_to_java<'local>(env: &mut JNIEnv<'local>, val: Value) -> JObject<'local> {
match val {
Value::Nil => JObject::null(),
Value::Status(str) => JObject::from(env.new_string(str).unwrap()),
Expand All @@ -22,16 +23,13 @@ fn redis_value_to_java<'local>(mut env: JNIEnv<'local>, val: Value) -> JObject<'
},
},
Value::Bulk(bulk) => {
let _ = env.throw("Not implemented");
JObject::null()
/*
let elements: &PyList = PyList::new(
py,
bulk.into_iter()
.map(|item| redis_value_to_py(py, item).unwrap()),
);
Ok(elements.into_py(py))
*/
let elements = env.new_object("java/util/ArrayList", "()Ljava/util/ArrayList;", &[]).unwrap();
let list = env.get_list(&elements).unwrap();
for value in bulk {
let java_value = redis_value_to_java(env, value);
list.add(env, &java_value).unwrap();
}
elements
}
}
}
Expand All @@ -43,12 +41,12 @@ pub extern "system" fn Java_javababushka_client_RedisClient_valueFromPointer<'lo
pointer: jlong
) -> JObject<'local> {
let value = unsafe { Box::from_raw(pointer as *mut Value) };
redis_value_to_java(env, *value)
redis_value_to_java(&mut env, *value)
}

#[no_mangle]
pub extern "system" fn Java_javababushka_client_RedisClient_startSocketListenerExternal<'local>(
mut env: JNIEnv<'local>,
env: JNIEnv<'local>,
_class: JClass<'local>,
callback: JObject<'local>
) {
Expand Down

0 comments on commit 478c107

Please sign in to comment.