reth_eth_wire/
protocol.rs1use crate::{Capability, EthMessageID, EthVersion};
4
5#[derive(Clone, Debug, PartialEq, Eq, Hash)]
10#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
11pub struct Protocol {
12 pub cap: Capability,
14 messages: u8,
18}
19
20impl Protocol {
21 pub const fn new(cap: Capability, messages: u8) -> Self {
23 Self { cap, messages }
24 }
25
26 pub const fn eth(version: EthVersion) -> Self {
28 let cap = Capability::eth(version);
29 let messages = EthMessageID::message_count(version);
30 Self::new(cap, messages)
31 }
32
33 pub const fn eth_66() -> Self {
35 Self::eth(EthVersion::Eth66)
36 }
37
38 pub const fn eth_67() -> Self {
40 Self::eth(EthVersion::Eth67)
41 }
42
43 pub const fn eth_68() -> Self {
45 Self::eth(EthVersion::Eth68)
46 }
47
48 #[inline]
50 pub(crate) fn split(self) -> (Capability, u8) {
51 (self.cap, self.messages)
52 }
53
54 pub const fn messages(&self) -> u8 {
56 self.messages
57 }
58}
59
60impl From<EthVersion> for Protocol {
61 fn from(version: EthVersion) -> Self {
62 Self::eth(version)
63 }
64}
65
66#[derive(Clone, Debug, PartialEq, Eq, Hash)]
68pub(crate) struct ProtoVersion {
69 pub(crate) messages: u8,
71 pub(crate) version: usize,
73}
74
75#[cfg(test)]
76mod tests {
77 use super::*;
78
79 #[test]
80 fn test_protocol_eth_message_count() {
81 assert_eq!(Protocol::eth(EthVersion::Eth66).messages(), 17);
84 assert_eq!(Protocol::eth(EthVersion::Eth67).messages(), 17);
85 assert_eq!(Protocol::eth(EthVersion::Eth68).messages(), 17);
86 assert_eq!(Protocol::eth(EthVersion::Eth69).messages(), 18);
87 }
88}