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