pub fn decode_response_notification(
bytes: &[u8],
) -> Result<BoardEvent, DecodeResponseNotificationError>Expand description
Decodes a battery or tracked-piece response notification.
The notification type byte determines whether the returned event is
BoardEvent::BatteryStatus or BoardEvent::PieceStatus.
§Examples
use chessnut_move::protocol::{
BatteryStatus, BoardEvent, decode_response_notification,
};
let event = decode_response_notification(&[0x41, 0x03, 0x0c, 0x01, 72])?;
assert_eq!(
event,
BoardEvent::BatteryStatus(BatteryStatus {
charging: true,
percentage: 72,
}),
);§Errors
Returns DecodeResponseNotificationError::NotificationTooShort for a
truncated frame, DecodeResponseNotificationError::InvalidNotificationHeader
for invalid header bytes, or
DecodeResponseNotificationError::UnexpectedNotification for an
unsupported response type.
Battery and piece payload validation errors are
returned through DecodeResponseNotificationError::BatteryStatus and
DecodeResponseNotificationError::PieceStatus.