Serve command #27

Merged
Dreaded_X merged 20 commits from feature/tftp_side into main 2026-10-21 05:15:47 +00:00
Showing only changes of commit cc84f13ed7 - Show all commits
+6 -4
View File
@@ -310,8 +310,8 @@ impl Packet {
} }
pub async fn recv_from(socket: &UdpSocket) -> Result<(Self, SocketAddr), Error> { pub async fn recv_from(socket: &UdpSocket) -> Result<(Self, SocketAddr), Error> {
let mut buf = Vec::with_capacity(PACKET_SIZE); let mut buf = [0u8; PACKET_SIZE];
let (_, src) = socket.recv_buf_from(&mut buf).await?; let (_, src) = socket.recv_from(&mut buf).await?;
let packet = buf.try_into()?; let packet = buf.try_into()?;
@@ -342,10 +342,12 @@ impl TryFrom<&Packet> for Vec<u8> {
} }
} }
impl TryFrom<Vec<u8>> for Packet { impl TryFrom<[u8; PACKET_SIZE]> for Packet {
type Error = Error; type Error = Error;
fn try_from(buf: Vec<u8>) -> Result<Self, <Packet as TryFrom<Vec<u8>>>::Error> { fn try_from(
buf: [u8; PACKET_SIZE],
) -> Result<Self, <Packet as TryFrom<[u8; PACKET_SIZE]>>::Error> {
let mut reader = BufReader::new(Cursor::new(buf)); let mut reader = BufReader::new(Cursor::new(buf));
Packet::decode(&mut reader) Packet::decode(&mut reader)