pub fn read_msg<T>(conn: TcpStream) -> Box<Future<Item = (TcpStream, T), Error = Error>>
where
	T: Readable + 'static,
{
	let read_header = read_exact(conn, vec![0u8; HEADER_LEN as usize])
		.from_err()
		.and_then(|(reader, buf)| {
			let header = try!(ser::deserialize::<MsgHeader>(&mut &buf[..]));
			if header.msg_len > MAX_MSG_LEN {
				// TODO add additional restrictions on a per-message-type basis to avoid 20MB
	// pings
				return Err(Error::Serialization(ser::Error::TooLargeReadErr));
			}
			Ok((reader, header))
		});

	let read_msg = read_header
		.and_then(|(reader, header)| {
			read_exact(reader, vec![0u8; header.msg_len as usize]).from_err()
		})
		.and_then(|(reader, buf)| {
			let body = try!(ser::deserialize(&mut &buf[..]));
			Ok((reader, body))
		});
	Box::new(read_msg)
}
/// Future combinator to read any message where the body is a Readable. Reads
/// the  header first, handles its validation and then reads the Readable body,
/// allocating buffers of the right size.
Future combinator to read any message where the body is a Readable. Reads
the  header first, handles its validation and then reads the Readable body,
allocating buffers of the right size.
Future combinator to read any message where the body is a Readable . Reads the header first handles its validation and then reads the Readable body allocating buffers of the right size .
pub fn read_msg<T>(conn: TcpStream) -> Box<Future<Item = (TcpStream, T), Error = Error>>
where
	T: Readable + 'static,
{
	let read_header = read_exact(conn, vec![0u8; HEADER_LEN as usize])
		.from_err()
		.and_then(|(reader, buf)| {
			let header = try!(ser::deserialize::<MsgHeader>(&mut &buf[..]));
			if header.msg_len > MAX_MSG_LEN {
				// TODO add additional restrictions on a per-message-type basis to avoid 20MB
	// pings
				return Err(Error::Serialization(ser::Error::TooLargeReadErr));
			}
			Ok((reader, header))
		});
	let read_msg = read_header
		.and_then(|(reader, header)| {
			read_exact(reader, vec![0u8; header.msg_len as usize]).from_err()
		})
		.and_then(|(reader, buf)| {
			let body = try!(ser::deserialize(&mut &buf[..]));
			Ok((reader, body))
		});
	Box::new(read_msg)
}
pub fn read_msg < T > ( conn : TcpStream ) -> Box < Future < Item = ( TcpStream , T ) , Error = Error > > where T : Readable + ' static , { let read_header = read_exact ( conn , vec ! [ 0u8 HEADER_LEN as usize ] ) . from_err ( ) . and_then ( | ( reader , buf ) | { let header = try ! ( ser deserialize MsgHeader ( mut buf [ ] ) ) ; if header . msg_len > MAX_MSG_LEN { // TODO add additional restrictions on a per-message-type basis to avoid 20MB // pings return Err ( Error :: Serialization ( ser :: Error :: TooLargeReadErr ) ) ; } Ok ( ( reader , header ) ) } ) ; let read_msg = read_header . and_then ( | ( reader , header ) | { read_exact ( reader , vec ! [ 0u8 header msg_len as usize ] ) . from_err ( ) } ) . and_then ( | ( reader , buf ) | { let body = try ! ( ser deserialize ( mut buf [ ] ) ) ; Ok ( ( reader , body ) ) } ) ; Box :: new ( read_msg ) }
Future combinator to read any message where the body is a Readable.
Future combinator to read any message where the body is a Readable .
conn
TcpStream