From 4085e8b32a13b5e0a8c741d82c8d59335bcf3d50 Mon Sep 17 00:00:00 2001 From: "ChenYing Kuo (CY)" Date: Tue, 3 Dec 2024 20:58:41 +0800 Subject: [PATCH] Bump up-rust to 0.3.0 (#93) * Bump up-rust to 0.3.0 Signed-off-by: ChenYing Kuo * Check entity type if only instance is wildcard. Signed-off-by: ChenYing Kuo * Fix clippy. Signed-off-by: ChenYing Kuo --------- Signed-off-by: ChenYing Kuo --- Cargo.lock | 4 ++-- Cargo.toml | 2 +- src/lib.rs | 24 +++++++++++++++++++++++- 3 files changed, 26 insertions(+), 4 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 79633b2..990865a 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2584,9 +2584,9 @@ dependencies = [ [[package]] name = "up-rust" -version = "0.2.0" +version = "0.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "af7f283ab2b74869f69bcd5a87950b87db5110e46764af2ddae3248109f0e374" +checksum = "30118ab07c7ca420e2196bbc0f6f380b3100928d03ec1cd960f9220472f48f1a" dependencies = [ "async-trait", "bytes", diff --git a/Cargo.toml b/Cargo.toml index d06eb34..6ab0480 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -40,7 +40,7 @@ serde_json = "1.0.128" tokio = { version = "1.35.1", default-features = false } tracing = "0.1.40" tracing-subscriber = "0.3.18" -up-rust = "0.2.0" +up-rust = "0.3.0" zenoh = { version = "1.0.0" } [dev-dependencies] diff --git a/src/lib.rs b/src/lib.rs index 761a94e..c9fc71f 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -28,6 +28,8 @@ pub use zenoh::config as zenoh_config; use zenoh::internal::runtime::Runtime as ZRuntime; use zenoh::{bytes::ZBytes, pubsub::Subscriber, qos::Priority, Session}; +const WILDCARD_ENTITY_TYPE: u32 = 0x0000_FFFF; + const UATTRIBUTE_VERSION: u8 = 1; const THREAD_NUM: usize = 10; @@ -164,8 +166,12 @@ impl UPTransportZenoh { uri.authority_name.clone() }; // ue_id - let ue_id = if uri.has_wildcard_entity_id() { + let ue_id = if uri.has_wildcard_entity_type() { + // If entity type is wildcard, the whole entity should be wilrdcard "*".to_string() + } else if uri.has_wildcard_entity_instance() { + // If entity instance is wildcard, we still need to check the entity type + format!("$*{:04X}", uri.ue_id & WILDCARD_ENTITY_TYPE) } else { format!("{:X}", uri.ue_id) }; @@ -266,6 +272,22 @@ mod tests { assert_eq!(up_transport_zenoh.is_ok(), expected_result); } + #[test_case("//1.2.3.4/1234/2/8001", "1.2.3.4/1234/2/8001"; "Standard")] + #[test_case("//1.2.3.4/12345678/2/8001", "1.2.3.4/12345678/2/8001"; "Standard with entity instance")] + #[test_case("//1.2.3.4/FFFF5678/2/8001", "1.2.3.4/$*5678/2/8001"; "Standard with wildcard entity instance")] + #[test_case("//*/FFFF/FF/FFFF", "*/*/*/*"; "All wildcard")] + #[test_case("//*/1234FFFF/FF/FFFF", "*/*/*/*"; "All wildcard but ignore entity instance")] + #[tokio::test(flavor = "multi_thread")] + async fn uri_to_zenoh_key(src_uri: &str, zenoh_key: &str) { + let up_transport_zenoh = + UPTransportZenoh::new(zenoh_config::Config::default(), "//uuri_dont_care/1234/5/0") + .await + .unwrap(); + let src = UUri::from_str(src_uri).unwrap(); + let zenoh_key_string = up_transport_zenoh.uri_to_zenoh_key(&src); + assert_eq!(zenoh_key_string, zenoh_key); + } + // Mapping with the examples in Zenoh spec #[test_case("/10AB/3/80CD", None, "up/192.168.1.100/10AB/3/80CD/{}/{}/{}/{}"; "Send Publish")] #[test_case("//192.168.1.100/10AB/3/80CD", None, "up/192.168.1.100/10AB/3/80CD/{}/{}/{}/{}"; "Subscribe messages")]