reth_ress_protocol/
types.rs
1use alloy_primitives::bytes::{Buf, BufMut};
2use alloy_rlp::{Decodable, Encodable};
3
4#[repr(u8)]
6#[derive(PartialEq, Eq, Copy, Clone, Debug)]
7#[cfg_attr(any(test, feature = "arbitrary"), derive(arbitrary::Arbitrary))]
8pub enum NodeType {
9 Stateless = 0x00,
11 Stateful,
13}
14
15impl Encodable for NodeType {
16 fn encode(&self, out: &mut dyn BufMut) {
17 out.put_u8(*self as u8);
18 }
19
20 fn length(&self) -> usize {
21 1
22 }
23}
24
25impl Decodable for NodeType {
26 fn decode(buf: &mut &[u8]) -> alloy_rlp::Result<Self> {
27 let id = match buf.first().ok_or(alloy_rlp::Error::InputTooShort)? {
28 0x00 => Self::Stateless,
29 0x01 => Self::Stateful,
30 _ => return Err(alloy_rlp::Error::Custom("Invalid message type")),
31 };
32 buf.advance(1);
33 Ok(id)
34 }
35}
36
37impl NodeType {
38 pub const fn is_stateful(&self) -> bool {
40 matches!(self, Self::Stateful)
41 }
42
43 pub const fn is_valid_connection(&self, other: &Self) -> bool {
52 !self.is_stateful() || !other.is_stateful()
53 }
54}