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`], [`SearchIndexResponse`], [`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::{
16//! BrowsePageRequest, SearchIndexRequest, SearchMatchMode, SearchRequest,
17//! };
18//!
19//! # async fn example() -> opcda_bridge::Result<()> {
20//! let mut client = opcda_bridge::Client::connect("localhost:7600").await?;
21//! let servers = client.list_servers().await?;
22//! let root = client.browse(servers[0].clone(), 200).await?;
23//! if let Some(token) = root.next_page_token.clone() {
24//! let request =
25//! BrowsePageRequest::next(servers[0].clone(), root.session_id.clone(), None, token, 200);
26//! let _next_page = client.browse_page(request).await?;
27//! }
28//! let mut search = client
29//! .search_stream(SearchRequest::new(
30//! servers[0].clone(),
31//! "Some",
32//! SearchMatchMode::Prefix,
33//! ))
34//! .await?;
35//! while let Some(event) = search.message().await? {
36//! println!("{event:?}");
37//! }
38//! let indexed = client
39//! .search_index(SearchIndexRequest::new(
40//! servers[0].clone(),
41//! "Some PV",
42//! SearchMatchMode::Contains,
43//! ))
44//! .await?;
45//! for found in indexed.matches {
46//! println!("{}: {}", found.display_name, found.item_id);
47//! }
48//! let values = client
49//! .read(servers[0].clone(), vec!["Some.Tag".into()])
50//! .await?;
51//! client.close_browse_session(root.session_id).await?;
52//! # let _ = values;
53//! # Ok(())
54//! # }
55//! ```
56
57mod client;
58mod error;
59mod types;
60
61#[cfg(test)]
62mod test_support;
63
64pub use client::Client;
65pub use client::SearchStream;
66pub use error::{Error, Result};
67pub use opcda_bridge_proto::DEFAULT_BRIDGE_PORT;
68pub use types::{
69 BrowseBreadcrumb, BrowseNode, BrowseNodeKind, BrowsePage, BrowsePageRequest, BrowseSource,
70 Capabilities, DEFAULT_INDEX_SEARCH_MAX_RESULTS, DEFAULT_PAGE_SIZE, DEFAULT_SEARCH_MAX_RESULTS,
71 IndexedSearchMatch, IndexedSearchProgress, NamespaceOrganization, SearchCompleted, SearchEvent,
72 SearchIndexControlAction, SearchIndexRequest, SearchIndexResponse, SearchIndexState,
73 SearchIndexStatus, SearchMatch, SearchMatchMode, SearchProgress, SearchRequest, TagValue,
74 Value, WriteResult, parse_value,
75};