(reader: &mut T, hdr_len: u8)
| 422 | } |
| 423 | |
| 424 | pub async fn read<T: AsyncRead + Unpin>(reader: &mut T, hdr_len: u8) -> Result<UdpTraffic> { |
| 425 | let mut buf = vec![0; hdr_len as usize]; |
| 426 | reader |
| 427 | .read_exact(&mut buf) |
| 428 | .await |
| 429 | .with_context(|| "Failed to read udp header")?; |
| 430 | |
| 431 | let hdr: UdpHeader = bincode::serde::decode_from_slice(&buf, bincode::config::legacy()) |
| 432 | .with_context(|| "Failed to deserialize UdpHeader")? |
| 433 | .0; |
| 434 | |
| 435 | trace!("hdr {:?}", hdr); |
| 436 | |
| 437 | let mut data = BytesMut::new(); |
| 438 | data.resize(hdr.len as usize, 0); |
| 439 | reader.read_exact(&mut data).await?; |
| 440 | |
| 441 | Ok(UdpTraffic { |
| 442 | from: hdr.from, |
| 443 | data: data.freeze(), |
| 444 | }) |
| 445 | } |
| 446 | } |
no outgoing calls
no test coverage detected