diff options
| author | Max Audron <audron@cocaine.farm> | 2020-09-26 12:01:27 +0200 |
|---|---|---|
| committer | Max Audron <audron@cocaine.farm> | 2020-09-26 12:03:01 +0200 |
| commit | 3bdae21716d10032f70a0a889070766bbbe4d141 (patch) | |
| tree | 78a1ddf98601fbbc03a9375626dfa7923ab85521 /src/message/handshake/clientinitreject.rs | |
| parent | add parsing of signalproxy messages (diff) | |
split handshake.rs
Diffstat (limited to 'src/message/handshake/clientinitreject.rs')
| -rw-r--r-- | src/message/handshake/clientinitreject.rs | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/src/message/handshake/clientinitreject.rs b/src/message/handshake/clientinitreject.rs new file mode 100644 index 0000000..06960b7 --- /dev/null +++ b/src/message/handshake/clientinitreject.rs @@ -0,0 +1,46 @@ +use crate::error::ProtocolError; +use crate::primitive::{Variant, VariantMap}; +use crate::{HandshakeDeserialize, HandshakeSerialize}; + +use failure::Error; + +/// ClientInitReject is received when the initialization fails +#[derive(Debug)] +pub struct ClientInitReject { + /// String with an error message of what went wrong + pub error_string: String, +} + +impl HandshakeSerialize for ClientInitReject { + fn serialize(&self) -> Result<Vec<u8>, Error> { + let mut values: VariantMap = VariantMap::with_capacity(2); + values.insert( + "MsgType".to_string(), + Variant::String("ClientInitReject".to_string()), + ); + values.insert( + "ErrorString".to_string(), + Variant::String(self.error_string.clone()), + ); + return HandshakeSerialize::serialize(&values); + } +} + +impl HandshakeDeserialize for ClientInitReject { + fn parse(b: &[u8]) -> Result<(usize, Self), Error> { + let (len, values): (usize, VariantMap) = HandshakeDeserialize::parse(b)?; + + let msgtype = match_variant!(&values["MsgType"], Variant::StringUTF8); + + if msgtype == "ClientInitReject" { + return Ok(( + len, + Self { + error_string: match_variant!(values["ErrorString"], Variant::String), + }, + )); + } else { + bail!(ProtocolError::WrongMsgType); + } + } +} |
