#[cfg(feature = "std")]
use crate::{Protocol, ProtocolDetector, Unknown};
#[cfg(feature = "std")]
#[derive(Debug, Default, Clone)]
pub struct ProtocolChainBuilder {
order: Vec<Protocol>,
max_inspect_bytes: usize,
}
#[cfg(feature = "std")]
impl ProtocolChainBuilder {
#[must_use]
pub fn new() -> Self {
Self {
order: Vec::new(),
max_inspect_bytes: crate::MAX_INSPECT_BYTES,
}
}
#[must_use]
pub fn max_inspect_bytes(mut self, bytes: usize) -> Self {
self.max_inspect_bytes = bytes;
self
}
#[cfg(feature = "http")]
#[must_use]
pub fn http(mut self) -> Self {
self.order.push(Protocol::Http);
self
}
#[cfg(feature = "tls")]
#[must_use]
pub fn tls(mut self) -> Self {
self.order.push(Protocol::Tls);
self
}
#[cfg(feature = "ssh")]
#[must_use]
pub fn ssh(mut self) -> Self {
self.order.push(Protocol::Ssh);
self
}
#[cfg(feature = "dns")]
#[must_use]
pub fn dns(mut self) -> Self {
self.order.push(Protocol::Dns);
self
}
#[cfg(feature = "quic")]
#[must_use]
pub fn quic(mut self) -> Self {
self.order.push(Protocol::Quic);
self
}
#[cfg(feature = "mysql")]
#[must_use]
pub fn mysql(mut self) -> Self {
self.order.push(Protocol::Mysql);
self
}
#[cfg(feature = "postgres")]
#[must_use]
pub fn postgres(mut self) -> Self {
self.order.push(Protocol::Postgres);
self
}
#[cfg(feature = "redis")]
#[must_use]
pub fn redis(mut self) -> Self {
self.order.push(Protocol::Redis);
self
}
#[cfg(feature = "mqtt")]
#[must_use]
pub fn mqtt(mut self) -> Self {
self.order.push(Protocol::Mqtt);
self
}
#[must_use]
pub fn all_tcp(mut self) -> Self {
let _ = &mut self;
#[cfg(feature = "ssh")]
{
self.order.push(Protocol::Ssh);
}
#[cfg(feature = "tls")]
{
self.order.push(Protocol::Tls);
}
#[cfg(feature = "http")]
{
self.order.push(Protocol::Http);
}
#[cfg(feature = "redis")]
{
self.order.push(Protocol::Redis);
}
#[cfg(feature = "mysql")]
{
self.order.push(Protocol::Mysql);
}
#[cfg(feature = "postgres")]
{
self.order.push(Protocol::Postgres);
}
#[cfg(feature = "mqtt")]
{
self.order.push(Protocol::Mqtt);
}
self
}
#[must_use]
pub fn all_udp(mut self) -> Self {
let _ = &mut self;
#[cfg(feature = "dns")]
{
self.order.push(Protocol::Dns);
}
#[cfg(feature = "quic")]
{
self.order.push(Protocol::Quic);
}
self
}
#[must_use]
pub fn all_db(mut self) -> Self {
let _ = &mut self;
#[cfg(feature = "redis")]
{
self.order.push(Protocol::Redis);
}
#[cfg(feature = "mysql")]
{
self.order.push(Protocol::Mysql);
}
#[cfg(feature = "postgres")]
{
self.order.push(Protocol::Postgres);
}
self
}
#[must_use]
pub fn all_web(mut self) -> Self {
let _ = &mut self;
#[cfg(feature = "http")]
{
self.order.push(Protocol::Http);
}
#[cfg(feature = "tls")]
{
self.order.push(Protocol::Tls);
}
#[cfg(feature = "quic")]
{
self.order.push(Protocol::Quic);
}
self
}
#[must_use]
pub fn from_slice(protocols: &[Protocol]) -> Self {
Self {
order: protocols.to_vec(),
max_inspect_bytes: crate::MAX_INSPECT_BYTES,
}
}
#[must_use]
pub fn build(self) -> ProtocolDetector<Unknown> {
ProtocolDetector::with_order(self.order, self.max_inspect_bytes)
}
}