bt-bass: Standardize error type for RemoteScanStoppedOperation decode Align RemoteScanStoppedOperation::decode to return `UnexpectedDataLength` instead of `BufferTooSmall` when the buffer is malformed. The former is used for these situations, and the latter is used for encoding errors due to truncated input buffers. Bug: 539983871 Test: cargo test Change-Id: I94e20bdced0ed8a0dd9540e587dc3d7f695094df Reviewed-on: https://bluetooth-review.googlesource.com/c/bluetooth/+/3320
diff --git a/rust/bt-bass/src/types.rs b/rust/bt-bass/src/types.rs index a3d1222..b881328 100644 --- a/rust/bt-bass/src/types.rs +++ b/rust/bt-bass/src/types.rs
@@ -87,7 +87,7 @@ fn decode(buf: &[u8]) -> (core::result::Result<Self, Self::Error>, usize) { const BYTE_SIZE: usize = ControlPointOpcode::BYTE_SIZE; if buf.len() < BYTE_SIZE { - return (Err(PacketError::BufferTooSmall), buf.len()); + return (Err(PacketError::UnexpectedDataLength), buf.len()); } (Self::check_opcode(buf[0]).map(|_| RemoteScanStoppedOperation), BYTE_SIZE) } @@ -1148,6 +1148,10 @@ let (decoded, len) = RemoteScanStoppedOperation::decode(&bytes); assert_eq!(decoded, Ok(stopped)); assert_eq!(len, 1); + assert_eq!( + RemoteScanStoppedOperation::decode(&[]).0, + Err(PacketError::UnexpectedDataLength) + ); } #[test]