Skip to main content

rust_ethernet_ip_protocol/
lib.rs

1use bytes::{Buf, BytesMut};
2
3pub mod cip;
4pub mod encap;
5pub mod values;
6
7#[derive(Debug, Clone, PartialEq, Eq)]
8pub struct ProtocolError {
9    message: String,
10}
11
12impl ProtocolError {
13    #[must_use]
14    pub fn new(message: impl Into<String>) -> Self {
15        Self {
16            message: message.into(),
17        }
18    }
19}
20
21impl std::fmt::Display for ProtocolError {
22    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
23        write!(f, "{}", self.message)
24    }
25}
26
27impl std::error::Error for ProtocolError {}
28
29pub type Result<T> = std::result::Result<T, ProtocolError>;
30
31pub trait Encode {
32    fn encode(&self, buf: &mut BytesMut);
33}
34
35pub trait Decode: Sized {
36    fn decode(buf: &mut impl Buf) -> Result<Self>;
37}
38
39#[cfg(test)]
40mod tests;