sestring/payload/
ui_glow.rs1use crate::payload::{Decode, Encode, SeStringChunkKind};
2use std::io::{Read, Seek};
3use crate::Payload;
4
5#[derive(Debug, Clone, PartialEq)]
6pub struct UiGlowPayload(pub u32);
7
8impl From<u32> for UiGlowPayload {
9 fn from(colour: u32) -> Self {
10 Self(colour)
11 }
12}
13
14impl Decode for UiGlowPayload {
15 fn decode<R: Read + Seek>(reader: R, _chunk_len: usize) -> Result<Self, crate::Error> {
16 let colour = Self::read_integer(reader)?;
17 Ok(Self(colour))
18 }
19}
20
21impl Encode for UiGlowPayload {
22 fn encode(&self) -> Vec<u8> {
23 use std::iter::once;
24
25 let colour = Self::make_integer(self.0);
26 let chunk_len = colour.len() + 1;
27
28 once(Payload::START_BYTE)
29 .chain(once(SeStringChunkKind::UiGlow.as_u8()))
30 .chain(once(chunk_len as u8))
31 .chain(colour.into_iter())
32 .chain(once(Payload::END_BYTE))
33 .collect()
34 }
35}