-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy paths001_bytes.rs
61 lines (56 loc) · 2.05 KB
/
s001_bytes.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
use jni::objects::JClass;
use jni::sys::{jbyteArray, jdouble, jfloat, jint, jlong};
use jni::JNIEnv;
// This keeps Rust from "mangling" the name and making it unique for this
// crate.
#[no_mangle]
pub extern "system" fn Java_sample_s001_Bytes_int2bytes<'local>(
env: JNIEnv<'local>,
// This is the class that owns our static method. It's not going to be used,
// but still must be present to match the expected signature of a static
// native method.
_class: JClass<'local>,
input: jint,
) -> jbyteArray {
let data = input.to_be_bytes();
return conv2bytes(env, data.as_slice(), data.len());
}
#[no_mangle]
pub extern "system" fn Java_sample_s001_Bytes_long2bytes<'local>(
env: JNIEnv<'local>,
// This is the class that owns our static method. It's not going to be used,
// but still must be present to match the expected signature of a static
// native method.
_class: JClass<'local>,
input: jlong,
) -> jbyteArray {
let data = input.to_be_bytes();
return conv2bytes(env, data.as_slice(), data.len());
}
#[no_mangle]
pub extern "system" fn Java_sample_s001_Bytes_float2bytes<'local>(
env: JNIEnv<'local>,
// This is the class that owns our static method. It's not going to be used,
// but still must be present to match the expected signature of a static
// native method.
_class: JClass<'local>,
input: jfloat,
) -> jbyteArray {
let data = input.to_be_bytes();
return conv2bytes(env, data.as_slice(), data.len());
}
#[no_mangle]
pub extern "system" fn Java_sample_s001_Bytes_double2bytes<'local>(
env: JNIEnv<'local>,
// This is the class that owns our static method. It's not going to be used,
// but still must be present to match the expected signature of a static
// native method.
_class: JClass<'local>,
input: jdouble,
) -> jbyteArray {
let data = input.to_be_bytes();
return conv2bytes(env, data.as_slice(), data.len());
}
fn conv2bytes(env: JNIEnv, data: &[u8], _len: usize) -> jbyteArray {
return env.byte_array_from_slice(data).unwrap().into_raw();
}