@@ -7,30 +7,6 @@ use zenoh_flat::jni_type_binding::{JniTypeBinding, ReturnEncode};
77
88const OWNED_OBJECT : & str = "crate::owned_object::OwnedObject" ;
99
10- fn enum_param ( name : & str , decoder : & str ) -> TypeBinding {
11- TypeBinding :: param ( name, "Int" , "jni::sys::jint" , InlineFn :: pure ( decoder) )
12- . enum_field_decoder ( decoder)
13- }
14-
15- fn jobject_param ( name : & str , decoder : & str , kotlin : & str ) -> TypeBinding {
16- TypeBinding :: param (
17- name,
18- kotlin,
19- "jni::objects::JObject" ,
20- InlineFn :: env_ref_mut ( decoder) ,
21- )
22- }
23-
24- fn wrapped_return ( rust_type : & str , kotlin : & str , jni_type : & str , wrapper : & str , default : & str ) -> TypeBinding {
25- TypeBinding :: returns (
26- rust_type,
27- kotlin,
28- jni_type,
29- ReturnEncode :: wrapper ( wrapper) ,
30- default,
31- )
32- }
33-
3410/// Type vocabulary shared across every JNI surface generated in this crate.
3511/// Defined once, threaded into the struct-phase converter, then forwarded —
3612/// together with the auto-registered struct bindings — into the methods phase.
@@ -50,33 +26,67 @@ fn shared_bindings() -> JniTypeBinding {
5026 InlineFn :: env_ref ( "crate::utils::decode_byte_array" ) ,
5127 ) )
5228 // Callbacks.
53- . type_binding ( jobject_param (
29+ . type_binding ( TypeBinding :: param (
5430 "impl Fn(Sample) + Send + Sync + 'static" ,
55- "crate::sample_callback::process_kotlin_sample_callback" ,
5631 "io.zenoh.jni.callbacks.JNISubscriberCallback" ,
32+ "jni::objects::JObject" ,
33+ InlineFn :: env_ref_mut ( "crate::sample_callback::process_kotlin_sample_callback" ) ,
5734 ) )
58- . type_binding ( jobject_param (
35+ . type_binding ( TypeBinding :: param (
5936 "impl Fn(Query) + Send + Sync + 'static" ,
60- "crate::sample_callback::process_kotlin_query_callback" ,
6137 "io.zenoh.jni.callbacks.JNIQueryableCallback" ,
38+ "jni::objects::JObject" ,
39+ InlineFn :: env_ref_mut ( "crate::sample_callback::process_kotlin_query_callback" ) ,
6240 ) )
63- . type_binding ( jobject_param (
41+ . type_binding ( TypeBinding :: param (
6442 "impl Fn(Reply) + Send + Sync + 'static" ,
65- "crate::sample_callback::process_kotlin_reply_callback" ,
6643 "io.zenoh.jni.callbacks.JNIGetCallback" ,
44+ "jni::objects::JObject" ,
45+ InlineFn :: env_ref_mut ( "crate::sample_callback::process_kotlin_reply_callback" ) ,
6746 ) )
68- . type_binding ( jobject_param (
47+ . type_binding ( TypeBinding :: param (
6948 "impl Fn() + Send + Sync + 'static" ,
70- "crate::sample_callback::process_kotlin_on_close_callback" ,
7149 "io.zenoh.jni.callbacks.JNIOnCloseCallback" ,
50+ "jni::objects::JObject" ,
51+ InlineFn :: env_ref_mut ( "crate::sample_callback::process_kotlin_on_close_callback" ) ,
7252 ) )
7353 // Java-enum-shaped types.
74- . type_binding ( enum_param ( "CongestionControl" , "crate::utils::decode_congestion_control" ) )
75- . type_binding ( enum_param ( "Priority" , "crate::utils::decode_priority" ) )
76- . type_binding ( enum_param ( "Reliability" , "crate::utils::decode_reliability" ) )
77- . type_binding ( enum_param ( "QueryTarget" , "crate::utils::decode_query_target" ) )
78- . type_binding ( enum_param ( "ConsolidationMode" , "crate::utils::decode_consolidation" ) )
79- . type_binding ( enum_param ( "ReplyKeyExpr" , "crate::utils::decode_reply_key_expr" ) )
54+ . type_binding ( TypeBinding :: param (
55+ "CongestionControl" ,
56+ "Int" ,
57+ "jni::sys::jint" ,
58+ InlineFn :: pure ( "crate::utils::decode_congestion_control" ) ,
59+ ) . enum_field_decoder ( "crate::utils::decode_congestion_control" ) )
60+ . type_binding ( TypeBinding :: param (
61+ "Priority" ,
62+ "Int" ,
63+ "jni::sys::jint" ,
64+ InlineFn :: pure ( "crate::utils::decode_priority" ) ,
65+ ) . enum_field_decoder ( "crate::utils::decode_priority" ) )
66+ . type_binding ( TypeBinding :: param (
67+ "Reliability" ,
68+ "Int" ,
69+ "jni::sys::jint" ,
70+ InlineFn :: pure ( "crate::utils::decode_reliability" ) ,
71+ ) . enum_field_decoder ( "crate::utils::decode_reliability" ) )
72+ . type_binding ( TypeBinding :: param (
73+ "QueryTarget" ,
74+ "Int" ,
75+ "jni::sys::jint" ,
76+ InlineFn :: pure ( "crate::utils::decode_query_target" ) ,
77+ ) . enum_field_decoder ( "crate::utils::decode_query_target" ) )
78+ . type_binding ( TypeBinding :: param (
79+ "ConsolidationMode" ,
80+ "Int" ,
81+ "jni::sys::jint" ,
82+ InlineFn :: pure ( "crate::utils::decode_consolidation" ) ,
83+ ) . enum_field_decoder ( "crate::utils::decode_consolidation" ) )
84+ . type_binding ( TypeBinding :: param (
85+ "ReplyKeyExpr" ,
86+ "Int" ,
87+ "jni::sys::jint" ,
88+ InlineFn :: pure ( "crate::utils::decode_reply_key_expr" ) ,
89+ ) . enum_field_decoder ( "crate::utils::decode_reply_key_expr" ) )
8090 // KeyExpr by-value: JNI side passes `Arc::into_raw(Arc::new(KeyExpr))`
8191 // as a raw pointer; the wrapper reconstructs the Arc, clones the inner
8292 // KeyExpr, and drops the Arc at end of scope. The full path is required
@@ -88,29 +98,30 @@ fn shared_bindings() -> JniTypeBinding {
8898 InlineFn :: new ( |input| quote ! { ( * std:: sync:: Arc :: from_raw( #input) ) . clone( ) } ) ,
8999 ) )
90100 // Encoding via JObject + custom decoder.
91- . type_binding ( jobject_param (
101+ . type_binding ( TypeBinding :: param (
92102 "Encoding" ,
93- "crate::utils::decode_jni_encoding" ,
94103 "io.zenoh.jni.JNIEncoding" ,
104+ "jni::objects::JObject" ,
105+ InlineFn :: env_ref_mut ( "crate::utils::decode_jni_encoding" ) ,
95106 ) )
96107 // Borrows: opaque Arc handles received as `*const T` and re-borrowed
97108 // via OwnedObject::from_raw. The `&` prefix on the row's key tells
98109 // the converter to pass `&name` to the wrapped fn.
99110 . type_binding ( TypeBinding :: opaque_borrow ( "Session" , OWNED_OBJECT ) )
100111 . type_binding ( TypeBinding :: opaque_borrow ( "Config" , OWNED_OBJECT ) )
101112 // Returns: ZenohId / Vec<ZenohId> via custom encoders.
102- . type_binding ( wrapped_return (
113+ . type_binding ( TypeBinding :: returns (
103114 "ZResult<ZenohId>" ,
104115 "ByteArray" ,
105116 "jni::sys::jbyteArray" ,
106- "crate::zenoh_id::zenoh_id_to_byte_array" ,
117+ ReturnEncode :: wrapper ( "crate::zenoh_id::zenoh_id_to_byte_array" ) ,
107118 "jni::objects::JByteArray::default().as_raw()" ,
108119 ) )
109- . type_binding ( wrapped_return (
120+ . type_binding ( TypeBinding :: returns (
110121 "ZResult<Vec<ZenohId>>" ,
111122 "List<ByteArray>" ,
112123 "jni::sys::jobject" ,
113- "crate::zenoh_id::zenoh_ids_to_java_list" ,
124+ ReturnEncode :: wrapper ( "crate::zenoh_id::zenoh_ids_to_java_list" ) ,
114125 "jni::objects::JObject::default().as_raw()" ,
115126 ) )
116127 // Returns: opaque Arc handles. Each emits `*const T` and
0 commit comments