pub fn write_msg<T>(
	conn: TcpStream,
	msg: T,
	msg_type: Type,
) -> Box<Future<Item = TcpStream, Error = Error>>
where
	T: Writeable + 'static,
{
	let write_msg = ok((conn)).and_then(move |conn| {
		// prepare the body first so we know its serialized length
		let mut body_buf = vec![];
		ser::serialize(&mut body_buf, &msg).unwrap();

		// build and serialize the header using the body size
		let mut header_buf = vec![];
		let blen = body_buf.len() as u64;
		ser::serialize(&mut header_buf, &MsgHeader::new(msg_type, blen)).unwrap();

		// send the whole thing
		write_all(conn, header_buf)
			.and_then(|(conn, _)| write_all(conn, body_buf))
			.map(|(conn, _)| conn)
			.from_err()
	});
	Box::new(write_msg)
}
/// Future combinator to write a full message from a Writeable payload.
/// Serializes the payload first and then sends the message header and that
/// payload.
Future combinator to write a full message from a Writeable payload.
Serializes the payload first and then sends the message header and that
payload.
Future combinator to write a full message from a Writeable payload . Serializes the payload first and then sends the message header and that payload .
pub fn write_msg<T>(
	conn: TcpStream,
	msg: T,
	msg_type: Type,
) -> Box<Future<Item = TcpStream, Error = Error>>
where
	T: Writeable + 'static,
{
	let write_msg = ok((conn)).and_then(move |conn| {
		// prepare the body first so we know its serialized length
		let mut body_buf = vec![];
		ser::serialize(&mut body_buf, &msg).unwrap();
		// build and serialize the header using the body size
		let mut header_buf = vec![];
		let blen = body_buf.len() as u64;
		ser::serialize(&mut header_buf, &MsgHeader::new(msg_type, blen)).unwrap();
		// send the whole thing
		write_all(conn, header_buf)
			.and_then(|(conn, _)| write_all(conn, body_buf))
			.map(|(conn, _)| conn)
			.from_err()
	});
	Box::new(write_msg)
}
pub fn write_msg < T > ( conn : TcpStream , msg : T , msg_type : Type , ) -> Box < Future < Item = TcpStream , Error = Error > > where T : Writeable + ' static , { let write_msg = ok ( ( conn ) ) . and_then ( move | conn | { // prepare the body first so we know its serialized length let mut body_buf = vec ! [ ] ; ser :: serialize ( & mut body_buf , & msg ) . unwrap ( ) ; // build and serialize the header using the body size let mut header_buf = vec ! [ ] ; let blen = body_buf . len ( ) as u64 ; ser :: serialize ( & mut header_buf , & MsgHeader :: new ( msg_type , blen ) ) . unwrap ( ) ; // send the whole thing write_all ( conn , header_buf ) . and_then ( | ( conn , _ ) | write_all ( conn , body_buf ) ) . map ( | ( conn , _ ) | conn ) . from_err ( ) } ) ; Box :: new ( write_msg ) }
Future combinator to write a full message from a Writeable payload.
Future combinator to write a full message from a Writeable payload .
conn
TcpStream
msg
T
msg_type
Type