use Message;
/*
/// Implements protocol handling, send and recv queues.
pub struct Protocol<'a, R: Read + 'a, W: Write + 'a> {
recv_queue: &'a mut RecvQueue<R>,
send_queue: &'a mut SendQueue<W>,
}
impl<'a, R: Read, W: Write> Protocol<'a, R, W> {
/// Creates a new instance from a given reader and writer.
pub fn new(recv_queue: &'a mut RecvQueue<R>, send_queue: &'a mut SendQueue<W>) -> Self {
assert_eq!(recv_queue.max_len(), MAX_PACKET_LEN);
Self {
recv_queue: recv_queue,
send_queue: send_queue,
}
}
/// Converts the message to sendable bytes and adds it to the sendqueue.
/// It is unspecified whether the message will be send immediately or not.
pub fn send(&mut self, msg: Message) -> io::Result<()> {
let data = msg.into_buffer();
self.send_queue.send(&data)?;
Ok(())
}
/// Try to decode one message from the recv queue.
/// Call this method whenever new data has been received.
pub fn fetch(&mut self) -> Result<Option<Message>, RPCError> {
let msg = Message::from_buffer(self.recv_queue.peek())?;
Ok(match msg {
None => None,
Some((msg, cnt)) => {
self.recv_queue.drop(cnt);
Some(msg)
}
})
}
}*/
// Future plans?
pub const MAX_PACKET_LEN: usize = 16 * 1024 * 1024; // 16 MiB
;