modelassetlib_native/util/
jni.rs1extern crate jni;
2
3use jni::JNIEnv;
4use jni::sys::{jboolean, jbyteArray};
5use anyhow::{Context, Result};
6
7pub fn bool_to_jboolean(val: bool) -> jboolean {
8 if val { 1 } else { 0 }
9}
10
11pub fn jboolean_to_bool(val: jboolean) -> bool {
12 if val == 0 { false } else { true }
13}
14
15pub fn throw_runtime_exception(env: &mut JNIEnv, message: &String) -> Result<()> {
16 env.throw_new("top/srcres/mods/modelassetlib/NativeRuntimeException", message).with_context(
17 || format!("Failed to throw native runtime exception with message: {}", message))
18}
19
20pub fn clear_exception_if_occurred(env: &mut JNIEnv) {
21 if let Ok(_) = env.exception_occurred() {
22 env.exception_clear().unwrap();
23 }
24}
25
26pub fn new_empty_byte_array(env: &mut JNIEnv) -> jbyteArray {
27 env.new_byte_array(0).unwrap().as_raw()
28}