36 lines
952 B
Rust
36 lines
952 B
Rust
use crate::payload::{Decode, Encode, SeStringChunkKind};
|
|
use std::io::{Read, Seek};
|
|
use crate::Payload;
|
|
|
|
#[derive(Debug, Clone, PartialEq)]
|
|
pub struct UiForegroundPayload(pub u32);
|
|
|
|
impl From<u32> for UiForegroundPayload {
|
|
fn from(colour: u32) -> Self {
|
|
Self(colour)
|
|
}
|
|
}
|
|
|
|
impl Decode for UiForegroundPayload {
|
|
fn decode<R: Read + Seek>(reader: R, _chunk_len: usize) -> Result<Self, crate::Error> {
|
|
let colour = Self::read_integer(reader)?;
|
|
Ok(Self(colour))
|
|
}
|
|
}
|
|
|
|
impl Encode for UiForegroundPayload {
|
|
fn encode(&self) -> Vec<u8> {
|
|
use std::iter::once;
|
|
|
|
let colour = Self::make_integer(self.0);
|
|
let chunk_len = colour.len() + 1;
|
|
|
|
once(Payload::START_BYTE)
|
|
.chain(once(SeStringChunkKind::UiForeground.as_u8()))
|
|
.chain(once(chunk_len as u8))
|
|
.chain(colour.into_iter())
|
|
.chain(once(Payload::END_BYTE))
|
|
.collect()
|
|
}
|
|
}
|