Trait bip_peer::PeerProtocol
[−]
[src]
pub trait PeerProtocol { type ProtocolMessage; fn bytes_needed(&mut self, bytes: &[u8]) -> Result<Option<usize>>; fn parse_bytes(&mut self, bytes: Bytes) -> Result<Self::ProtocolMessage>; fn write_bytes<W>(
&mut self,
message: &Self::ProtocolMessage,
writer: W
) -> Result<()>
where
W: Write; fn message_size(&mut self, message: &Self::ProtocolMessage) -> usize; }
Trait for implementing a bittorrent protocol message.
Associated Types
type ProtocolMessage
Type of message the protocol operates with.
Required Methods
fn bytes_needed(&mut self, bytes: &[u8]) -> Result<Option<usize>>
Total number of bytes needed to parse a complete message. This is not in addition to what we were given, this is the total number of bytes, so if the given bytes has length >= needed, then we can parse it.
If none is returned, it means we need more bytes to determine the number of bytes needed. If an error is returned, it means the connection should be dropped, as probably the message exceeded some maximum length.
fn parse_bytes(&mut self, bytes: Bytes) -> Result<Self::ProtocolMessage>
Parse a ProtocolMessage
from the given bytes.
fn write_bytes<W>(
&mut self,
message: &Self::ProtocolMessage,
writer: W
) -> Result<()> where
W: Write,
&mut self,
message: &Self::ProtocolMessage,
writer: W
) -> Result<()> where
W: Write,
Write a ProtocolMessage
to the given writer.
fn message_size(&mut self, message: &Self::ProtocolMessage) -> usize
Retrieve how many bytes the message will occupy on the wire.
Implementors
impl PeerProtocol for UnitProtocol
impl PeerProtocol for NullProtocol
impl<P> PeerProtocol for PeerWireProtocol<P> where
P: PeerProtocol,