Skip to main content

steamkit/base/gc/
msg_base_gc.rs

1//! The common interface and base type of game coordinator messages.
2
3use crate::base::msg_base::MsgBase;
4use crate::error::SteamError;
5use crate::types::job_id::JobID;
6
7/// A unified interface into game coordinator messages.
8pub trait IClientGCMsg: Send + Sync {
9    /// Whether this game coordinator message is protobuf backed.
10    fn is_proto(&self) -> bool;
11
12    /// The network message type of this game coordinator message.
13    fn msg_type(&self) -> u32;
14
15    /// The target job id of this game coordinator message.
16    fn target_job_id(&self) -> JobID;
17
18    /// Sets the target job id of this game coordinator message.
19    fn set_target_job_id(&mut self, id: JobID);
20
21    /// The source job id of this game coordinator message.
22    fn source_job_id(&self) -> JobID;
23
24    /// Sets the source job id of this game coordinator message.
25    fn set_source_job_id(&mut self, id: JobID);
26
27    /// Serializes this message.
28    fn serialize(&self) -> Vec<u8>;
29
30    /// Fills this message in from serialized `data`.
31    fn deserialize(&mut self, data: &[u8]) -> Result<(), SteamError>;
32}
33
34/// Header plus payload buffer, shared by all game coordinator messages.
35pub struct GCMsgBase<THeader> {
36    /// The header of this message.
37    pub header: THeader,
38    /// The payload buffer of this message.
39    pub payload: MsgBase,
40}
41
42impl<THeader> GCMsgBase<THeader> {
43    /// Creates a game coordinator message base with the given header.
44    pub fn new(header: THeader, payload_reserve: usize) -> Self {
45        GCMsgBase {
46            header,
47            payload: MsgBase::new(payload_reserve),
48        }
49    }
50}