diff options
Diffstat (limited to 'src/message/signalproxy/rpccall.rs')
| -rw-r--r-- | src/message/signalproxy/rpccall.rs | 59 |
1 files changed, 59 insertions, 0 deletions
diff --git a/src/message/signalproxy/rpccall.rs b/src/message/signalproxy/rpccall.rs new file mode 100644 index 0000000..2eac86d --- /dev/null +++ b/src/message/signalproxy/rpccall.rs @@ -0,0 +1,59 @@ +use crate::message::MessageType; +use crate::primitive::Message; +use crate::primitive::{Variant, VariantList}; +use crate::{Deserialize, Serialize}; + +#[derive(Clone, Debug, std::cmp::PartialEq)] +pub enum RpcCall { + DisplayMessage(DisplayMessage), +} + +#[derive(Clone, Debug, std::cmp::PartialEq)] +pub struct DisplayMessage { + pub message: Message, +} + +// #[derive(Clone, Debug, std::cmp::PartialEq)] +// pub struct RpcCall { +// pub slot_name: String, +// pub params: VariantList, +// } + +impl Serialize for RpcCall { + fn serialize(&self) -> Result<Vec<std::primitive::u8>, failure::Error> { + let mut res = VariantList::new(); + + res.push(Variant::i32(MessageType::RpcCall as i32)); + + match self { + RpcCall::DisplayMessage(msg) => { + res.push(Variant::StringUTF8("2displayMsg(Message)".to_string())); + res.push(Variant::Message(msg.message.clone())); + } + } + + res.serialize() + } +} + +impl Deserialize for RpcCall { + fn parse(b: &[std::primitive::u8]) -> Result<(std::primitive::usize, Self), failure::Error> { + let (size, mut res) = VariantList::parse(&b)?; + + res.remove(0); + + let rpc = match_variant!(res.remove(0), Variant::StringUTF8); + + match rpc.as_str() { + "2displayMsg(Message)" => { + return Ok(( + size, + RpcCall::DisplayMessage(DisplayMessage { + message: match_variant!(res.remove(0), Variant::Message), + }), + )) + } + _ => unimplemented!(), + } + } +} |
