Skip to content

Commit 9438d2b

Browse files
committed
vec unfold
1 parent f885561 commit 9438d2b

4 files changed

Lines changed: 27 additions & 8 deletions

File tree

zenoh-flat-jni/build.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -304,8 +304,14 @@ fn main() {
304304
.expand(pq!(encoding)) // Option<&ZEncoding> ← String?
305305
.expand(pq!(attachment)) // Option<ZZBytes> ← ByteArray?
306306
.package_fun(pq!(z_session_zid))
307+
// Output expansion (M4, Iterable): Vec<ZZenohId> → fold, each ZZenohId
308+
// delivered WHOLE (its value_blob projection); caller owns the result
309+
// collection. No combined accessor — the element crosses as the typed
310+
// `ZZenohId` value class, matching the prior `List<ZZenohId>`.
307311
.package_fun(pq!(z_session_peers_zid))
312+
.expand_output() // Vec<ZZenohId> → fun <A>(acc, fold: (A, ZZenohId) -> A): A
308313
.package_fun(pq!(z_session_routers_zid))
314+
.expand_output()
309315
.package_fun(pq!(z_liveliness_declare_token))
310316
.expand(pq!(key_expr)) // ZKeyExpr (by-value) ← String | handle
311317
.package_fun(pq!(z_liveliness_get))

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -147,9 +147,9 @@ internal object JNINative {
147147
external fun zSessionDeclareSubscriber(session: Long, keyExprSel: Int, keyExpr0: String?, keyExpr1: Long, callback: ZSampleCallback, onClose: Callback, errorSink: Any): Long
148148
external fun zSessionDelete(session: Long, keyExprSel: Int, keyExpr0: String?, keyExpr1: Long, congestionControl: Int?, priority: Int?, express: Boolean?, attachment: ByteArray?, reliability: Int?, errorSink: Any)
149149
external fun zSessionGet(session: Long, keyExprSel: Int, keyExpr0: String?, keyExpr1: Long, parameters: String?, timeoutMs: Long?, target: Int?, consolidation: Int?, acceptReplies: Int?, congestionControl: Int?, priority: Int?, express: Boolean?, payload: ByteArray?, encoding: String?, attachment: ByteArray?, callback: ZReplyCallback, onClose: Callback, errorSink: Any)
150-
external fun zSessionPeersZid(session: Long, errorSink: Any): List<ByteArray>
150+
external fun zSessionPeersZid(session: Long, acc: Any?, fold: Any, errorSink: Any): Any?
151151
external fun zSessionPut(session: Long, keyExprSel: Int, keyExpr0: String?, keyExpr1: Long, payload: ByteArray, encoding: String?, congestionControl: Int?, priority: Int?, express: Boolean?, attachment: ByteArray?, reliability: Int?, errorSink: Any)
152-
external fun zSessionRoutersZid(session: Long, errorSink: Any): List<ByteArray>
152+
external fun zSessionRoutersZid(session: Long, acc: Any?, fold: Any, errorSink: Any): Any?
153153
external fun zSessionUndeclareKeyexpr(session: Long, keyExpr: Long, errorSink: Any)
154154
external fun zSessionZid(session: Long, errorSink: Any): ByteArray
155155
external fun zTimestampId(t: Long, errorSink: Any): ByteArray

zenoh-flat-jni/generated-kotlin/io/zenoh/jni/session/JNIsession.kt

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -230,25 +230,27 @@ public fun zSessionZid(session: ZSession): ZZenohId {
230230
return __ret
231231
}
232232

233-
public fun zSessionPeersZid(session: ZSession): List<ZZenohId> {
233+
@Suppress("UNCHECKED_CAST")
234+
public fun <A> zSessionPeersZid(session: ZSession, acc: A, fold: (A, ZZenohId) -> A): A {
234235
val __err = ErrorHolder()
235236
val __sink = ErrorSink { __m -> __err.message = __m }
236237
val __ret = withSortedHandleLocks(session) {
237238
val session_ptr = session.ptr
238239
if (session_ptr == 0L) throw ZException("Operation on a closed native handle.")
239-
JNINative.zSessionPeersZid(session_ptr, __sink).map { ZZenohId(it) }
240+
(JNINative.zSessionPeersZid(session_ptr, acc, { __a: A, __raw: ByteArray -> fold(__a, ZZenohId(__raw)) }, __sink) as A)
240241
}
241242
__err.message?.let { throw ZException(it) }
242243
return __ret
243244
}
244245

245-
public fun zSessionRoutersZid(session: ZSession): List<ZZenohId> {
246+
@Suppress("UNCHECKED_CAST")
247+
public fun <A> zSessionRoutersZid(session: ZSession, acc: A, fold: (A, ZZenohId) -> A): A {
246248
val __err = ErrorHolder()
247249
val __sink = ErrorSink { __m -> __err.message = __m }
248250
val __ret = withSortedHandleLocks(session) {
249251
val session_ptr = session.ptr
250252
if (session_ptr == 0L) throw ZException("Operation on a closed native handle.")
251-
JNINative.zSessionRoutersZid(session_ptr, __sink).map { ZZenohId(it) }
253+
(JNINative.zSessionRoutersZid(session_ptr, acc, { __a: A, __raw: ByteArray -> fold(__a, ZZenohId(__raw)) }, __sink) as A)
252254
}
253255
__err.message?.let { throw ZException(it) }
254256
return __ret

zenoh-java/src/commonMain/kotlin/io/zenoh/Session.kt

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -823,13 +823,24 @@ class Session private constructor(private val config: Config) : AutoCloseable {
823823
@Throws(ZError::class)
824824
internal fun getPeersId(): List<ZenohId> {
825825
val zSession = zSession ?: throw sessionClosedException
826-
return wrapJNIExceptionAsZError { io.zenoh.jni.session.zSessionPeersZid(zSession).map { ZenohId(it) } }
826+
// Output expansion (M4): the native side folds each ZZenohId into this
827+
// accumulator in one pass — the caller owns the list (no intermediate
828+
// List<ZZenohId>). `zid` is the typed ZZenohId value class.
829+
return wrapJNIExceptionAsZError {
830+
io.zenoh.jni.session.zSessionPeersZid(zSession, ArrayList<ZenohId>()) { list, zid ->
831+
list.add(ZenohId(zid)); list
832+
}
833+
}
827834
}
828835

829836
@Throws(ZError::class)
830837
internal fun getRoutersId(): List<ZenohId> {
831838
val zSession = zSession ?: throw sessionClosedException
832-
return wrapJNIExceptionAsZError { io.zenoh.jni.session.zSessionRoutersZid(zSession).map { ZenohId(it) } }
839+
return wrapJNIExceptionAsZError {
840+
io.zenoh.jni.session.zSessionRoutersZid(zSession, ArrayList<ZenohId>()) { list, zid ->
841+
list.add(ZenohId(zid)); list
842+
}
843+
}
833844
}
834845

835846
/** Launches the session, returning the [Session] on success. */

0 commit comments

Comments
 (0)