opcda_bridge/lib.rs
1//! Reusable, presentation-free async client for the opcda-bridge gateway's
2//! gRPC API.
3//!
4//! This crate is the typed connect/read/write/browse/search/list-servers surface
5//! extracted from `opcda-bridge-client`'s `commands.rs`: no `clap`, no
6//! `tabled`, no `serde_json`/`toml` — just [`Client`], the parameters its
7//! methods take, and the plain result types they return ([`BrowsePage`],
8//! [`SearchEvent`], [`TagValue`], [`WriteResult`], [`Value`]). `opcda-bridge-client` depends
9//! on this crate and adds only CLI parsing and table/JSON rendering on top
10//! of it; any other async Rust program that needs typed OPC DA
11//! reads/writes/browses without shelling out to the CLI binary and parsing
12//! its output can depend on this crate directly instead.
13//!
14//! ```no_run
15//! use opcda_bridge::{BrowsePageRequest, SearchMatchMode, SearchRequest};
16//!
17//! # async fn example() -> opcda_bridge::Result<()> {
18//! let mut client = opcda_bridge::Client::connect("localhost:7600").await?;
19//! let servers = client.list_servers().await?;
20//! let root = client.browse(servers[0].clone(), 200).await?;
21//! if let Some(token) = root.next_page_token.clone() {
22//! let request =
23//! BrowsePageRequest::next(servers[0].clone(), root.session_id.clone(), None, token, 200);
24//! let _next_page = client.browse_page(request).await?;
25//! }
26//! let mut search = client
27//! .search_stream(SearchRequest::new(
28//! servers[0].clone(),
29//! "Some",
30//! SearchMatchMode::Prefix,
31//! ))
32//! .await?;
33//! while let Some(event) = search.message().await? {
34//! println!("{event:?}");
35//! }
36//! let values = client
37//! .read(servers[0].clone(), vec!["Some.Tag".into()])
38//! .await?;
39//! client.close_browse_session(root.session_id).await?;
40//! # let _ = values;
41//! # Ok(())
42//! # }
43//! ```
44
45mod client;
46mod error;
47mod types;
48
49#[cfg(test)]
50mod test_support;
51
52pub use client::Client;
53pub use client::SearchStream;
54pub use error::{Error, Result};
55pub use opcda_bridge_proto::DEFAULT_BRIDGE_PORT;
56pub use types::{
57 BrowseBreadcrumb, BrowseNode, BrowseNodeKind, BrowsePage, BrowsePageRequest, BrowseSource,
58 Capabilities, DEFAULT_PAGE_SIZE, DEFAULT_SEARCH_MAX_RESULTS, NamespaceOrganization,
59 SearchCompleted, SearchEvent, SearchMatch, SearchMatchMode, SearchProgress, SearchRequest,
60 TagValue, Value, WriteResult, parse_value,
61};