(
src: &mut (impl AsyncRead + Unpin),
)
| 5 | }; |
| 6 | |
| 7 | pub async fn read_message<T: DeserializeOwned>( |
| 8 | src: &mut (impl AsyncRead + Unpin), |
| 9 | ) -> std::io::Result<T> { |
| 10 | let len = src.read_u32().await?; |
| 11 | |
| 12 | let mut payload_buf = vec![0; len as usize]; |
| 13 | src.read_exact(&mut payload_buf).await?; |
| 14 | |
| 15 | // Uncomment the below to debug the output |
| 16 | // let s = String::from_utf8_lossy(&payload_buf); |
| 17 | // dbg!(s); |
| 18 | |
| 19 | let decoded = serde_json::from_slice(&payload_buf)?; |
| 20 | Ok(decoded) |
| 21 | } |
| 22 | |
| 23 | pub async fn write_message<T: Serialize>( |
| 24 | msg: &T, |
no outgoing calls
no test coverage detected