MCPcopy Create free account
hub / github.com/deviceplug/btleplug / byte_array_to_vec

Function byte_array_to_vec

src/droidplug/jni_utils/arrays.rs:17–26  ·  view source on GitHub ↗

Get a [`Vec`] of bytes from the given Java byte array.

(env: &'a JNIEnv<'a>, obj: jbyteArray)

Source from the content-addressed store, hash-verified

15
16/// Get a [`Vec`] of bytes from the given Java byte array.
17pub fn byte_array_to_vec<'a>(env: &'a JNIEnv<'a>, obj: jbyteArray) -> Result<Vec<u8>> {
18 let size = env.get_array_length(obj)? as usize;
19 let mut result = Vec::with_capacity(size);
20 unsafe {
21 let result_slice = slice::from_raw_parts_mut(result.as_mut_ptr() as *mut jbyte, size);
22 env.get_byte_array_region(obj, 0, result_slice)?;
23 result.set_len(size);
24 }
25 Ok(result)
26}
27
28#[cfg(test)]
29mod test {

Callers 5

readMethod · 0.85
read_descriptorMethod · 0.85
test_byte_array_to_vecFunction · 0.85
get_valueMethod · 0.85
try_fromMethod · 0.85

Calls

no outgoing calls

Tested by 1

test_byte_array_to_vecFunction · 0.68