42 lines
1.1 KiB
Rust
42 lines
1.1 KiB
Rust
|
use crate::payload::{Decode, Encode, SeStringChunkKind, SeInteractableKind};
|
||
|
use std::io::{Read, Seek};
|
||
|
use crate::Payload;
|
||
|
|
||
|
#[derive(Debug, PartialEq)]
|
||
|
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()
|
||
|
}
|
||
|
}
|