Write a length-prefixed message to a stream.
(w: &mut W, data: &[u8])
| 67 | |
| 68 | /// Write a length-prefixed message to a stream. |
| 69 | pub async fn write_msg<W: AsyncWriteExt + Unpin>(w: &mut W, data: &[u8]) -> anyhow::Result<()> { |
| 70 | let len = (data.len() as u32).to_be_bytes(); |
| 71 | w.write_all(&len).await?; |
| 72 | w.write_all(data).await?; |
| 73 | w.flush().await?; |
| 74 | Ok(()) |
| 75 | } |
| 76 | |
| 77 | /// Read a length-prefixed message from a stream. |
| 78 | pub async fn read_msg<R: AsyncReadExt + Unpin>(r: &mut R) -> anyhow::Result<Vec<u8>> { |
no outgoing calls
no test coverage detected