Skip to content

Commit

Permalink
Restrict server features in codec
Browse files Browse the repository at this point in the history
  • Loading branch information
uklotzde committed Oct 13, 2024
1 parent 8eaa6f7 commit 1e93356
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 15 deletions.
24 changes: 12 additions & 12 deletions src/codec/rtu.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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<Option<usize>> {
if let Some(fn_code) = adu_buf.get(1) {
let len = match fn_code {
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -339,7 +339,7 @@ impl<'a> Encoder<RequestAdu<'a>> for ClientCodec {
}
}

#[cfg(feature = "server")]
#[cfg(any(feature = "rtu-over-tcp-server", feature = "rtu-server"))]
impl Encoder<ResponseAdu> for ServerCodec {
type Error = Error;

Expand Down Expand Up @@ -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();

Expand Down Expand Up @@ -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();
Expand All @@ -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][..]);
Expand All @@ -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(
Expand All @@ -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(
Expand All @@ -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(
Expand Down
6 changes: 3 additions & 3 deletions src/codec/tcp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ impl ClientCodec {
}
}

#[cfg(feature = "server")]
#[cfg(feature = "tcp-server")]
#[derive(Debug, Default)]
pub(crate) struct ServerCodec {
pub(crate) decoder: AduDecoder,
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -139,7 +139,7 @@ impl<'a> Encoder<RequestAdu<'a>> for ClientCodec {
}
}

#[cfg(feature = "server")]
#[cfg(feature = "tcp-server")]
impl Encoder<ResponseAdu> for ServerCodec {
type Error = Error;

Expand Down

0 comments on commit 1e93356

Please sign in to comment.