Skip to content

Commit

Permalink
feat(ZenohID): using ZenohID.to_le_bytes() to get the zenoh id as a s…
Browse files Browse the repository at this point in the history
…lice + cargo update and fix incompatibilities.
  • Loading branch information
DariusIMP committed Sep 11, 2024
1 parent b1da608 commit 89f7449
Show file tree
Hide file tree
Showing 4 changed files with 4 additions and 13 deletions.
1 change: 0 additions & 1 deletion zenoh-jni/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ json5 = "0.4.1"
serde_yaml = "0.9.19"
zenoh = { version = "1.0.0-dev", git = "https://github.com/eclipse-zenoh/zenoh.git", branch = "main", default-features = false }
zenoh-ext = { version = "1.0.0-dev", git = "https://github.com/eclipse-zenoh/zenoh.git", branch = "main", default-features = false }
zenoh-protocol = { version = "1.0.0-dev", git = "https://github.com/eclipse-zenoh/zenoh.git", branch = "main", default-features = false }
tracing = "0.1"
[lib]
name = "zenoh_jni"
Expand Down
4 changes: 1 addition & 3 deletions zenoh-jni/src/scouting.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ use jni::{
};
use zenoh::{config::WhatAmIMatcher, prelude::Wait};
use zenoh::{scouting::Scout, Config};
use zenoh_protocol::core::ZenohIdProto;

use crate::{errors::Result, throw_exception};
use crate::{
Expand Down Expand Up @@ -66,9 +65,8 @@ pub unsafe extern "C" fn Java_io_zenoh_jni_JNIScout_00024Companion_scoutViaJNI(
let _ = || -> jni::errors::Result<()> {
let mut env = java_vm.attach_current_thread_as_daemon()?;
let whatami = hello.whatami() as jint;
let zenoh_id_proto: ZenohIdProto = hello.zid().into();
let zenoh_id = env
.byte_array_from_slice(&zenoh_id_proto.to_le_bytes())
.byte_array_from_slice(&hello.zid().to_le_bytes())
.map(|it| env.auto_local(it))?;
let locators = env
.new_object("java/util/ArrayList", "()V", &[])
Expand Down
7 changes: 2 additions & 5 deletions zenoh-jni/src/session.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ use zenoh::pubsub::{Publisher, Subscriber};
use zenoh::query::{Query, Queryable, ReplyError, Selector};
use zenoh::sample::Sample;
use zenoh::session::{Session, SessionDeclarations};
use zenoh_protocol::core::ZenohIdProto;

/// Open a Zenoh session via JNI.
///
Expand Down Expand Up @@ -918,8 +917,7 @@ fn on_reply_success(
.map_or_else(
|| Ok(JByteArray::default()),
|replier_id| {
let zenoh_id_proto: ZenohIdProto = replier_id.into();
env.byte_array_from_slice(&zenoh_id_proto.to_le_bytes())
env.byte_array_from_slice(&replier_id.to_le_bytes())
.map_err(|err| jni_error!(err))
},
)
Expand Down Expand Up @@ -1005,8 +1003,7 @@ fn on_reply_error(
.map_or_else(
|| Ok(JByteArray::default()),
|replier_id| {
let zenoh_id_proto: ZenohIdProto = replier_id.into();
env.byte_array_from_slice(&zenoh_id_proto.to_le_bytes())
env.byte_array_from_slice(&replier_id.to_le_bytes())
.map_err(|err| jni_error!(err))
},
)
Expand Down
5 changes: 1 addition & 4 deletions zenoh-jni/src/zenoh_id.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ use jni::{
JNIEnv,
};
use zenoh::config::ZenohId;
use zenoh_protocol::core::ZenohIdProto;

/// Returns the string representation of a ZenohID.
#[no_mangle]
Expand All @@ -31,9 +30,7 @@ pub extern "C" fn Java_io_zenoh_jni_JNIZenohID_toStringViaJNI(
) -> jstring {
|| -> Result<JString> {
let bytes = decode_byte_array(&env, zenoh_id)?;
let zenohIdProto =
ZenohIdProto::try_from(bytes.as_slice()).map_err(|err| session_error!(err))?;
let zenohid = ZenohId::from(zenohIdProto);
let zenohid = ZenohId::try_from(bytes.as_slice()).map_err(|err| session_error!(err))?;
env.new_string(zenohid.to_string())
.map_err(|err| jni_error!(err))
}()
Expand Down

0 comments on commit 89f7449

Please sign in to comment.