prebindgen_jni_runtime/
byte_array_helpers.rs1use jni::{
4 objects::{JByteArray, JObject},
5 JNIEnv,
6};
7
8pub fn decode_byte_array(env: &mut JNIEnv, payload: &JByteArray) -> Result<Vec<u8>, String> {
10 env.convert_byte_array(payload)
11 .map_err(|err| format!("Error while decoding JByteArray: {}", err))
12}
13
14pub fn encode_byte_array<'local>(
16 env: &mut JNIEnv<'local>,
17 bytes: &[u8],
18) -> Result<JByteArray<'local>, String> {
19 env.byte_array_from_slice(bytes)
20 .map_err(|err| format!("Error while encoding JByteArray: {}", err))
21}
22
23pub fn null_byte_array() -> JByteArray<'static> {
25 JByteArray::from(JObject::null())
26}