diff options
| author | Max Audron <audron@cocaine.farm> | 2021-01-04 18:38:31 +0100 |
|---|---|---|
| committer | Max Audron <audron@cocaine.farm> | 2021-01-04 18:38:31 +0100 |
| commit | 0b7c6cf0b129799110d3ef0118e1f2b5697a2068 (patch) | |
| tree | 9bbb49c7af7feb6fc1aff497e0d577fe31ef11ed /src/message/handshake/clientinitreject.rs | |
| parent | WIP: function api (diff) | |
| parent | add example program: quasselproxy (diff) | |
Merge branch 'client'
Diffstat (limited to 'src/message/handshake/clientinitreject.rs')
| -rw-r--r-- | src/message/handshake/clientinitreject.rs | 28 |
1 files changed, 8 insertions, 20 deletions
diff --git a/src/message/handshake/clientinitreject.rs b/src/message/handshake/clientinitreject.rs index 06960b7..d93413d 100644 --- a/src/message/handshake/clientinitreject.rs +++ b/src/message/handshake/clientinitreject.rs @@ -1,14 +1,13 @@ -use crate::error::ProtocolError; use crate::primitive::{Variant, VariantMap}; -use crate::{HandshakeDeserialize, HandshakeSerialize}; +use crate::HandshakeSerialize; use failure::Error; /// ClientInitReject is received when the initialization fails -#[derive(Debug)] +#[derive(Debug, Clone)] pub struct ClientInitReject { /// String with an error message of what went wrong - pub error_string: String, + pub error: String, } impl HandshakeSerialize for ClientInitReject { @@ -20,27 +19,16 @@ impl HandshakeSerialize for ClientInitReject { ); values.insert( "ErrorString".to_string(), - Variant::String(self.error_string.clone()), + Variant::String(self.error.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); +impl From<VariantMap> for ClientInitReject { + fn from(input: VariantMap) -> Self { + ClientInitReject { + error: match_variant!(input.get("ErrorString").unwrap(), Variant::String), } } } |
