now_proto_pdu/system/
mod.rs

1mod shutdown;
2
3use ironrdp_core::{DecodeResult, Encode, EncodeResult, IntoOwned, ReadCursor, WriteCursor};
4pub use shutdown::{NowSystemShutdownMsg, OwnedNowSystemShutdownMsg};
5
6use crate::NowHeader;
7
8// Wrapper for the `NOW_SYSTEM_MSG_CLASS_ID` message class.
9#[derive(Debug, Clone, PartialEq, Eq)]
10pub enum NowSystemMessage<'a> {
11    Shutdown(NowSystemShutdownMsg<'a>),
12}
13
14pub type OwnedNowSystemMessage = NowSystemMessage<'static>;
15
16impl IntoOwned for NowSystemMessage<'_> {
17    type Owned = OwnedNowSystemMessage;
18
19    fn into_owned(self) -> Self::Owned {
20        match self {
21            Self::Shutdown(msg) => OwnedNowSystemMessage::Shutdown(msg.into_owned()),
22        }
23    }
24}
25
26impl<'a> NowSystemMessage<'a> {
27    const NAME: &'static str = "NOW_SYSTEM_MSG";
28
29    pub fn decode_from_body(header: NowHeader, src: &mut ReadCursor<'a>) -> DecodeResult<Self> {
30        match NowSystemMessageKind(header.kind) {
31            NowSystemMessageKind::SHUTDOWN => Ok(Self::Shutdown(NowSystemShutdownMsg::decode_from_body(header, src)?)),
32            _ => Err(unsupported_message_err!(class: header.class.0, kind: header.kind)),
33        }
34    }
35}
36
37impl Encode for NowSystemMessage<'_> {
38    fn encode(&self, dst: &mut WriteCursor<'_>) -> EncodeResult<()> {
39        match self {
40            Self::Shutdown(msg) => msg.encode(dst),
41        }
42    }
43
44    fn name(&self) -> &'static str {
45        Self::NAME
46    }
47
48    fn size(&self) -> usize {
49        match self {
50            Self::Shutdown(msg) => msg.size(),
51        }
52    }
53}
54
55/// NOW-PROTO: NOW_SYSTEM_INFO_*_ID
56#[derive(Debug, Clone, Copy, PartialEq, Eq)]
57pub struct NowSystemMessageKind(pub u8);
58
59impl NowSystemMessageKind {
60    // TODO: NOW_SYSTEM_INFO_REQ_ID/NOW_SYSTEM_INFO_RSP_ID when will be added to the protocol
61    // specification.
62
63    // /// NOW-PROTO: NOW_SYSTEM_INFO_REQ_ID
64    // pub const INFO_REQ: Self = Self(0x01);
65    // /// NOW-PROTO: NOW_SYSTEM_INFO_RSP_ID
66    // pub const INFO_RSP: Self = Self(0x02);
67    /// NOW-PROTO: NOW_SYSTEM_SHUTDOWN_ID
68    pub const SHUTDOWN: Self = Self(0x03);
69}