Skip to content

Commit f3e855f

Browse files
committed
recursive expamd demo
1 parent 5f5fb71 commit f3e855f

3 files changed

Lines changed: 34 additions & 0 deletions

File tree

zenoh-flat-jni/build.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,12 @@ fn main() {
203203
.package("sample")
204204
.enum_class(pq!(SampleKind))
205205
.ptr_class(pq!(ZSample))
206+
// Canonical INPUT: a ZSample is built from (key_expr, payload, encoding)
207+
// via z_sample_new. Because those params are themselves ptr_class types
208+
// with their own canonical inputs, a `ZSample` param expands RECURSIVELY:
209+
// key_expr → (String|handle selector), payload → ByteArray, encoding →
210+
// String — all flattened into the consuming fn's signature.
211+
.ptr_class_input(pq!(z_sample_new))
206212
// Canonical output: the full sample decomposed in ONE crossing. Each
207213
// record is unwrapped per its return type's canonical output —
208214
// z_sample_key_expr → (ZKeyExpr handle, String); payload/attachment →
@@ -248,6 +254,9 @@ fn main() {
248254
.fun(pq!(z_query_reply_success))
249255
.fun(pq!(z_query_reply_error))
250256
.fun(pq!(z_query_reply_delete))
257+
// Recursive-input demo: `sample: ZSample` expands via z_sample_new into
258+
// (key_expr String|handle, payload ByteArray, encoding String).
259+
.fun(pq!(z_query_reply_sample))
251260
.fun_accessor(pq!(z_query_keyexpr))
252261
.fun_accessor(pq!(z_query_parameters))
253262
.fun_accessor(pq!(z_query_payload))

zenoh-flat-jni/generated-kotlin/io/zenoh/jni/JNINative.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,7 @@ internal object JNINative {
126126
external fun zQueryPayload(q: Long, errorSink: Any): Long
127127
external fun zQueryReplyDelete(query: Long, keyExprSel: Int, keyExpr0: String?, keyExpr1: Long, timestampNtp64: Long?, attachment: ByteArray?, express: Boolean?, errorSink: Any)
128128
external fun zQueryReplyError(query: Long, payload: ByteArray, encoding: String?, errorSink: Any)
129+
external fun zQueryReplySample(query: Long, sampleKeyExprSel: Int, sampleKeyExpr0: String?, sampleKeyExpr1: Long, samplePayload: ByteArray, sampleEncoding: String, errorSink: Any)
129130
external fun zQueryReplySuccess(query: Long, keyExprSel: Int, keyExpr0: String?, keyExpr1: Long, payload: ByteArray, encoding: String?, timestampNtp64: Long?, attachment: ByteArray?, express: Boolean?, errorSink: Any)
130131
external fun zReplyErrorEncoding(r: Long, errorSink: Any): Long
131132
external fun zReplyErrorPayload(r: Long, errorSink: Any): Long

zenoh-flat-jni/generated-kotlin/io/zenoh/jni/query/JNIquery.kt

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,30 @@ public fun zQueryReplyDelete(query: ZQuery, keyExprSel: Int, keyExpr0: String?,
8282
if (__cap_failed) return onError(__cap_je, (__cap_ze0 ?: ""))
8383
}
8484

85+
public fun zQueryReplySample(query: ZQuery, sampleKeyExprSel: Int, sampleKeyExpr0: String?, sampleKeyExpr1: ZKeyExpr?, samplePayload: ByteArray, sampleEncoding: String, onError: (String?, String) -> Unit = { __de_je, __de_z0 -> throw ZException(__de_je ?: __de_z0) }) {
86+
if (query.ptr == 0L) { onError("Operation on a closed native handle.", ""); return }
87+
if (sampleKeyExpr1 != null && sampleKeyExpr1.ptr == 0L) { onError("Operation on a closed native handle.", ""); return }
88+
var __cap_failed = false
89+
var __cap_je: String? = null
90+
var __cap_ze0: String? = null
91+
val __cap = { __je: String?, __ze0: String? -> __cap_failed = true; __cap_je = __je; __cap_ze0 = __ze0 }
92+
run {
93+
val __locks = ArrayList<NativeHandle>()
94+
__locks.add(query)
95+
sampleKeyExpr1?.let { __locks.add(it) }
96+
withSortedHandleLocks(__locks) {
97+
val query_ptr = query.ptr
98+
val sampleKeyExpr1_ptr = sampleKeyExpr1?.ptr ?: 0L
99+
try {
100+
JNINative.zQueryReplySample(query_ptr, sampleKeyExprSel, sampleKeyExpr0, sampleKeyExpr1_ptr, samplePayload, sampleEncoding, __cap)
101+
} finally {
102+
sampleKeyExpr1?.let { it.ptr = 0L }
103+
}
104+
}
105+
}
106+
if (__cap_failed) return onError(__cap_je, (__cap_ze0 ?: ""))
107+
}
108+
85109
public fun zQueryKeyexpr(q: ZQuery, onError: (String?) -> ZKeyExpr = { __de_je -> throw ZException(__de_je) }): ZKeyExpr {
86110
if (q.ptr == 0L) return onError("Operation on a closed native handle.")
87111
var __cap_failed = false

0 commit comments

Comments
 (0)