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