Skip to content

Commit

Permalink
Bump up-rust to 0.3.0 (#93)
Browse files Browse the repository at this point in the history
* Bump up-rust to 0.3.0

Signed-off-by: ChenYing Kuo <[email protected]>

* Check entity type if only instance is wildcard.

Signed-off-by: ChenYing Kuo <[email protected]>

* Fix clippy.

Signed-off-by: ChenYing Kuo <[email protected]>

---------

Signed-off-by: ChenYing Kuo <[email protected]>
  • Loading branch information
evshary authored Dec 3, 2024
1 parent 94e6c53 commit 4085e8b
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 4 deletions.
4 changes: 2 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
24 changes: 23 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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)
};
Expand Down Expand Up @@ -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")]
Expand Down

0 comments on commit 4085e8b

Please sign in to comment.