Skip to content

Commit d380b96

Browse files
committed
valur type handling fix
1 parent fe33837 commit d380b96

8 files changed

Lines changed: 421 additions & 300 deletions

File tree

prebindgen-ext/src/jni/jni_ext.rs

Lines changed: 231 additions & 198 deletions
Large diffs are not rendered by default.

prebindgen-ext/src/jni/jni_kotlin_ext.rs

Lines changed: 155 additions & 64 deletions
Large diffs are not rendered by default.

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

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import io.zenoh.jni.callbacks.ZSampleCallback
1616
import io.zenoh.jni.config.WhatAmI
1717
import io.zenoh.jni.config.ZConfig
1818
import io.zenoh.jni.config.ZZenohId
19+
import io.zenoh.jni.config.ZenohId
1920
import io.zenoh.jni.keyexpr.KeyExpr
2021
import io.zenoh.jni.keyexpr.SetIntersectionLevel
2122
import io.zenoh.jni.keyexpr.ZKeyExpr
@@ -194,14 +195,14 @@ internal object JNINative {
194195
external fun zQueryReplyDelete(query: Long, keyExpr: Any, timestampNtp64: Long?, attachment: Any?, express: Boolean)
195196
external fun zQueryReplyError(query: Long, payload: Any, encoding: Any)
196197
external fun zQueryReplySuccess(query: Long, keyExpr: Any, payload: Any, encoding: Any, timestampNtp64: Long?, attachment: Any?, express: Boolean)
197-
external fun zReplyErrorEncoding(r: Long): Long
198-
external fun zReplyErrorPayload(r: Long): Long
198+
external fun zReplyErrorEncoding(r: Long): Long?
199+
external fun zReplyErrorPayload(r: Long): Long?
199200
external fun zReplyExpand(r: Long): Reply
200201
external fun zReplyIsOk(r: Long): Boolean
201202
external fun zReplyReplierEid(r: Long): Int
202-
external fun zReplyReplierZid(r: Long): Long
203-
external fun zReplySample(r: Long): Long
204-
external fun zSampleAttachment(s: Long): Long
203+
external fun zReplyReplierZid(r: Long): Long?
204+
external fun zReplySample(r: Long): Long?
205+
external fun zSampleAttachment(s: Long): Long?
205206
external fun zSampleCongestionControl(s: Long): Int
206207
external fun zSampleEncoding(s: Long): Long
207208
external fun zSampleExpand(s: Long): Sample
@@ -210,7 +211,7 @@ internal object JNINative {
210211
external fun zSampleKind(s: Long): Int
211212
external fun zSamplePayload(s: Long): Long
212213
external fun zSamplePriority(s: Long): Int
213-
external fun zSampleTimestamp(s: Long): Long
214+
external fun zSampleTimestamp(s: Long): Long?
214215
external fun zScout(whatami: Int, config: Long, callback: ZHelloCallback, onClose: Callback): Long
215216
external fun zSessionDeclareKeyexpr(session: Long, keyExpr: String): Long
216217
external fun zSessionDeclarePublisher(session: Long, keyExpr: Any, congestionControl: Int, priority: Int, express: Boolean, reliability: Int): Long

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ public class ZReply(initialPtr: Long) : AutoCloseable {
3636
synchronized(this) {
3737
val r_ptr = this.ptr
3838
if (r_ptr == 0L) throw JniBindingError("Operation on a closed native handle.")
39-
return ZZenohId(JNINative.zReplyReplierZid(r_ptr))
39+
return JNINative.zReplyReplierZid(r_ptr)?.let { ZZenohId(it) }
4040
}
4141
}
4242

@@ -63,7 +63,7 @@ public class ZReply(initialPtr: Long) : AutoCloseable {
6363
synchronized(this) {
6464
val r_ptr = this.ptr
6565
if (r_ptr == 0L) throw JniBindingError("Operation on a closed native handle.")
66-
return ZSample(JNINative.zReplySample(r_ptr))
66+
return JNINative.zReplySample(r_ptr)?.let { ZSample(it) }
6767
}
6868
}
6969

@@ -72,7 +72,7 @@ public class ZReply(initialPtr: Long) : AutoCloseable {
7272
synchronized(this) {
7373
val r_ptr = this.ptr
7474
if (r_ptr == 0L) throw JniBindingError("Operation on a closed native handle.")
75-
return ZZBytes(JNINative.zReplyErrorPayload(r_ptr))
75+
return JNINative.zReplyErrorPayload(r_ptr)?.let { ZZBytes(it) }
7676
}
7777
}
7878

@@ -81,7 +81,7 @@ public class ZReply(initialPtr: Long) : AutoCloseable {
8181
synchronized(this) {
8282
val r_ptr = this.ptr
8383
if (r_ptr == 0L) throw JniBindingError("Operation on a closed native handle.")
84-
return ZEncoding(JNINative.zReplyErrorEncoding(r_ptr))
84+
return JNINative.zReplyErrorEncoding(r_ptr)?.let { ZEncoding(it) }
8585
}
8686
}
8787

zenoh-flat-jni/generated-kotlin/io/zenoh/jni/sample/ZSample.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ public class ZSample(initialPtr: Long) : AutoCloseable {
7474
synchronized(this) {
7575
val s_ptr = this.ptr
7676
if (s_ptr == 0L) throw JniBindingError("Operation on a closed native handle.")
77-
return ZTimestamp(JNINative.zSampleTimestamp(s_ptr))
77+
return JNINative.zSampleTimestamp(s_ptr)?.let { ZTimestamp(it) }
7878
}
7979
}
8080

@@ -110,7 +110,7 @@ public class ZSample(initialPtr: Long) : AutoCloseable {
110110
synchronized(this) {
111111
val s_ptr = this.ptr
112112
if (s_ptr == 0L) throw JniBindingError("Operation on a closed native handle.")
113-
return ZZBytes(JNINative.zSampleAttachment(s_ptr))
113+
return JNINative.zSampleAttachment(s_ptr)?.let { ZZBytes(it) }
114114
}
115115
}
116116

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

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import io.zenoh.jni.callbacks.ZQueryCallback
1414
import io.zenoh.jni.callbacks.ZReplyCallback
1515
import io.zenoh.jni.callbacks.ZSampleCallback
1616
import io.zenoh.jni.config.ZConfig
17+
import io.zenoh.jni.config.ZenohId
1718
import io.zenoh.jni.keyexpr.ZKeyExpr
1819
import io.zenoh.jni.liveliness.ZLivelinessToken
1920
import io.zenoh.jni.pubsub.ZPublisher
@@ -386,29 +387,29 @@ public class ZSession(initialPtr: Long) : AutoCloseable {
386387
}
387388

388389
@Throws(JniBindingError::class)
389-
public fun zSessionZid(): ByteArray {
390+
public fun zSessionZid(): ZenohId {
390391
synchronized(this) {
391392
val session_ptr = this.ptr
392393
if (session_ptr == 0L) throw JniBindingError("Operation on a closed native handle.")
393-
return JNINative.zSessionZid(session_ptr)
394+
return ZenohId(JNINative.zSessionZid(session_ptr))
394395
}
395396
}
396397

397398
@Throws(JniBindingError::class)
398-
public fun zSessionPeersZid(): List<ByteArray> {
399+
public fun zSessionPeersZid(): List<ZenohId> {
399400
synchronized(this) {
400401
val session_ptr = this.ptr
401402
if (session_ptr == 0L) throw JniBindingError("Operation on a closed native handle.")
402-
return JNINative.zSessionPeersZid(session_ptr)
403+
return JNINative.zSessionPeersZid(session_ptr).map { ZenohId(it) }
403404
}
404405
}
405406

406407
@Throws(JniBindingError::class)
407-
public fun zSessionRoutersZid(): List<ByteArray> {
408+
public fun zSessionRoutersZid(): List<ZenohId> {
408409
synchronized(this) {
409410
val session_ptr = this.ptr
410411
if (session_ptr == 0L) throw JniBindingError("Operation on a closed native handle.")
411-
return JNINative.zSessionRoutersZid(session_ptr)
412+
return JNINative.zSessionRoutersZid(session_ptr).map { ZenohId(it) }
412413
}
413414
}
414415

zenoh-flat/src/session/z_session.rs

Lines changed: 12 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use crate::util::OnceDrop;
22
use crate::{
33
into_native, CongestionControl, ConsolidationMode, Encoding, Error, KeyExpr, Priority, Query,
44
QueryTarget, Reliability, Reply, ReplyKeyExpr, Sample, ZBytes, ZConfig, ZEncoding, ZKeyExpr,
5-
ZPublisher, ZQuerier, ZQuery, ZQueryable, ZReply, ZSample, ZSession, ZSubscriber,
5+
ZPublisher, ZQuerier, ZQuery, ZQueryable, ZReply, ZSample, ZSession, ZSubscriber, ZenohId,
66
};
77
use prebindgen_proc_macro::prebindgen;
88
use std::time::Duration;
@@ -300,32 +300,27 @@ pub fn session_get(
300300
)
301301
}
302302

303-
// Zid accessors return raw little-endian id bytes (Kotlin `ByteArray` /
304-
// `List<ByteArray>`); the public layer wraps them into `ZenohId`. Returning the
305-
// `ZenohId` value class directly would be ambiguous in a `Vec` — value classes
306-
// box in generic position but erase to their inner elsewhere — so bytes keep
307-
// the FFI surface unambiguous and match the existing public bridging.
303+
// Zid accessors return the value-class `ZenohId` directly. With the unified
304+
// newtype projection, value classes ride the same fold-and-wrap machinery as
305+
// opaque handles: the generated Kotlin surface is `ZenohId` / `List<ZenohId>`,
306+
// each value erased to its inner `[B` over the wire and wrapped on the Kotlin
307+
// side, with no raw-bytes hop visible in the FFI surface.
308308
#[prebindgen]
309-
pub fn z_session_zid(session: &ZSession) -> Vec<u8> {
310-
session.info().zid().wait().to_le_bytes().to_vec()
309+
pub fn z_session_zid(session: &ZSession) -> ZenohId {
310+
ZenohId::from(session.info().zid().wait())
311311
}
312312

313313
#[prebindgen]
314-
pub fn z_session_peers_zid(session: &ZSession) -> Vec<Vec<u8>> {
315-
session
316-
.info()
317-
.peers_zid()
318-
.wait()
319-
.map(|z| z.to_le_bytes().to_vec())
320-
.collect()
314+
pub fn z_session_peers_zid(session: &ZSession) -> Vec<ZenohId> {
315+
session.info().peers_zid().wait().map(ZenohId::from).collect()
321316
}
322317

323318
#[prebindgen]
324-
pub fn z_session_routers_zid(session: &ZSession) -> Vec<Vec<u8>> {
319+
pub fn z_session_routers_zid(session: &ZSession) -> Vec<ZenohId> {
325320
session
326321
.info()
327322
.routers_zid()
328323
.wait()
329-
.map(|z| z.to_le_bytes().to_vec())
324+
.map(ZenohId::from)
330325
.collect()
331326
}

zenoh-java/src/commonMain/kotlin/io/zenoh/jni/JNISession.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -249,16 +249,16 @@ internal class JNISession(internal val zSession: ZSession) {
249249

250250
@Throws(ZError::class)
251251
fun zid(): ZenohId = wrapJNIExceptionAsZError {
252-
ZenohId(io.zenoh.jni.config.ZenohId(zSession.zSessionZid()))
252+
ZenohId(zSession.zSessionZid())
253253
}
254254

255255
@Throws(ZError::class)
256256
fun peersZid(): List<ZenohId> = wrapJNIExceptionAsZError {
257-
zSession.zSessionPeersZid().map { ZenohId(io.zenoh.jni.config.ZenohId(it)) }
257+
zSession.zSessionPeersZid().map { ZenohId(it) }
258258
}
259259

260260
@Throws(ZError::class)
261261
fun routersZid(): List<ZenohId> = wrapJNIExceptionAsZError {
262-
zSession.zSessionRoutersZid().map { ZenohId(io.zenoh.jni.config.ZenohId(it)) }
262+
zSession.zSessionRoutersZid().map { ZenohId(it) }
263263
}
264264
}

0 commit comments

Comments
 (0)