2021-10-03 19:52:21 +00:00
|
|
|
use crate::payload::{Decode, Encode, SeStringChunkKind, SeInteractableKind};
|
|
|
|
use std::io::{Read, Seek};
|
|
|
|
use crate::Payload;
|
|
|
|
|
2021-10-10 23:39:39 +00:00
|
|
|
#[derive(Debug, Clone, PartialEq)]
|
2021-10-03 19:52:21 +00:00
|
|
|
pub struct StatusPayload(pub u32);
|
|
|
|
|
|
|
|
impl From<u32> for StatusPayload {
|
|
|
|
fn from(id: u32) -> Self {
|
|
|
|
Self(id)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl Decode for StatusPayload {
|
|
|
|
fn decode<R: Read + Seek>(reader: R, _chunk_len: usize) -> Result<Self, crate::Error> {
|
|
|
|
let id = Self::read_integer(reader)?;
|
|
|
|
Ok(Self(id))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl Encode for StatusPayload {
|
|
|
|
fn encode(&self) -> Vec<u8> {
|
|
|
|
use std::iter::once;
|
|
|
|
|
|
|
|
let id = Self::make_integer(self.0);
|
|
|
|
let chunk_len = id.len() + 7;
|
|
|
|
|
|
|
|
once(Payload::START_BYTE)
|
|
|
|
.chain(once(SeStringChunkKind::Interactable.as_u8()))
|
|
|
|
.chain(once(chunk_len as u8))
|
|
|
|
.chain(once(SeInteractableKind::Status.as_u8()))
|
|
|
|
.chain(id.into_iter())
|
|
|
|
.chain(once(0x01))
|
|
|
|
.chain(once(0x01))
|
|
|
|
.chain(once(0xFF))
|
|
|
|
.chain(once(0x02))
|
|
|
|
.chain(once(0x20))
|
|
|
|
.chain(once(Payload::END_BYTE))
|
|
|
|
.collect()
|
|
|
|
}
|
|
|
|
}
|