From 263e32ad4d313846f7bfc95564ca063db3bd020f Mon Sep 17 00:00:00 2001 From: Uwe Klotz Date: Sun, 13 Oct 2024 13:44:21 +0200 Subject: [PATCH] Restrict server features in codec (#290) --- src/codec/rtu.rs | 24 ++++++++++++------------ src/codec/tcp.rs | 6 +++--- 2 files changed, 15 insertions(+), 15 deletions(-) diff --git a/src/codec/rtu.rs b/src/codec/rtu.rs index 8c0f551..1978fd3 100644 --- a/src/codec/rtu.rs +++ b/src/codec/rtu.rs @@ -103,7 +103,7 @@ impl FrameDecoder { } } -#[cfg(feature = "server")] +#[cfg(any(feature = "rtu-over-tcp-server", feature = "rtu-server"))] #[derive(Debug, Default)] pub(crate) struct RequestDecoder { frame_decoder: FrameDecoder, @@ -119,13 +119,13 @@ pub(crate) struct ClientCodec { pub(crate) decoder: ResponseDecoder, } -#[cfg(feature = "server")] +#[cfg(any(feature = "rtu-over-tcp-server", feature = "rtu-server"))] #[derive(Debug, Default)] pub(crate) struct ServerCodec { pub(crate) decoder: RequestDecoder, } -#[cfg(feature = "server")] +#[cfg(any(feature = "rtu-over-tcp-server", feature = "rtu-server"))] fn get_request_pdu_len(adu_buf: &BytesMut) -> Result> { if let Some(fn_code) = adu_buf.get(1) { let len = match fn_code { @@ -216,7 +216,7 @@ fn check_crc(adu_data: &[u8], expected_crc: u16) -> Result<()> { Ok(()) } -#[cfg(feature = "server")] +#[cfg(any(feature = "rtu-over-tcp-server", feature = "rtu-server"))] impl Decoder for RequestDecoder { type Item = (SlaveId, Bytes); type Error = Error; @@ -299,7 +299,7 @@ impl Decoder for ClientCodec { } } -#[cfg(feature = "server")] +#[cfg(any(feature = "rtu-over-tcp-server", feature = "rtu-server"))] impl Decoder for ServerCodec { type Item = RequestAdu<'static>; type Error = Error; @@ -339,7 +339,7 @@ impl<'a> Encoder> for ClientCodec { } } -#[cfg(feature = "server")] +#[cfg(any(feature = "rtu-over-tcp-server", feature = "rtu-server"))] impl Encoder for ServerCodec { type Error = Error; @@ -370,7 +370,7 @@ mod tests { } #[test] - #[cfg(feature = "server")] + #[cfg(any(feature = "rtu-over-tcp-server", feature = "rtu-server"))] fn test_get_request_pdu_len() { let mut buf = BytesMut::new(); @@ -553,7 +553,7 @@ mod tests { } #[test] - #[cfg(feature = "server")] + #[cfg(any(feature = "rtu-over-tcp-server", feature = "rtu-server"))] fn decode_empty_server_message() { let mut codec = ServerCodec::default(); let mut buf = BytesMut::new(); @@ -566,7 +566,7 @@ mod tests { } #[test] - #[cfg(feature = "server")] + #[cfg(any(feature = "rtu-over-tcp-server", feature = "rtu-server"))] fn decode_single_byte_server_message() { let mut codec = ServerCodec::default(); let mut buf = BytesMut::from(&[0x00][..]); @@ -579,7 +579,7 @@ mod tests { } #[test] - #[cfg(feature = "server")] + #[cfg(any(feature = "rtu-over-tcp-server", feature = "rtu-server"))] fn decode_partly_received_server_message_0x16() { let mut codec = ServerCodec::default(); let mut buf = BytesMut::from( @@ -597,7 +597,7 @@ mod tests { } #[test] - #[cfg(feature = "server")] + #[cfg(any(feature = "rtu-over-tcp-server", feature = "rtu-server"))] fn decode_partly_received_server_message_0x0f() { let mut codec = ServerCodec::default(); let mut buf = BytesMut::from( @@ -615,7 +615,7 @@ mod tests { } #[test] - #[cfg(feature = "server")] + #[cfg(any(feature = "rtu-over-tcp-server", feature = "rtu-server"))] fn decode_partly_received_server_message_0x10() { let mut codec = ServerCodec::default(); let mut buf = BytesMut::from( diff --git a/src/codec/tcp.rs b/src/codec/tcp.rs index 7a3b1ce..05fb88e 100644 --- a/src/codec/tcp.rs +++ b/src/codec/tcp.rs @@ -33,7 +33,7 @@ impl ClientCodec { } } -#[cfg(feature = "server")] +#[cfg(feature = "tcp-server")] #[derive(Debug, Default)] pub(crate) struct ServerCodec { pub(crate) decoder: AduDecoder, @@ -108,7 +108,7 @@ impl Decoder for ClientCodec { } } -#[cfg(feature = "server")] +#[cfg(feature = "tcp-server")] impl Decoder for ServerCodec { type Item = RequestAdu<'static>; type Error = Error; @@ -139,7 +139,7 @@ impl<'a> Encoder> for ClientCodec { } } -#[cfg(feature = "server")] +#[cfg(feature = "tcp-server")] impl Encoder for ServerCodec { type Error = Error;