aboutsummaryrefslogtreecommitdiff
path: root/src/message/handshake
diff options
context:
space:
mode:
Diffstat (limited to 'src/message/handshake')
-rw-r--r--src/message/handshake/clientinit.rs10
-rw-r--r--src/message/handshake/clientinitack.rs8
-rw-r--r--src/message/handshake/clientinitreject.rs4
-rw-r--r--src/message/handshake/clientlogin.rs6
-rw-r--r--src/message/handshake/clientloginack.rs4
-rw-r--r--src/message/handshake/clientloginreject.rs6
-rw-r--r--src/message/handshake/mod.rs4
-rw-r--r--src/message/handshake/sessioninit.rs20
8 files changed, 31 insertions, 31 deletions
diff --git a/src/message/handshake/clientinit.rs b/src/message/handshake/clientinit.rs
index 32e8595..94d52cf 100644
--- a/src/message/handshake/clientinit.rs
+++ b/src/message/handshake/clientinit.rs
@@ -64,12 +64,12 @@ impl HandshakeSerialize for ClientInit {
}
impl From<VariantMap> for ClientInit {
- fn from(input: VariantMap) -> Self {
+ fn from(mut input: VariantMap) -> Self {
ClientInit {
- client_version: match_variant!(input.get("ClientVersion").unwrap(), Variant::String),
- client_date: match_variant!(input.get("ClientDate").unwrap(), Variant::String),
- client_features: match_variant!(input.get("Features").unwrap(), Variant::u32),
- feature_list: match_variant!(input.get("FeatureList").unwrap(), Variant::StringList),
+ client_version: input.remove("ClientVersion").unwrap().try_into().unwrap(),
+ client_date: input.remove("ClientDate").unwrap().try_into().unwrap(),
+ client_features: input.remove("Features").unwrap().try_into().unwrap(),
+ feature_list: input.remove("FeatureList").unwrap().try_into().unwrap(),
}
}
}
diff --git a/src/message/handshake/clientinitack.rs b/src/message/handshake/clientinitack.rs
index 610cdc0..21e65de 100644
--- a/src/message/handshake/clientinitack.rs
+++ b/src/message/handshake/clientinitack.rs
@@ -50,11 +50,11 @@ impl From<VariantMap> for ClientInitAck {
ClientInitAck {
// TODO make this compatible with older clients
core_features: 0,
- core_configured: match_variant!(input.get("Configured").unwrap(), Variant::bool),
- storage_backends: match_variant!(input.get("StorageBackends").unwrap(), Variant::VariantList),
+ core_configured: input.get("Configured").unwrap().try_into().unwrap(),
+ storage_backends: input.get("StorageBackends").unwrap().try_into().unwrap(),
#[cfg(feature = "authenticators")]
- authenticators: match_variant!(input.get("Authenticators").unwrap(), Variant::VariantList),
- feature_list: match_variant!(input.get("FeatureList").unwrap(), Variant::StringList),
+ authenticators: input.get("Authenticators").unwrap().try_into().unwrap(),
+ feature_list: input.get("FeatureList").unwrap().try_into().unwrap(),
}
}
}
diff --git a/src/message/handshake/clientinitreject.rs b/src/message/handshake/clientinitreject.rs
index 8c2fd34..7c4bb72 100644
--- a/src/message/handshake/clientinitreject.rs
+++ b/src/message/handshake/clientinitreject.rs
@@ -22,9 +22,9 @@ impl HandshakeSerialize for ClientInitReject {
}
impl From<VariantMap> for ClientInitReject {
- fn from(input: VariantMap) -> Self {
+ fn from(mut input: VariantMap) -> Self {
ClientInitReject {
- error: match_variant!(input.get("ErrorString").unwrap(), Variant::String),
+ error: input.remove("ErrorString").unwrap().try_into().unwrap(),
}
}
}
diff --git a/src/message/handshake/clientlogin.rs b/src/message/handshake/clientlogin.rs
index c589810..b619e48 100644
--- a/src/message/handshake/clientlogin.rs
+++ b/src/message/handshake/clientlogin.rs
@@ -21,10 +21,10 @@ impl HandshakeSerialize for ClientLogin {
}
impl From<VariantMap> for ClientLogin {
- fn from(input: VariantMap) -> Self {
+ fn from(mut input: VariantMap) -> Self {
ClientLogin {
- user: match_variant!(input.get("User").unwrap(), Variant::String),
- password: match_variant!(input.get("Password").unwrap(), Variant::String),
+ user: input.remove("User").unwrap().try_into().unwrap(),
+ password: input.remove("Password").unwrap().try_into().unwrap(),
}
}
}
diff --git a/src/message/handshake/clientloginack.rs b/src/message/handshake/clientloginack.rs
index c8650f9..8a12f60 100644
--- a/src/message/handshake/clientloginack.rs
+++ b/src/message/handshake/clientloginack.rs
@@ -20,9 +20,9 @@ impl HandshakeSerialize for ClientLoginAck {
impl HandshakeDeserialize for ClientLoginAck {
fn parse(b: &[u8]) -> Result<(usize, Self), ProtocolError> {
- let (len, values): (usize, VariantMap) = HandshakeDeserialize::parse(b)?;
+ let (len, mut values): (usize, VariantMap) = HandshakeDeserialize::parse(b)?;
- let msgtype = match_variant!(&values["MsgType"], Variant::ByteArray);
+ let msgtype: String = values.remove("MsgType").unwrap().try_into().unwrap();
if msgtype == "ClientLogin" {
Ok((len, Self {}))
diff --git a/src/message/handshake/clientloginreject.rs b/src/message/handshake/clientloginreject.rs
index 964ce0c..c4f09cc 100644
--- a/src/message/handshake/clientloginreject.rs
+++ b/src/message/handshake/clientloginreject.rs
@@ -17,14 +17,14 @@ impl HandshakeSerialize for ClientLoginReject {
Variant::String("ClientLoginReject".to_string()),
);
values.insert("ErrorString".to_string(), Variant::String(self.error.clone()));
- return HandshakeSerialize::serialize(&values);
+ HandshakeSerialize::serialize(&values)
}
}
impl From<VariantMap> for ClientLoginReject {
- fn from(input: VariantMap) -> Self {
+ fn from(mut input: VariantMap) -> Self {
ClientLoginReject {
- error: match_variant!(input.get("ErrorString").unwrap(), Variant::String),
+ error: input.remove("ErrorString").unwrap().try_into().unwrap(),
}
}
}
diff --git a/src/message/handshake/mod.rs b/src/message/handshake/mod.rs
index 022b71f..9bcbe6e 100644
--- a/src/message/handshake/mod.rs
+++ b/src/message/handshake/mod.rs
@@ -56,9 +56,9 @@ impl HandshakeSerialize for HandshakeMessage {
impl HandshakeDeserialize for HandshakeMessage {
fn parse(b: &[u8]) -> Result<(usize, Self), ProtocolError> {
- let (size, res) = VariantMap::parse(b)?;
+ let (size, mut res) = VariantMap::parse(b)?;
- let msgtype: String = (&res["MsgType"]).into();
+ let msgtype: String = res.remove("MsgType").unwrap().try_into().unwrap();
match msgtype.as_str() {
"ClientInit" => Ok((size, HandshakeMessage::ClientInit(res.into()))),
"ClientInitAck" => Ok((size, HandshakeMessage::ClientInitAck(res.into()))),
diff --git a/src/message/handshake/sessioninit.rs b/src/message/handshake/sessioninit.rs
index 81b72f4..e2a29ad 100644
--- a/src/message/handshake/sessioninit.rs
+++ b/src/message/handshake/sessioninit.rs
@@ -1,6 +1,6 @@
use crate::error::ProtocolError;
use crate::message::objects::Identity;
-use crate::primitive::{BufferInfo, NetworkId, Variant, VariantMap};
+use crate::primitive::{BufferInfo, NetworkId, Variant, VariantList, VariantMap};
use crate::HandshakeSerialize;
/// SessionInit is received along with ClientLoginAck to initialize that user Session
@@ -10,31 +10,31 @@ pub struct SessionInit {
/// List of all configured identities
pub identities: Vec<Identity>,
/// List of all existing buffers
- pub buffers: Vec<BufferInfo>,
+ pub buffers: Vec<BufferInfo>, // Vec<Variant::BufferInfo()>
/// Ids of all networks
pub network_ids: Vec<NetworkId>,
}
impl From<VariantMap> for SessionInit {
fn from(input: VariantMap) -> Self {
- let state: VariantMap = input.get("SessionState").unwrap().try_into().unwrap();
+ let mut state: VariantMap = input.get("SessionState").unwrap().try_into().unwrap();
log::trace!("sessionstate: {:#?}", state);
+ let identities: VariantList = state.remove("Identities").unwrap().try_into().unwrap();
+ let buffers: VariantList = state.remove("BufferInfos").unwrap().try_into().unwrap();
+ let network_ids: VariantList = state.remove("NetworkIds").unwrap().try_into().unwrap();
+
SessionInit {
- identities: std::convert::TryInto::<Vec<Variant>>::try_into(state.get("Identities").unwrap())
- .unwrap()
- .into_iter()
- .map(|x| x.try_into().unwrap())
- .collect(),
- buffers: match_variant!(state.get("BufferInfos").unwrap(), Variant::VariantList)
+ identities: identities.into_iter().map(|x| x.try_into().unwrap()).collect(),
+ buffers: buffers
.iter()
.map(|buffer| match buffer {
Variant::BufferInfo(buffer) => buffer.clone(),
_ => unimplemented!(),
})
.collect(),
- network_ids: match_variant!(state.get("NetworkIds").unwrap(), Variant::VariantList)
+ network_ids: network_ids
.iter()
.map(|network| match network {
Variant::NetworkId(network) => network.clone(),