diff options
Diffstat (limited to '')
| -rw-r--r-- | src/message/handshake/clientlogin.rs | 26 |
1 files changed, 7 insertions, 19 deletions
diff --git a/src/message/handshake/clientlogin.rs b/src/message/handshake/clientlogin.rs index 769245b..dffd996 100644 --- a/src/message/handshake/clientlogin.rs +++ b/src/message/handshake/clientlogin.rs @@ -1,12 +1,11 @@ -use crate::error::ProtocolError; use crate::primitive::{Variant, VariantMap}; -use crate::{HandshakeDeserialize, HandshakeSerialize}; +use crate::HandshakeSerialize; use failure::Error; /// Login to the core with user data /// username and password are transmitted in plain text -#[derive(Debug)] +#[derive(Debug, Clone)] pub struct ClientLogin { pub user: String, pub password: String, @@ -28,22 +27,11 @@ impl HandshakeSerialize for ClientLogin { } } -impl HandshakeDeserialize for ClientLogin { - 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 == "ClientLogin" { - return Ok(( - len, - Self { - user: match_variant!(values["User"], Variant::String), - password: match_variant!(values["Password"], Variant::String), - }, - )); - } else { - bail!(ProtocolError::WrongMsgType); +impl From<VariantMap> for ClientLogin { + fn from(input: VariantMap) -> Self { + ClientLogin { + user: match_variant!(input.get("User").unwrap(), Variant::String), + password: match_variant!(input.get("Password").unwrap(), Variant::String), } } } |
