moninj: decode host messages

This commit is contained in:
Sebastien Bourdeauducq 2020-04-24 15:17:41 +08:00
parent b310e068d4
commit 531dd956d3
2 changed files with 27 additions and 0 deletions

View File

@ -59,6 +59,27 @@ async fn handle_connection(stream: &TcpStream) -> Result<()> {
let message: HostMessage = FromPrimitive::from_i8(read_i8(&stream).await?) let message: HostMessage = FromPrimitive::from_i8(read_i8(&stream).await?)
.ok_or(Error::UnrecognizedPacket)?; .ok_or(Error::UnrecognizedPacket)?;
info!("{:?}", message); 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?;
},
}
} }
} }

View File

@ -22,6 +22,12 @@ pub async fn expect(stream: &TcpStream, pattern: &[u8]) -> Result<bool> {
}).await? }).await?
} }
pub async fn read_bool(stream: &TcpStream) -> Result<bool> {
Ok(stream.recv(|buf| {
Poll::Ready((1, buf[0] != 0))
}).await?)
}
pub async fn read_i8(stream: &TcpStream) -> Result<i8> { pub async fn read_i8(stream: &TcpStream) -> Result<i8> {
Ok(stream.recv(|buf| { Ok(stream.recv(|buf| {
Poll::Ready((1, buf[0] as i8)) Poll::Ready((1, buf[0] as i8))