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 of message the protocol operates with.

Required Methods

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.

Parse a ProtocolMessage from the given bytes.

Write a ProtocolMessage to the given writer.

Retrieve how many bytes the message will occupy on the wire.

Implementors