use std::io::{self, Write};
use message::NullProtocolMessage;
use protocol::{PeerProtocol, NestedPeerProtocol};
use bytes::Bytes;
pub struct NullProtocol;
impl NullProtocol {
pub fn new() -> NullProtocol {
NullProtocol
}
}
impl PeerProtocol for NullProtocol {
type ProtocolMessage = NullProtocolMessage;
fn bytes_needed(&mut self, _bytes: &[u8]) -> io::Result<Option<usize>> {
Ok(Some(0))
}
fn parse_bytes(&mut self, _bytes: Bytes) -> io::Result<Self::ProtocolMessage> {
Err(io::Error::new(io::ErrorKind::Other, "Attempted To Parse Bytes As Null Protocol"))
}
fn write_bytes<W>(&mut self, _message: &Self::ProtocolMessage, _writer: W) -> io::Result<()>
where W: Write {
panic!("bip_peer: NullProtocol::write_bytes Was Called...Wait, How Did You Construct An Instance Of NullProtocolMessage? :)")
}
fn message_size(&mut self, _message: &Self::ProtocolMessage) -> usize {
0
}
}
impl<M> NestedPeerProtocol<M> for NullProtocol {
fn received_message(&mut self, _message: &M) { }
fn sent_message(&mut self, _message: &M) { }
}