mirror of
https://github.com/hexedtech/codemp.git
synced 2025-03-21 18:51:32 +01:00
35 lines
845 B
Rust
35 lines
845 B
Rust
|
use jni::{objects::{JClass, JString}, sys::{jboolean, jlong}, JNIEnv};
|
||
|
|
||
|
use super::JExceptable;
|
||
|
|
||
|
/// Calculate the XXH3 hash for a given String.
|
||
|
#[no_mangle]
|
||
|
pub extern "system" fn Java_mp_code_Extensions_hash<'local>(
|
||
|
mut env: JNIEnv,
|
||
|
_class: JClass<'local>,
|
||
|
content: JString<'local>,
|
||
|
) -> jlong {
|
||
|
let content: String = env.get_string(&content)
|
||
|
.map(|s| s.into())
|
||
|
.jexcept(&mut env);
|
||
|
let hash = crate::ext::hash(content.as_bytes());
|
||
|
i64::from_ne_bytes(hash.to_ne_bytes())
|
||
|
}
|
||
|
|
||
|
/// Tells the [tokio] runtime how to drive the event loop.
|
||
|
#[no_mangle]
|
||
|
pub extern "system" fn Java_mp_code_Extensions_drive(
|
||
|
_env: JNIEnv,
|
||
|
_class: JClass,
|
||
|
block: jboolean
|
||
|
) {
|
||
|
if block != 0 {
|
||
|
super::tokio().block_on(std::future::pending::<()>());
|
||
|
} else {
|
||
|
std::thread::spawn(|| {
|
||
|
super::tokio().block_on(std::future::pending::<()>());
|
||
|
});
|
||
|
}
|
||
|
}
|
||
|
|