1use async_trait::async_trait;
2
3use crate::data::OpenRGBReadable;
4use crate::OpenRGBError;
5use crate::protocol::OpenRGBReadableStream;
6
7#[derive(Debug, Eq, PartialEq)]
9pub struct LED {
10 pub name: String,
12
13 pub value: u32,
15}
16
17#[async_trait]
18impl OpenRGBReadable for LED {
19 async fn read(stream: &mut impl OpenRGBReadableStream, protocol: u32) -> Result<Self, OpenRGBError> {
20 Ok(LED {
21 name: stream.read_value(protocol).await?,
22 value: stream.read_value(protocol).await?,
23 })
24 }
25}
26
27#[cfg(test)]
28mod tests {
29 use std::error::Error;
30
31 use tokio_test::io::Builder;
32
33 use crate::data::LED;
34 use crate::DEFAULT_PROTOCOL;
35 use crate::protocol::OpenRGBReadableStream;
36 use crate::tests::setup;
37
38 #[tokio::test]
39 async fn test_read_001() -> Result<(), Box<dyn Error>> {
40 setup()?;
41
42 let mut stream = Builder::new()
43 .read(&5_u16.to_le_bytes())
44 .read(b"test\0")
45 .read(&45_u32.to_le_bytes())
46 .build();
47
48 assert_eq!(stream.read_value::<LED>(DEFAULT_PROTOCOL).await?, LED { name: "test".to_string(), value: 45 });
49
50 Ok(())
51 }
52}