diff options
author | yuzu <yuzu@b9215c17-b818-4693-b096-d1e41a411fef> | 2025-08-01 08:48:17 +0000 |
---|---|---|
committer | yuzu <yuzu@b9215c17-b818-4693-b096-d1e41a411fef> | 2025-08-01 08:48:17 +0000 |
commit | 2df86268298de8a4961c3296c19b0767565453e8 (patch) | |
tree | 1f048c96efaeb0959e04ad4273a149a108491361 /src/protocol.rs | |
parent | 40a65f981a664a186a52fc2981b99a6d8a1191d4 (diff) | |
download | salaryman-canon.tar.gz salaryman-canon.tar.bz2 salaryman-canon.zip |
git-svn-id: svn+ssh://diminuette.aengel.lesbianunix.dev/salaryman/trunk@17 b9215c17-b818-4693-b096-d1e41a411fef
Diffstat (limited to 'src/protocol.rs')
-rw-r--r-- | src/protocol.rs | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/src/protocol.rs b/src/protocol.rs new file mode 100644 index 0000000..a252b9a --- /dev/null +++ b/src/protocol.rs @@ -0,0 +1,42 @@ +use serde::{Serialize, Deserialize}; +use uuid::Uuid; +use super::service::ServiceConf; + +#[derive(Serialize, Deserialize)] +pub enum SalarymanPacket { + Ping, + Pong, + Okay, + Create(ServiceConf), + Delete(Uuid), + Start(Uuid), + Stop(Uuid), + Restart(Uuid), + + Quit, + Invalid, +} +impl SalarymanPacket { + /// Used to encode the enum and any nested structs for network transmission + pub fn serialize(&self) -> Result<Vec<u8>, bincode::error::EncodeError>{ + bincode::serde::encode_to_vec(&self, bincode::config::standard()) + } + /// Used to decode the enum and any nested struct from a network transmission + pub fn deserialize(data: &[u8]) -> Result<SalarymanPacket, bincode::error::DecodeError> { + let (ret, _size) = bincode::serde::decode_from_slice(data, bincode::config::standard())?; + Ok(ret) + } + /// Generates a response from a given SalarymanPacket invariant + pub fn response(&self) -> Self { + match self { + Self::Ping => Self::Pong, + Self::Create(_) => Self::Okay, + Self::Delete(_) => Self::Okay, + Self::Start(_) => Self::Okay, + Self::Stop(_) => Self::Okay, + Self::Restart(_) => Self::Okay, + Self::Quit => Self::Okay, + _ => Self::Invalid, + } + } +} |