feat: add sync TFTP client/server library
This commit is contained in:
@@ -294,8 +294,15 @@ impl fmt::Display for DecodeError {
|
||||
Self::UnknownMode(mode) => write!(f, "unknown transfer mode {mode:?}"),
|
||||
Self::UnknownErrorCode(code) => write!(f, "unknown error code {code}"),
|
||||
Self::OversizeData(n) => write!(f, "DATA payload too large ({n} bytes)"),
|
||||
Self::InvalidLength { kind, expected, got } => {
|
||||
write!(f, "{kind} packet has invalid length (expected {expected}, got {got})")
|
||||
Self::InvalidLength {
|
||||
kind,
|
||||
expected,
|
||||
got,
|
||||
} => {
|
||||
write!(
|
||||
f,
|
||||
"{kind} packet has invalid length (expected {expected}, got {got})"
|
||||
)
|
||||
}
|
||||
Self::TrailingBytes => write!(f, "trailing bytes after packet"),
|
||||
}
|
||||
@@ -339,7 +346,10 @@ mod tests {
|
||||
Packet::Ack { block: 1 }.encode_into(&mut bytes);
|
||||
bytes.push(0);
|
||||
let err = Packet::decode(&bytes).unwrap_err();
|
||||
assert!(matches!(err, DecodeError::InvalidLength { kind: "ACK", .. }));
|
||||
assert!(matches!(
|
||||
err,
|
||||
DecodeError::InvalidLength { kind: "ACK", .. }
|
||||
));
|
||||
}
|
||||
|
||||
#[allow(clippy::unwrap_used)]
|
||||
|
||||
Reference in New Issue
Block a user