### Publisher Example Command-Line Arguments Source: https://github.com/eclipse-uprotocol/up-transport-zenoh-rust/blob/main/_autodocs/configuration.md Demonstrates various command-line arguments for configuring the publisher example, including custom config files, session modes, and endpoints. ```bash # Default configuration ./target/debug/examples/publisher # With custom config file ./target/debug/examples/publisher -c config.json5 # As Zenoh client connecting to router ./target/debug/examples/publisher -m client -e tcp/zenoh-router:7447 # With custom endpoints ./target/debug/examples/publisher -l tcp/0.0.0.0:7447 # Disable multicast ./target/debug/examples/publisher --no-multicast-scouting ``` -------------------------------- ### Run Zenoh Transport Examples Source: https://github.com/eclipse-uprotocol/up-transport-zenoh-rust/blob/main/README.md Commands to execute the example applications for publisher, subscriber, notifier, RPC client/server, and L2 RPC client. ```shell ./target/debug/examples/publisher ./target/debug/examples/subscriber ./target/debug/examples/notifier ./target/debug/examples/notification_receiver ./target/debug/examples/rpc_server ./target/debug/examples/rpc_client ./target/debug/examples/l2_rpc_client ``` -------------------------------- ### Example Usage of InitialBuilderState Source: https://github.com/eclipse-uprotocol/up-transport-zenoh-rust/blob/main/_autodocs/types.md Demonstrates how to start building a UPTransportZenoh instance using the initial builder state. ```rust let builder: UPTransportZenohBuilder = UPTransportZenoh::builder("vehicle1")?; ``` -------------------------------- ### JSON5 Configuration File Example Source: https://github.com/eclipse-uprotocol/up-transport-zenoh-rust/blob/main/_autodocs/configuration.md An example of a Zenoh configuration file in JSON5 format, specifying mode, connection, and listen endpoints, as well as multicast scouting. ```json5 { mode: "peer", connect: { endpoints: ["tcp/192.168.1.100:7447"], }, listen: { endpoints: ["tcp/0.0.0.0:7447"], }, scouting: { multicast: { enabled: false, }, }, } ``` -------------------------------- ### Example Usage of ConfigBuilderState Source: https://github.com/eclipse-uprotocol/up-transport-zenoh-rust/blob/main/_autodocs/types.md Shows how to transition to the ConfigBuilderState by providing a Zenoh configuration object and then building the transport. ```rust use up_transport_zenoh::zenoh_config; let builder = UPTransportZenoh::builder("vehicle1")? .with_config(zenoh_config::Config::default()); // builder now has type UPTransportZenohBuilder let transport = builder.build().await?; ``` -------------------------------- ### Example Usage of ConfigPathBuilderState Source: https://github.com/eclipse-uprotocol/up-transport-zenoh-rust/blob/main/_autodocs/types.md Demonstrates transitioning to the ConfigPathBuilderState by specifying a configuration file path and then building the transport. Errors occur if the file is unreadable or invalid. ```rust let builder = UPTransportZenoh::builder("vehicle1")? .with_config_path("config.json5".to_string()); // builder now has type UPTransportZenohBuilder let transport = builder.build().await?; ``` -------------------------------- ### Initialization Loading Configuration from File Source: https://github.com/eclipse-uprotocol/up-transport-zenoh-rust/blob/main/_autodocs/usage-patterns.md Initializes the UPTransportZenoh by loading configuration from a specified file path. The example zenoh.json5 shows peer mode configuration. ```rust use up_transport_zenoh::UPTransportZenoh; #[tokio::main] async fn main() -> Result<(), Box> { let transport = UPTransportZenoh::builder("myapp")? .with_config_path("zenoh.json5".to_string()) .build() .await?; Ok(()) } ``` ```json5 { mode: "peer", connect: { endpoints: ["tcp/192.168.1.100:7447"], }, listen: { endpoints: ["tcp/0.0.0.0:7447"], }, } ``` -------------------------------- ### Minimal Initialization Source: https://github.com/eclipse-uprotocol/up-transport-zenoh-rust/blob/main/_autodocs/usage-patterns.md Initializes the UPTransportZenoh with a default configuration. This is the most basic setup. ```rust use up_transport_zenoh::{zenoh_config, UPTransportZenoh}; #[tokio::main] async fn main() -> Result<(), Box> { let transport = UPTransportZenoh::builder("myapp")? .with_config(zenoh_config::Config::default()) .build() .await?; Ok(()) } ``` -------------------------------- ### Log Initialization Example Source: https://github.com/eclipse-uprotocol/up-transport-zenoh-rust/blob/main/_autodocs/module-overview.md Initializes logging for the transport using the RUST_LOG environment variable. This is a utility function provided by the transport implementation. ```rust UPTransportZenoh::try_init_log_from_env() ``` -------------------------------- ### Initialize Tokio Runtime for Transport Source: https://github.com/eclipse-uprotocol/up-transport-zenoh-rust/blob/main/_autodocs/module-overview.md Shows the basic setup for using the transport within a Tokio asynchronous runtime. The transport expects an existing runtime to be available. ```rust #[tokio::main] async fn main() { let transport = /* ... */; transport.send(message).await?; } ``` -------------------------------- ### Message Construction with UMessageBuilder Source: https://github.com/eclipse-uprotocol/up-transport-zenoh-rust/blob/main/_autodocs/types.md Demonstrates how to construct a uProtocol message using the UMessageBuilder. This example shows creating a publish message with a text payload. ```rust use up_rust::UMessageBuilder; let message = UMessageBuilder::publish(topic_uri) .build_with_payload("data", UPayloadFormat::UPAYLOAD_FORMAT_TEXT)?; ``` -------------------------------- ### Minimal UPTransportZenoh Configuration Source: https://github.com/eclipse-uprotocol/up-transport-zenoh-rust/blob/main/_autodocs/api-reference/uptransport-zenoh-builder.md Builds the transport with default settings, using a minimal configuration. This is suitable for basic setups. ```rust let transport = UPTransportZenoh::builder("myapp")? .with_config(zenoh_config::Config::default()) .build() .await?; ``` -------------------------------- ### Zenoh Transport Authority Name Validation Examples Source: https://github.com/eclipse-uprotocol/up-transport-zenoh-rust/blob/main/_autodocs/configuration.md Illustrates successful and failing attempts to set the authority name for the Zenoh transport builder, highlighting validation constraints. ```rust // All fail UPTransportZenoh::builder("")?; // empty UPTransportZenoh::builder("*")?; // wildcard UPTransportZenoh::builder("bad name!")?; // invalid chars // All succeed UPTransportZenoh::builder("vehicle1")?; UPTransportZenoh::builder("my.app")?; UPTransportZenoh::builder("service-1")?; ``` -------------------------------- ### Monitor Listener Count Health Source: https://github.com/eclipse-uprotocol/up-transport-zenoh-rust/blob/main/_autodocs/usage-patterns.md This example demonstrates a background task that periodically monitors the number of active listeners against a defined maximum. It prints a warning when listener usage exceeds a certain threshold, aiding in resource management. ```rust async fn monitor_listener_health( transport: Arc, ) { let mut interval = tokio::time::interval(Duration::from_secs(60)); loop { interval.tick().await; // In real implementation, you'd track this let current_listeners = 42; // Your tracking let max_listeners = 100; if current_listeners > max_listeners * 80 / 100 { eprintln!("WARNING: Listener usage at {}%", current_listeners * 100 / max_listeners); } } } ``` -------------------------------- ### Handle RESOURCE_EXHAUSTED when Exceeding Max Listeners Source: https://github.com/eclipse-uprotocol/up-transport-zenoh-rust/blob/main/_autodocs/errors.md This example shows how to handle the RESOURCE_EXHAUSTED error when the number of registered listeners exceeds the maximum limit. It sets a low limit for demonstration purposes. ```rust let transport = UPTransportZenoh::builder("vehicle")? .with_max_listeners(2) // Very low limit for demo .with_config(zenoh_config::Config::default()) .build() .await?; // Register first listener — succeeds let filter1 = UUri::from_str("//*/FFFFFFFF/FF/8000")?; transport.register_listener(&filter1, None, listener1).await?; // Register second listener — succeeds let filter2 = UUri::from_str("//*/FFFFFFFF/FF/8001")?; transport.register_listener(&filter2, None, listener2).await?; // Register third listener — fails with RESOURCE_EXHAUSTED let filter3 = UUri::from_str("//*/FFFFFFFF/FF/8002")?; let result = transport.register_listener(&filter3, None, listener3).await; assert!(result.is_err_and(|e| e.get_code() == UCode::RESOURCE_EXHAUSTED)); ``` -------------------------------- ### Register a uProtocol Listener with Zenoh Source: https://github.com/eclipse-uprotocol/up-transport-zenoh-rust/blob/main/_autodocs/api-reference/listener-registry.md Registers a uProtocol listener for messages matching a given Zenoh key expression. This method handles Zenoh subscriber creation, message callback setup, and listener storage. It returns an error if the maximum subscriber limit is reached or if Zenoh subscriber creation fails. ```rust // Internal API; normally called via UPTransportZenoh::register_listener() use async_trait::async_trait; use std::sync::Arc; use up_rust::{UListener, UMessage}; struct MyListener; #[async_trait] impl UListener for MyListener { async fn on_receive(&self, msg: UMessage) { println!("Got message"); } } let registry = /* ... */; registry.register_subscriber( "up/vehicle1/ABCD/1/0/8000".to_string(), Arc::new(MyListener) ).await?; ``` -------------------------------- ### Initialize Builder with Config File Path Source: https://github.com/eclipse-uprotocol/up-transport-zenoh-rust/blob/main/_autodocs/api-reference/uptransport-zenoh-builder.md Use `with_config_path` to set Zenoh configuration by loading from a file path. This transitions the builder to `ConfigPathBuilderState`. ```rust use up_transport_zenoh::UPTransportZenoh; let builder = UPTransportZenoh::builder("vehicle1")?; let config_builder = builder.with_config_path("/etc/zenoh/config.json5".to_string()); // Now call .build() or .with_max_listeners() ``` -------------------------------- ### Enable Info Logging for Initialization Source: https://github.com/eclipse-uprotocol/up-transport-zenoh-rust/blob/main/_autodocs/configuration.md Illustrates setting RUST_LOG to info level, useful for tracking initialization processes. ```bash # Enable logging from initialization RUST_LOG=info ./my_app ``` -------------------------------- ### build (from ConfigBuilderState) Source: https://github.com/eclipse-uprotocol/up-transport-zenoh-rust/blob/main/_autodocs/api-reference/uptransport-zenoh-builder.md Creates and initializes the transport with the provided configuration. This method is available after calling `.with_config()`. ```APIDOC ## build (from ConfigBuilderState) ### Description Creates and initializes the transport with the provided configuration. This method is available after calling `.with_config()`. ### Method `build` ### Parameters None (configuration already set) ### Request Example ```rust use up_transport_zenoh::{zenoh_config, UPTransportZenoh}; #[tokio::main] async fn main() -> Result<(), Box> { let transport = UPTransportZenoh::builder("vehicle1")? .with_config(zenoh_config::Config::default()) .build() .await?; Ok(()) } ``` ### Response #### Success Response (200) `Result` — An initialized transport instance. #### Response Example None (returns initialized transport instance or error) ``` -------------------------------- ### Validate UMessage Attributes for Sending Source: https://github.com/eclipse-uprotocol/up-transport-zenoh-rust/blob/main/_autodocs/errors.md Example showing how to create an invalid UMessage (missing sink for a notification) that will result in an INVALID_ARGUMENT error when sent. ```rust // Create invalid notification (missing sink): let invalid_msg = UMessage { attributes: Some(UAttributes { type_: UMessageType::UMESSAGE_TYPE_NOTIFICATION.into(), source: Some(source_uri).into(), sink: None.into(), ..Default::default() }).into(), ..Default::default() }; match transport.send(invalid_msg).await { Err(status) if status.get_code() == UCode::INVALID_ARGUMENT => { println!("Message validation failed"); } _ => {} } ``` -------------------------------- ### Build UPTransportZenoh with Configuration File Source: https://github.com/eclipse-uprotocol/up-transport-zenoh-rust/blob/main/_autodocs/api-reference/uptransport-zenoh-builder.md Initializes the transport by loading configuration from a specified file path. Ensure the configuration file is valid and accessible. ```rust use up_transport_zenoh::UPTransportZenoh; #[tokio::main] async fn main() -> Result<(), Box> { let transport = UPTransportZenoh::builder("vehicle1")? .with_config_path("config.json5".to_string()) .build() .await?; Ok(()) } ``` -------------------------------- ### Initialize Builder with Config Object Source: https://github.com/eclipse-uprotocol/up-transport-zenoh-rust/blob/main/_autodocs/api-reference/uptransport-zenoh-builder.md Use `with_config` to set Zenoh configuration using a `zenoh::config::Config` object. This transitions the builder to `ConfigBuilderState`. ```rust use up_transport_zenoh::{zenoh_config, UPTransportZenoh}; let builder = UPTransportZenoh::builder("vehicle1")?; let config = zenoh_config::Config::default(); let configured_builder = builder.with_config(config); // Now call .build() or .with_max_listeners() ``` -------------------------------- ### build (from session) Source: https://github.com/eclipse-uprotocol/up-transport-zenoh-rust/blob/main/_autodocs/api-reference/uptransport-zenoh-builder.md Creates and initializes the transport using a pre-established Zenoh session. This is a synchronous operation. ```APIDOC ## build (from session) ### Description Creates and initializes the transport using a pre-established Zenoh session. This is a synchronous operation. ### Method `fn build(self) -> Result` ### Parameters None (session already set) ### Return Type `Result` — An initialized transport instance. ### Note This method is synchronous (not async) since the session is already established. ### Example ```rust use up_transport_zenoh::UPTransportZenoh; use zenoh::config::Config; #[tokio::main] async fn main() -> Result<(), Box> { let zenoh_session = zenoh::open(Config::default()).await?; let transport = UPTransportZenoh::builder("vehicle1")? .with_session(zenoh_session) .build()?; Ok(()) } ``` ``` -------------------------------- ### build (from config path) Source: https://github.com/eclipse-uprotocol/up-transport-zenoh-rust/blob/main/_autodocs/api-reference/uptransport-zenoh-builder.md Creates and initializes the transport by loading the configuration from a specified file path. This is an asynchronous operation. ```APIDOC ## build (from config path) ### Description Creates and initializes the transport by loading the configuration from a specified file path. This is an asynchronous operation. ### Method `async fn build(self) -> Result` ### Parameters None (configuration path already set) ### Return Type `Result` — An initialized transport instance, or an error. ### Errors - `UCode::INVALID_ARGUMENT`: Configuration file cannot be read or is invalid. - `UCode::INTERNAL`: Zenoh session cannot be opened after loading config. ### Example ```rust use up_transport_zenoh::UPTransportZenoh; #[tokio::main] async fn main() -> Result<(), Box> { let transport = UPTransportZenoh::builder("vehicle1")? .with_config_path("config.json5".to_string()) .build() .await?; Ok(()) } ``` ``` -------------------------------- ### Error Handling for Transport Send Operation Source: https://github.com/eclipse-uprotocol/up-transport-zenoh-rust/blob/main/_autodocs/types.md Provides an example of how to handle potential errors when sending a message using the transport. It demonstrates extracting the error code and message from the UStatus. ```rust match transport.send(message).await { Ok(()) => println!("Message sent"), Err(status) => { let code = status.get_code(); let message = status.get_message(); eprintln!("Failed: {:?} - {}", code, message); } } ``` -------------------------------- ### Initialize Builder with Existing Zenoh Session Source: https://github.com/eclipse-uprotocol/up-transport-zenoh-rust/blob/main/_autodocs/api-reference/uptransport-zenoh-builder.md Use `with_session` to set Zenoh configuration by providing an existing Zenoh session. This transitions the builder to `SessionBuilderState`. ```rust use up_transport_zenoh::UPTransportZenoh; use zenoh::config::Config; let zenoh_session = zenoh::open(Config::default()).await?; let builder = UPTransportZenoh::builder("vehicle1")?; let session_builder = builder.with_session(zenoh_session); // Now call .build() or .with_max_listeners() ``` -------------------------------- ### Build UPTransportZenoh with Existing Session Source: https://github.com/eclipse-uprotocol/up-transport-zenoh-rust/blob/main/_autodocs/api-reference/uptransport-zenoh-builder.md Demonstrates how to create a UPTransportZenoh instance using an existing Zenoh session and configure the maximum number of listeners. ```rust let session = zenoh::open(custom_config).await?; let transport = UPTransportZenoh::builder("myapp")? .with_session(session) .with_max_listeners(50) .build()?; ``` -------------------------------- ### Build UPTransportZenoh with Authority Name Validation Source: https://github.com/eclipse-uprotocol/up-transport-zenoh-rust/blob/main/_autodocs/errors.md Examples demonstrating invalid authority names that result in an INVALID_ARGUMENT error when building the UPTransportZenoh. A valid authority name is also shown. ```rust // All of these return INVALID_ARGUMENT error: assert!(UPTransportZenoh::builder("").is_err()); assert!(UPTransportZenoh::builder("*").is_err()); assert!(UPTransportZenoh::builder("invalid name!").is_err()); // This succeeds: let builder = UPTransportZenoh::builder("vehicle1")?; ``` -------------------------------- ### with_config_path Source: https://github.com/eclipse-uprotocol/up-transport-zenoh-rust/blob/main/_autodocs/api-reference/uptransport-zenoh-builder.md Sets the Zenoh configuration by loading from a file path. This method transitions the builder to the ConfigPathBuilderState. ```APIDOC ## with_config_path ### Description Sets the Zenoh configuration by loading from a file path. This method transitions the builder to the ConfigPathBuilderState, allowing for subsequent calls to `.build()` or `.with_max_listeners()`. ### Method `with_config_path` ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body - **config_path** (String) - Required - Path to a Zenoh config file (JSON5 or other format supported by Zenoh). ### Request Example ```rust use up_transport_zenoh::UPTransportZenoh; let builder = UPTransportZenoh::builder("vehicle1")?; let config_builder = builder.with_config_path("/etc/zenoh/config.json5".to_string()); // Now call .build() or .with_max_listeners() ``` ### Response #### Success Response `UPTransportZenohBuilder` — Builder in ConfigPathBuilderState, ready for `.build()` or `.with_max_listeners()`. #### Response Example None (returns builder instance) ``` -------------------------------- ### Build and Test Rust Library Source: https://github.com/eclipse-uprotocol/up-transport-zenoh-rust/blob/main/README.md Commands to check code quality, build the library, run tests, and generate test coverage reports. ```shell cargo clippy --all-targets cargo build cargo test cargo tarpaulin -o lcov -o html --output-dir target/tarpaulin ``` -------------------------------- ### InitialBuilderState Source: https://github.com/eclipse-uprotocol/up-transport-zenoh-rust/blob/main/_autodocs/types.md Marker type indicating no Zenoh configuration has been set yet on the builder. Provides methods to transition to different builder states. ```APIDOC ## InitialBuilderState ### Description Marker type indicating no Zenoh configuration has been set yet on the builder. Provides methods to transition to different builder states. ### Definition ```rust pub struct InitialBuilderState; ``` ### Location src/lib.rs:143 ### Trait Implementations - `BuilderState` ### Available Methods - `with_config(config: zenoh_config::Config) → UPTransportZenohBuilder` - `with_config_path(path: String) → UPTransportZenohBuilder` - `with_session(session: Session) → UPTransportZenohBuilder` - `with_max_listeners(max: usize) → Self` (available in any state) ### Example ```rust let builder: UPTransportZenohBuilder = UPTransportZenoh::builder("vehicle1")?; ``` ``` -------------------------------- ### Build UPTransportZenoh Instance with Config Source: https://github.com/eclipse-uprotocol/up-transport-zenoh-rust/blob/main/_autodocs/api-reference/uptransport-zenoh-builder.md Call `build` after configuring with `with_config` to create and initialize the transport. This method may return an error if the Zenoh session cannot be opened. ```rust use up_transport_zenoh::{zenoh_config, UPTransportZenoh}; #[tokio::main] async fn main() -> Result<(), Box> { let transport = UPTransportZenoh::builder("vehicle1")? .with_config(zenoh_config::Config::default()) .build() .await?; Ok(()) } ``` -------------------------------- ### Initialization with Custom Zenoh Configuration Source: https://github.com/eclipse-uprotocol/up-transport-zenoh-rust/blob/main/_autodocs/usage-patterns.md Initializes the UPTransportZenoh using a custom Zenoh configuration, allowing connection to a remote router as a client. ```rust use up_transport_zenoh::{zenoh_config, UPTransportZenoh}; use serde_json::json; #[tokio::main] async fn main() -> Result<(), Box> { let mut config = zenoh_config::Config::default(); // Run as Zenoh client connecting to a remote router config.insert_json5("mode", &json!("client").to_string())?; config.insert_json5( "connect/endpoints", &json!(["tcp/zenoh-router.example.com:7447"]) .to_string() )?; let transport = UPTransportZenoh::builder("myapp")? .with_config(config) .build() .await?; Ok(()) } ``` -------------------------------- ### UPTransportZenoh::try_init_log_from_env Source: https://github.com/eclipse-uprotocol/up-transport-zenoh-rust/blob/main/_autodocs/api-reference/uptransport-zenoh.md Initializes a tracing formatter subscriber using the RUST_LOG environment variable for logging configuration. ```APIDOC ## UPTransportZenoh::try_init_log_from_env ### Description Initializes a tracing formatter subscriber using the `RUST_LOG` environment variable. ### Method Associated Function ### Signature ```rust pub fn try_init_log_from_env() ``` ### Parameters None ### Return Type None ### Example ```rust use up_transport_zenoh::UPTransportZenoh; // Initialize logging based on RUST_LOG environment variable UPTransportZenoh::try_init_log_from_env(); // Now logs will be printed according to RUST_LOG level // RUST_LOG=debug ./my_app ``` ``` -------------------------------- ### with_config Source: https://github.com/eclipse-uprotocol/up-transport-zenoh-rust/blob/main/_autodocs/api-reference/uptransport-zenoh-builder.md Sets the Zenoh configuration using a zenoh::config::Config object. This method transitions the builder to the ConfigBuilderState. ```APIDOC ## with_config ### Description Sets the Zenoh configuration using a `zenoh::config::Config` object. This method transitions the builder to the ConfigBuilderState, allowing for subsequent calls to `.build()` or `.with_max_listeners()`. ### Method `with_config` ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body - **config** (zenoh::config::Config) - Required - Zenoh configuration object. See [Zenoh documentation](https://zenoh.io/docs/manual/configuration/). ### Request Example ```rust use up_transport_zenoh::{zenoh_config, UPTransportZenoh}; let builder = UPTransportZenoh::builder("vehicle1")?; let config = zenoh_config::Config::default(); let configured_builder = builder.with_config(config); // Now call .build() or .with_max_listeners() ``` ### Response #### Success Response `UPTransportZenohBuilder` — Builder in ConfigBuilderState, ready for `.build()` or `.with_max_listeners()`. #### Response Example None (returns builder instance) ``` -------------------------------- ### Initialization with Logging Enabled Source: https://github.com/eclipse-uprotocol/up-transport-zenoh-rust/blob/main/_autodocs/usage-patterns.md Initializes the UPTransportZenoh and enables logging based on the RUST_LOG environment variable. Run with `RUST_LOG=debug cargo run`. ```rust use up_transport_zenoh::{zenoh_config, UPTransportZenoh}; #[tokio::main] async fn main() -> Result<(), Box> { // Initialize logging from RUST_LOG environment variable UPTransportZenoh::try_init_log_from_env(); let transport = UPTransportZenoh::builder("myapp")? .with_config(zenoh_config::Config::default()) .build() .await?; // Now all logs will be output according to RUST_LOG level Ok(()) } ``` -------------------------------- ### Initialize Logging from Environment Source: https://github.com/eclipse-uprotocol/up-transport-zenoh-rust/blob/main/_autodocs/api-index.md Initializes the tracing system from the RUST_LOG environment variable. This is useful for configuring logging levels dynamically. ```rust pub fn try_init_log_from_env() ``` -------------------------------- ### Configure Zenoh Transport by Loading Config from File Source: https://github.com/eclipse-uprotocol/up-transport-zenoh-rust/blob/main/_autodocs/configuration.md Loads Zenoh configuration from a specified file path. Supports formats like JSON5 as understood by Zenoh. ```rust let transport = UPTransportZenoh::builder("vehicle1")? .with_config_path("/etc/zenoh/config.json5".to_string()) .build() .await?; ``` -------------------------------- ### Convert uProtocol URI to Zenoh Key Source: https://github.com/eclipse-uprotocol/up-transport-zenoh-rust/blob/main/_autodocs/module-overview.md Demonstrates the conversion of a uProtocol URI to a Zenoh key expression, including handling of wildcards. The conversion involves parsing URI components and formatting them as a hex-based Zenoh key. ```text uProtocol URI: up://vehicle1/ABCD/1/8000 ↓ (parse) Components: authority=vehicle1, ue_type=ABCD, ue_instance=1, version=0, resource=8000 ↓ (format as hex) Zenoh Key: up/vehicle1/ABCD/0/1/0/8000 For wildcards: uProtocol: up://*/FFFFFFFF/FF/8000 Components: authority=*, ue_type=*, ue_instance=*, version=*, resource=8000 Zenoh Key: up/*/*/*/*/8000 ``` -------------------------------- ### Enable Debug Logging with RUST_LOG Source: https://github.com/eclipse-uprotocol/up-transport-zenoh-rust/blob/main/_autodocs/configuration.md Demonstrates how to set the RUST_LOG environment variable to enable debug logging for the application. ```bash # Enable debug logging RUST_LOG=debug ./my_app ``` -------------------------------- ### Bidirectional RPC Server Handling Source: https://github.com/eclipse-uprotocol/up-transport-zenoh-rust/blob/main/_autodocs/usage-patterns.md Implement a server that listens for RPC requests on a specific URI filter, processes them, and sends responses back to the source. Requires implementing `UListener` and using `UMessageBuilder`. ```rust async fn handle_rpc_server( transport: Arc, uri_provider: Arc, ) -> Result<(), Box> { let server_uri = uri_provider.get_authority(); // Listen for RPC requests let request_filter = UUri::from_str(&format!("//{}//*//*", server_uri))?; struct RpcHandler { transport: Arc, uri_provider: Arc, } #[async_trait] impl UListener for RpcHandler { async fn on_receive(&self, req_msg: UMessage) { let req_attrs = req_msg.attributes.unwrap(); let source = req_attrs.source.unwrap(); // Generate response let response_payload = handle_request(&req_msg.payload).await; // Send response back to requester if let Ok(response) = UMessageBuilder::response( source.clone(), req_attrs.source.unwrap(), ).build_with_payload(&response_payload, UPayloadFormat::UPAYLOAD_FORMAT_TEXT) { let _ = self.transport.send(response).await; } } } let handler = Arc::new(RpcHandler { transport: transport.clone(), uri_provider: uri_provider.clone(), }); transport.register_listener( &request_filter, Some(&UUri::try_from_parts(&server_uri, 0xFFFF, 0xFF, 0)?), handler, ).await?; Ok(()) } async fn handle_request(payload: &Option) -> String { "response".to_string() } ``` -------------------------------- ### Initialize Zenoh Logging from Environment Source: https://github.com/eclipse-uprotocol/up-transport-zenoh-rust/blob/main/_autodocs/configuration.md This Rust code snippet initializes the logging system for the Zenoh transport using the RUST_LOG environment variable. ```rust UPTransportZenoh::try_init_log_from_env(); ``` -------------------------------- ### Initialization Using an Existing Zenoh Session Source: https://github.com/eclipse-uprotocol/up-transport-zenoh-rust/blob/main/_autodocs/usage-patterns.md Initializes the UPTransportZenoh using a pre-existing Zenoh session. This is useful when multiple components need to share a single Zenoh session. Note that this build method is synchronous. ```rust use up_transport_zenoh::UPTransportZenoh; use zenoh::config::Config; #[tokio::main] async fn main() -> Result<(), Box> { // Create and configure Zenoh session manually let zenoh_session = zenoh::open(Config::default()).await?; // Use that session with the transport let transport = UPTransportZenoh::builder("myapp")? .with_session(zenoh_session) .build()?; // Note: synchronous, not async Ok(()) } ``` -------------------------------- ### UPTransportZenohBuilder with Zenoh Session Source: https://github.com/eclipse-uprotocol/up-transport-zenoh-rust/blob/main/_autodocs/types.md Demonstrates how to build a UPTransportZenoh instance by providing an existing Zenoh session. The builder transitions through SessionBuilderState, and the final build step is synchronous. ```rust let zenoh_session = zenoh::open(zenoh::config::Config::default()).await?; let builder = UPTransportZenoh::builder("vehicle1")? .with_session(zenoh_session); // builder now has type UPTransportZenohBuilder let transport = builder.build()?; // synchronous! ``` -------------------------------- ### Enable Trace Logging for Zenoh Module Source: https://github.com/eclipse-uprotocol/up-transport-zenoh-rust/blob/main/_autodocs/configuration.md Shows how to configure RUST_LOG to enable trace-level logging specifically for the up_transport_zenoh module. ```bash # Enable trace logging for specific modules RUST_LOG=up_transport_zenoh=trace ./my_app ``` -------------------------------- ### Create UPTransportZenoh with Default Config Source: https://github.com/eclipse-uprotocol/up-transport-zenoh-rust/blob/main/_autodocs/README.md Creates a UPTransportZenoh instance using the builder pattern with a default Zenoh configuration. Requires the `up_transport_zenoh` crate and an async runtime. ```rust use up_transport_zenoh::UPTransportZenoh; let transport = UPTransportZenoh::builder("myapp")? .with_config(zenoh::config::Config::default()) .build() .await?; ``` -------------------------------- ### Chain Max Listeners Configuration Source: https://github.com/eclipse-uprotocol/up-transport-zenoh-rust/blob/main/_autodocs/configuration.md Demonstrates setting the maximum number of listeners either before or after configuring the Zenoh session. ```rust // Can set before config let transport = UPTransportZenoh::builder("vehicle1")? .with_max_listeners(50) .with_config(config) .build() .await?; // Or after config let transport = UPTransportZenoh::builder("vehicle1")? .with_config(config) .with_max_listeners(50) .build() .await?; ``` -------------------------------- ### UPTransportZenoh Configuration Loading from File with Max Listeners Source: https://github.com/eclipse-uprotocol/up-transport-zenoh-rust/blob/main/_autodocs/api-reference/uptransport-zenoh-builder.md Builds the transport by loading configuration from a file and setting a custom maximum number of listeners. This combines file-based configuration with specific listener limits. ```rust let transport = UPTransportZenoh::builder("myapp")? .with_config_path("/etc/zenoh.json5".to_string()) .with_max_listeners(100) .build() .await?; ``` -------------------------------- ### Create UPTransportZenoh Instance Source: https://github.com/eclipse-uprotocol/up-transport-zenoh-rust/blob/main/_autodocs/README.md Instantiates the UPTransportZenoh with a specified authority and configuration. Requires Zenoh configuration and an async runtime. ```rust let transport = UPTransportZenoh::builder("local_authority")? .with_config(config) .build() .await?; transport.send(message).await?; ``` -------------------------------- ### UPTransportZenohBuilder::with_config_path Source: https://github.com/eclipse-uprotocol/up-transport-zenoh-rust/blob/main/_autodocs/api-index.md Sets the path to a Zenoh configuration file for the transport builder. This method takes a file path string and transitions the builder state. ```APIDOC ## UPTransportZenohBuilder::with_config_path ### Description Sets the path to a Zenoh configuration file for the transport builder. This method takes a file path string and transitions the builder state. ### Method `pub fn with_config_path(self, config_path: String) -> UPTransportZenohBuilder` ### Parameters * `config_path` (String) - The path to the Zenoh configuration file. ### Returns * `UPTransportZenohBuilder` - The builder in the `ConfigPathBuilderState`. ``` -------------------------------- ### Create UPTransportZenoh Builder Source: https://github.com/eclipse-uprotocol/up-transport-zenoh-rust/blob/main/_autodocs/api-reference/uptransport-zenoh.md Constructs a builder for a new Zenoh transport instance. The local authority name must be valid according to uProtocol specifications. Use this to begin configuring the transport. ```rust use up_transport_zenoh::UPTransportZenoh; // Create a builder with a valid authority name let builder = UPTransportZenoh::builder("vehicle1") .expect("invalid authority name"); // Authority names must conform to uProtocol spec assert!(UPTransportZenoh::builder("").is_err()); // empty assert!(UPTransportZenoh::builder("*" ).is_err()); // wildcard ``` -------------------------------- ### UPTransportZenohBuilder Usage with Session Source: https://github.com/eclipse-uprotocol/up-transport-zenoh-rust/blob/main/_autodocs/types.md Demonstrates how to use the UPTransportZenoh builder with an existing Zenoh session. This involves creating a Zenoh session, passing it to the builder, and then building the transport. ```APIDOC ## UPTransportZenohBuilder ### Description This builder state allows for the construction of `UPTransportZenoh` after an existing Zenoh session has been provided. ### Method `build()` ### Endpoint N/A (SDK method) ### Parameters None directly on `build()`. Configuration is done via preceding builder methods. ### Request Example ```rust use up_transport_zenoh::UPTransportZenoh; // Assume zenoh_session is an established zenoh::Session let zenoh_session = zenoh::open(zenoh::config::Config::default()).await?; let builder = UPTransportZenoh::builder("vehicle1")? .with_session(zenoh_session); // builder now has type UPTransportZenohBuilder let transport = builder.build()?; // synchronous build ``` ### Response #### Success Response - `UPTransportZenoh`: An initialized UPTransportZenoh instance. - `UStatus`: If an error occurs during the build process. ``` -------------------------------- ### ConfigBuilderState Source: https://github.com/eclipse-uprotocol/up-transport-zenoh-rust/blob/main/_autodocs/types.md Marker type indicating a Zenoh configuration object has been set on the builder. Allows building the transport or further configuration. ```APIDOC ## ConfigBuilderState ### Description Marker type indicating a Zenoh configuration object has been set on the builder. Allows building the transport or further configuration. ### Definition ```rust pub struct ConfigBuilderState { config: zenoh_config::Config, } ``` ### Location src/lib.rs:144-146 ### Trait Implementations - `BuilderState` ### Fields - **config** (zenoh_config::Config) - Zenoh configuration object. ### Available Methods - `build() → Result` (async) - `with_max_listeners(max: usize) → Self` ### Transition Returned by `UPTransportZenohBuilder::with_config()`. ### Example ```rust use up_transport_zenoh::zenoh_config; let builder = UPTransportZenoh::builder("vehicle1")? .with_config(zenoh_config::Config::default()); // builder now has type UPTransportZenohBuilder let transport = builder.build().await?; ``` ``` -------------------------------- ### Initialize Logging from Environment Source: https://github.com/eclipse-uprotocol/up-transport-zenoh-rust/blob/main/_autodocs/api-reference/uptransport-zenoh.md Initializes a tracing formatter subscriber using the RUST_LOG environment variable. This allows controlling log verbosity via environment settings without code changes. Ensure RUST_LOG is set before calling this function. ```rust use up_transport_zenoh::UPTransportZenoh; // Initialize logging based on RUST_LOG environment variable UPTransportZenoh::try_init_log_from_env(); // Now logs will be printed according to RUST_LOG level // RUST_LOG=debug ./my_app ``` -------------------------------- ### Configure UPTransportZenoh with Config Path Source: https://github.com/eclipse-uprotocol/up-transport-zenoh-rust/blob/main/_autodocs/api-index.md Provides a path to a Zenoh configuration file for the transport builder. This allows external configuration files to be used. ```rust pub fn with_config_path( self, config_path: String, ) -> UPTransportZenohBuilder ``` -------------------------------- ### Parametrized and Async Tokio Tests Source: https://github.com/eclipse-uprotocol/up-transport-zenoh-rust/blob/main/_autodocs/implementation-details.md Demonstrates the use of the `test-case` crate for parametrized tests and `tokio::test` for asynchronous tests in Rust. ```rust #[test_case(input1 => expected1; "description")] #[test_case(input2 => expected2; "description")] #[tokio::test(flavor = "multi_thread")] async fn test_name(param: Type) -> ReturnType { // test logic } ``` -------------------------------- ### Re-export: zenoh_config Source: https://github.com/eclipse-uprotocol/up-transport-zenoh-rust/blob/main/_autodocs/types.md Provides convenient access to the Zenoh configuration module for setting up Zenoh connections. ```APIDOC ## zenoh_config ### Description Re-export of the `zenoh::config` module, providing access to Zenoh configuration types like `Config`. ### Method N/A (Type re-export) ### Endpoint N/A ### Parameters N/A ### Request Example ```rust use up_transport_zenoh::zenoh_config; let config = zenoh_config::Config::default(); // Use this config to open a Zenoh session ``` ``` -------------------------------- ### Register Listener with Valid Argument Source: https://github.com/eclipse-uprotocol/up-transport-zenoh-rust/blob/main/_autodocs/errors.md Demonstrates registering a listener with a valid source URI resource ID for topic-based patterns. This should succeed. ```rust let good_filter = UUri::from_str("//vehicle/ABCD/1/8000")?; assert!(transport.register_listener(&good_filter, None, listener).await.is_ok()); ``` -------------------------------- ### Build UPTransportZenoh with Configured Zenoh Source: https://github.com/eclipse-uprotocol/up-transport-zenoh-rust/blob/main/_autodocs/api-index.md Builds the UPTransportZenoh instance using the Zenoh configuration provided via `.with_config()`. This is an asynchronous operation. ```rust pub async fn build(self) -> Result ``` -------------------------------- ### UPTransportZenoh Builder States Source: https://github.com/eclipse-uprotocol/up-transport-zenoh-rust/blob/main/_autodocs/README.md Illustrates the state transitions within the UPTransportZenoh builder pattern, showing available configuration methods. ```rust UPTransportZenohBuilder ├─ .with_config() → ConfigBuilderState ├─ .with_config_path() → ConfigPathBuilderState └─ .with_session() → SessionBuilderState (all states) ├─ .with_max_listeners() → same state └─ .build() → Result ``` -------------------------------- ### Configure Zenoh Transport with Direct Config Object Source: https://github.com/eclipse-uprotocol/up-transport-zenoh-rust/blob/main/_autodocs/configuration.md Passes a pre-configured zenoh::config::Config object directly to the transport builder. ```rust use up_transport_zenoh::zenoh_config; let mut config = zenoh_config::Config::default(); // Modify config as needed let transport = UPTransportZenoh::builder("vehicle1")? .with_config(config) .build() .await?; ``` -------------------------------- ### Register Listener Performance Source: https://github.com/eclipse-uprotocol/up-transport-zenoh-rust/blob/main/_autodocs/implementation-details.md This snippet details the performance characteristics of the register listener path, highlighting the constant time complexity and key operations involved. ```text register_listener(filter, listener) ├─ Validate filters — O(1) ├─ Convert to Zenoh key — O(1) ├─ Lock registry — O(1) ├─ Check capacity — O(1) ├─ Check duplicate — O(1) HashMap lookup ├─ Create subscriber — O(1) async Zenoh operation └─ Insert to HashMap — O(1) amortized Total: O(1) with small constant factor ``` -------------------------------- ### Build UPTransportZenoh with Existing Zenoh Session Source: https://github.com/eclipse-uprotocol/up-transport-zenoh-rust/blob/main/_autodocs/api-reference/uptransport-zenoh-builder.md Creates the transport using a pre-established Zenoh session. This method is synchronous as the session is already open. ```rust use up_transport_zenoh::UPTransportZenoh; use zenoh::config::Config; #[tokio::main] async fn main() -> Result<(), Box> { let zenoh_session = zenoh::open(Config::default()).await?; let transport = UPTransportZenoh::builder("vehicle1")? .with_session(zenoh_session) .build()?; Ok(()) } ``` -------------------------------- ### Re-export Zenoh Configuration Source: https://github.com/eclipse-uprotocol/up-transport-zenoh-rust/blob/main/_autodocs/types.md Shows how to use the re-exported zenoh_config module to create a Zenoh configuration object. This is typically used when initializing the transport with custom Zenoh settings. ```rust use up_transport_zenoh::zenoh_config; let config = zenoh_config::Config::default(); ``` -------------------------------- ### Builder Pattern: Valid Configuration Sequence Source: https://github.com/eclipse-uprotocol/up-transport-zenoh-rust/blob/main/_autodocs/module-overview.md Demonstrates a valid sequence of configuration steps using the type state pattern for the Zenoh transport builder. This ensures that essential configurations like Zenoh settings are provided before building the transport. ```rust builder .with_config(config) // Returns ConfigBuilderState .with_max_listeners(50) // Chainable on any state .build() // Valid: ConfigBuilderState has .build() ``` -------------------------------- ### Configure Connect Endpoints Source: https://github.com/eclipse-uprotocol/up-transport-zenoh-rust/blob/main/_autodocs/configuration.md Specifies the remote Zenoh routers or peers to connect to. Accepts a JSON array of endpoint strings. ```rust config.insert_json5( "connect/endpoints", &json!(["tcp/127.0.0.1:7447", "tcp/192.168.1.1:7447"]).to_string() )?; ``` -------------------------------- ### Configure Listen Endpoints Source: https://github.com/eclipse-uprotocol/up-transport-zenoh-rust/blob/main/_autodocs/configuration.md Defines the local endpoints on which the Zenoh session will listen for incoming connections. Accepts a JSON array of endpoint strings. ```rust config.insert_json5( "listen/endpoints", &json!(["tcp/0.0.0.0:7447"]).to_string() )?; ``` -------------------------------- ### with_session Source: https://github.com/eclipse-uprotocol/up-transport-zenoh-rust/blob/main/_autodocs/api-reference/uptransport-zenoh-builder.md Sets the Zenoh configuration by providing an existing Zenoh session. This method transitions the builder to the SessionBuilderState. ```APIDOC ## with_session ### Description Sets the Zenoh configuration by providing an existing Zenoh session. This method transitions the builder to the SessionBuilderState, allowing for subsequent calls to `.build()` or `.with_max_listeners()`. ### Method `with_session` ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body - **zenoh_session** (zenoh::Session) - Required - An already-open Zenoh session. Ownership is transferred to the transport. ### Request Example ```rust use up_transport_zenoh::UPTransportZenoh; use zenoh::config::Config; let zenoh_session = zenoh::open(Config::default()).await?; let builder = UPTransportZenoh::builder("vehicle1")?; let session_builder = builder.with_session(zenoh_session); // Now call .build() or .with_max_listeners() ``` ### Response #### Success Response `UPTransportZenohBuilder` — Builder in SessionBuilderState, ready for `.build()` or `.with_max_listeners()`. #### Response Example None (returns builder instance) ``` -------------------------------- ### UPTransportZenohBuilder::build Source: https://github.com/eclipse-uprotocol/up-transport-zenoh-rust/blob/main/_autodocs/api-index.md Builds the `UPTransportZenoh` instance using the configured Zenoh configuration. This is an asynchronous operation. ```APIDOC ## UPTransportZenohBuilder::build ### Description Builds the `UPTransportZenoh` instance using the configured Zenoh configuration. This is an asynchronous operation. ### Method `pub async fn build(self) -> Result` ### Returns * `Result` - The constructed `UPTransportZenoh` instance or a `UStatus` error. ``` -------------------------------- ### Basic Listener Implementation Source: https://github.com/eclipse-uprotocol/up-transport-zenoh-rust/blob/main/_autodocs/usage-patterns.md Implements a basic listener for receiving messages. The `on_receive` method is called for each incoming message. Requires registering the listener with a filter. ```rust use async_trait::async_trait; use std::sync::Arc; use up_rust::{UListener, UMessage}; struct MyListener; #[async_trait] impl UListener for MyListener { async fn on_receive(&self, msg: UMessage) { let payload = msg.payload.unwrap_or_default(); let text = String::from_utf8_lossy(&payload); println!("Received: {}", text); } } // Register it let listener = Arc::new(MyListener); let filter = UUri::from_str("//*/FFFFFFFF/FF/8001")?; transport.register_listener(&filter, None, listener).await?; ``` -------------------------------- ### Set Zenoh Session Mode Source: https://github.com/eclipse-uprotocol/up-transport-zenoh-rust/blob/main/_autodocs/configuration.md Configures the Zenoh session mode. Options include 'peer', 'client', or 'router'. ```rust use serde_json::json; let mut config = zenoh_config::Config::default(); config.insert_json5("mode", &json!("peer").to_string())?; ``` -------------------------------- ### Create a new ListenerRegistry Source: https://github.com/eclipse-uprotocol/up-transport-zenoh-rust/blob/main/_autodocs/api-reference/listener-registry.md Instantiates a new ListenerRegistry with a specified Zenoh session and maximum subscriber capacity. This is an internal function called during the initialization of UPTransportZenoh. ```rust use std::sync::Arc; use up_transport_zenoh::listener_registry::ListenerRegistry; let zenoh_session = zenoh::open(zenoh::config::Config::default()).await?; let registry = ListenerRegistry::new(Arc::new(zenoh_session), 100); ``` -------------------------------- ### Add Dependencies to Rust Project Source: https://github.com/eclipse-uprotocol/up-transport-zenoh-rust/blob/main/README.md Commands to add the necessary up-rust and up-transport-zenoh crates as dependencies to your Rust project. ```shell cargo add up-rust cargo add up-transport-zenoh ``` -------------------------------- ### ConfigPathBuilderState Source: https://github.com/eclipse-uprotocol/up-transport-zenoh-rust/blob/main/_autodocs/types.md Marker type indicating a configuration file path has been set on the builder. Allows building the transport or further configuration, with error handling for file operations. ```APIDOC ## ConfigPathBuilderState ### Description Marker type indicating a configuration file path has been set on the builder. Allows building the transport or further configuration, with error handling for file operations. ### Definition ```rust pub struct ConfigPathBuilderState { config_path: String, } ``` ### Location src/lib.rs:147-149 ### Trait Implementations - `BuilderState` ### Fields - **config_path** (String) - File path to a Zenoh configuration file (JSON5 or other supported format). ### Available Methods - `build() → Result` (async) - `with_max_listeners(max: usize) → Self` ### Transition Returned by `UPTransportZenohBuilder::with_config_path()`. ### Error Handling If the file cannot be read or is invalid, `.build()` returns `UCode::INVALID_ARGUMENT`. ### Example ```rust let builder = UPTransportZenoh::builder("vehicle1")? .with_config_path("config.json5".to_string()); // builder now has type UPTransportZenohBuilder let transport = builder.build().await?; ``` ``` -------------------------------- ### Build UPTransportZenoh with Zenoh Session Source: https://github.com/eclipse-uprotocol/up-transport-zenoh-rust/blob/main/_autodocs/api-index.md Builds the transport using a pre-existing Zenoh session. This is a synchronous build operation and is available after calling `.with_session()` on the builder. ```rust pub fn build(self) -> Result ``` -------------------------------- ### Complete Zenoh Transport Configuration Source: https://github.com/eclipse-uprotocol/up-transport-zenoh-rust/blob/main/_autodocs/configuration.md Builds a Zenoh transport instance with custom configuration, including mode, connection endpoints, and scouting settings. ```rust use up_transport_zenoh::{zenoh_config, UPTransportZenoh}; use serde_json::json; let mut config = zenoh_config::Config::default(); // Set mode config.insert_json5("mode", &json!("client").to_string())?; // Set connection endpoints config.insert_json5( "connect/endpoints", &json!(["tcp/zenoh-router:7447"]).to_string() )?; // Disable multicast discovery config.insert_json5("scouting/multicast/enabled", &json!(false).to_string())?; // Build transport with custom config let transport = UPTransportZenoh::builder("vehicle1")? .with_max_listeners(200) .with_config(config) .build() .await?; ```