#[cfg(feature = "http")]
mod http;
#[cfg(feature = "mqtt")]
mod mqtt_broker;
#[cfg(feature = "mqtt")]
mod response_collector;
#[cfg(feature = "mqtt")]
mod shared_mqtt_client;
#[cfg(feature = "mqtt")]
mod topic_router;
#[cfg(feature = "http")]
pub use http::HttpConfig;
#[cfg(feature = "mqtt")]
pub use mqtt_broker::{MqttBroker, MqttBrokerBuilder};
#[cfg(feature = "http")]
pub use http::{HttpClient, HttpClientBuilder};
#[cfg(feature = "mqtt")]
pub use shared_mqtt_client::SharedMqttClient;
#[cfg(feature = "mqtt")]
pub use mqtt_broker::MqttBrokerConfig;
#[cfg(feature = "mqtt")]
pub use response_collector::ResponseSpec;
#[cfg(feature = "mqtt")]
pub use topic_router::TopicRouter;
use crate::command::Command;
use crate::error::ProtocolError;
#[derive(Debug, Clone)]
pub struct CommandResponse {
body: String,
}
impl CommandResponse {
#[must_use]
pub fn new(body: String) -> Self {
Self { body }
}
#[must_use]
pub fn body(&self) -> &str {
&self.body
}
pub fn parse<T: serde::de::DeserializeOwned>(&self) -> Result<T, crate::error::ParseError> {
serde_json::from_str(&self.body).map_err(Into::into)
}
}
#[allow(async_fn_in_trait)]
pub trait Protocol: Send + Sync {
async fn send_command<C: Command + Sync>(
&self,
command: &C,
) -> Result<CommandResponse, ProtocolError>;
async fn send_raw(&self, command: &str) -> Result<CommandResponse, ProtocolError>;
}