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