From 531dd956d3f528e10c086cb7dd2836c2fbfbc154 Mon Sep 17 00:00:00 2001 From: Sebastien Bourdeauducq Date: Fri, 24 Apr 2020 15:17:41 +0800 Subject: [PATCH] moninj: decode host messages --- runtime/src/moninj.rs | 21 +++++++++++++++++++++ runtime/src/proto.rs | 6 ++++++ 2 files changed, 27 insertions(+) diff --git a/runtime/src/moninj.rs b/runtime/src/moninj.rs index 6f539a9..3802e7a 100644 --- a/runtime/src/moninj.rs +++ b/runtime/src/moninj.rs @@ -59,6 +59,27 @@ async fn handle_connection(stream: &TcpStream) -> Result<()> { let message: HostMessage = FromPrimitive::from_i8(read_i8(&stream).await?) .ok_or(Error::UnrecognizedPacket)?; info!("{:?}", message); + match message { + HostMessage::MonitorProbe => { + let enable = read_bool(&stream).await?; + let channel = read_i32(&stream).await?; + let probe = read_i8(&stream).await?; + }, + HostMessage::Inject => { + let channel = read_i32(&stream).await?; + let overrd = read_i8(&stream).await?; + let value = read_i8(&stream).await?; + }, + HostMessage::GetInjectionStatus => { + let channel = read_i32(&stream).await?; + let overrd = read_i8(&stream).await?; + }, + HostMessage::MonitorInjection => { + let enable = read_bool(&stream).await?; + let channel = read_i32(&stream).await?; + let overrd = read_i8(&stream).await?; + }, + } } } diff --git a/runtime/src/proto.rs b/runtime/src/proto.rs index 3052505..f01dca2 100644 --- a/runtime/src/proto.rs +++ b/runtime/src/proto.rs @@ -22,6 +22,12 @@ pub async fn expect(stream: &TcpStream, pattern: &[u8]) -> Result { }).await? } +pub async fn read_bool(stream: &TcpStream) -> Result { + Ok(stream.recv(|buf| { + Poll::Ready((1, buf[0] != 0)) + }).await?) +} + pub async fn read_i8(stream: &TcpStream) -> Result { Ok(stream.recv(|buf| { Poll::Ready((1, buf[0] as i8))