Write a single frame to the stream.
(
stream: &mut W,
payload: &[u8],
)
| 68 | |
| 69 | /// Write a single frame to the stream. |
| 70 | pub async fn write_frame<W: AsyncWrite + Unpin>( |
| 71 | stream: &mut W, |
| 72 | payload: &[u8], |
| 73 | ) -> crate::Result<()> { |
| 74 | let len = payload.len() as u32; |
| 75 | stream |
| 76 | .write_all(&len.to_be_bytes()) |
| 77 | .await |
| 78 | .map_err(crate::Error::Io)?; |
| 79 | stream.write_all(payload).await.map_err(crate::Error::Io)?; |
| 80 | stream.flush().await.map_err(crate::Error::Io)?; |
| 81 | Ok(()) |
| 82 | } |
| 83 | |
| 84 | /// Decode a request payload according to the detected format. |
| 85 | pub fn decode_request(payload: &[u8], format: FrameFormat) -> crate::Result<NativeRequest> { |
no test coverage detected