diff options
Diffstat (limited to 'src/message/signalproxy')
| -rw-r--r-- | src/message/signalproxy/heartbeat.rs | 4 | ||||
| -rw-r--r-- | src/message/signalproxy/initdata.rs | 4 | ||||
| -rw-r--r-- | src/message/signalproxy/initrequest.rs | 4 | ||||
| -rw-r--r-- | src/message/signalproxy/objects/chanmodes.rs | 18 | ||||
| -rw-r--r-- | src/message/signalproxy/objects/network.rs | 37 | ||||
| -rw-r--r-- | src/message/signalproxy/rpccall/bufferinfo.rs | 2 | ||||
| -rw-r--r-- | src/message/signalproxy/rpccall/client.rs | 2 | ||||
| -rw-r--r-- | src/message/signalproxy/rpccall/identity.rs | 10 | ||||
| -rw-r--r-- | src/message/signalproxy/rpccall/message.rs | 10 | ||||
| -rw-r--r-- | src/message/signalproxy/rpccall/mod.rs | 2 | ||||
| -rw-r--r-- | src/message/signalproxy/rpccall/network.rs | 10 | ||||
| -rw-r--r-- | src/message/signalproxy/rpccall/objectrenamed.rs | 6 | ||||
| -rw-r--r-- | src/message/signalproxy/rpccall/passwordchange.rs | 12 | ||||
| -rw-r--r-- | src/message/signalproxy/syncmessage.rs | 10 |
14 files changed, 69 insertions, 62 deletions
diff --git a/src/message/signalproxy/heartbeat.rs b/src/message/signalproxy/heartbeat.rs index 9c952e5..7bb5b19 100644 --- a/src/message/signalproxy/heartbeat.rs +++ b/src/message/signalproxy/heartbeat.rs @@ -28,7 +28,7 @@ impl Deserialize for HeartBeat { Ok(( size, Self { - timestamp: match_variant!(res.remove(0), Variant::DateTime), + timestamp: res.remove(0).try_into().unwrap(), }, )) } @@ -59,7 +59,7 @@ impl Deserialize for HeartBeatReply { Ok(( size, Self { - timestamp: match_variant!(res.remove(0), Variant::DateTime), + timestamp: res.remove(0).try_into().unwrap(), }, )) } diff --git a/src/message/signalproxy/initdata.rs b/src/message/signalproxy/initdata.rs index efdd8d7..f95e0b2 100644 --- a/src/message/signalproxy/initdata.rs +++ b/src/message/signalproxy/initdata.rs @@ -32,8 +32,8 @@ impl Deserialize for InitData { res.remove(0); - let class_name: String = res.remove(0).into(); - let object_name: String = res.remove(0).into(); + let class_name: String = res.remove(0).try_into().unwrap(); + let object_name: String = res.remove(0).try_into().unwrap(); Ok(( size, diff --git a/src/message/signalproxy/initrequest.rs b/src/message/signalproxy/initrequest.rs index 1990dba..bf2f200 100644 --- a/src/message/signalproxy/initrequest.rs +++ b/src/message/signalproxy/initrequest.rs @@ -30,8 +30,8 @@ impl Deserialize for InitRequest { Ok(( size, Self { - class_name: match_variant!(res.remove(0), Variant::ByteArray), - object_name: match_variant!(res.remove(0), Variant::ByteArray), + class_name: res.remove(0).try_into().unwrap(), + object_name: res.remove(0).try_into().unwrap(), }, )) } diff --git a/src/message/signalproxy/objects/chanmodes.rs b/src/message/signalproxy/objects/chanmodes.rs index 1161e28..b297126 100644 --- a/src/message/signalproxy/objects/chanmodes.rs +++ b/src/message/signalproxy/objects/chanmodes.rs @@ -62,20 +62,24 @@ impl NetworkMap for ChanModes { } fn from_network_map(input: &mut Self::Item) -> Self { + let channel_modes_a: VariantMap = input.remove("A").unwrap().try_into().unwrap(); + let channel_modes_b: VariantMap = input.remove("B").unwrap().try_into().unwrap(); + let channel_modes_c: VariantMap = input.remove("C").unwrap().try_into().unwrap(); + ChanModes { - channel_modes_a: match_variant!(input.remove("A").unwrap(), Variant::VariantMap) + channel_modes_a: channel_modes_a .into_iter() - .map(|(mut k, v)| (k.remove(0), match_variant!(v, Variant::StringList))) + .map(|(mut k, v)| (k.remove(0), v.try_into().unwrap())) .collect(), - channel_modes_b: match_variant!(input.remove("B").unwrap(), Variant::VariantMap) + channel_modes_b: channel_modes_b .into_iter() - .map(|(mut k, v)| (k.remove(0), match_variant!(v, Variant::String))) + .map(|(mut k, v)| (k.remove(0), v.try_into().unwrap())) .collect(), - channel_modes_c: match_variant!(input.remove("C").unwrap(), Variant::VariantMap) + channel_modes_c: channel_modes_c .into_iter() - .map(|(mut k, v)| (k.remove(0), match_variant!(v, Variant::String))) + .map(|(mut k, v)| (k.remove(0), v.try_into().unwrap())) .collect(), - channel_modes_d: match_variant!(input.remove("D").unwrap(), Variant::String), + channel_modes_d: input.remove("D").unwrap().try_into().unwrap(), } } } diff --git a/src/message/signalproxy/objects/network.rs b/src/message/signalproxy/objects/network.rs index 138f63f..a606537 100644 --- a/src/message/signalproxy/objects/network.rs +++ b/src/message/signalproxy/objects/network.rs @@ -346,6 +346,7 @@ impl crate::message::signalproxy::NetworkList for Network { res } + // TODO VariantList -> VariantMap conversion fn from_network_list(input: &mut VariantList) -> Self { let mut i = input.iter().cycle(); @@ -363,7 +364,7 @@ impl crate::message::signalproxy::NetworkList for Network { i.position(|x| *x == Variant::ByteArray(String::from("myNick"))) .unwrap(); - i.next().unwrap().try_into().unwrap() + i.next().unwrap().clone().try_into().unwrap() }, latency: { i.position(|x| *x == Variant::ByteArray(String::from("latency"))) @@ -375,7 +376,7 @@ impl crate::message::signalproxy::NetworkList for Network { i.position(|x| *x == Variant::ByteArray(String::from("currentServer"))) .unwrap(); - i.next().unwrap().try_into().unwrap() + i.next().unwrap().clone().try_into().unwrap() }, is_connected: { i.position(|x| *x == Variant::ByteArray(String::from("isConnected"))) @@ -529,23 +530,23 @@ impl crate::message::signalproxy::NetworkMap for Network { } fn from_network_map(input: &mut Self::Item) -> Self { - let users_and_channels: VariantMap = - { input.get("IrcUsersAndChannels").unwrap().try_into().unwrap() }; - - return Self { - my_nick: input.get("myNick").unwrap().into(), - latency: input.get("latency").unwrap().try_into().unwrap(), - current_server: input.get("currentServer").unwrap().into(), - is_connected: input.get("isConnected").unwrap().try_into().unwrap(), + let mut users_and_channels: VariantMap = + { input.remove("IrcUsersAndChannels").unwrap().try_into().unwrap() }; + + Self { + my_nick: input.remove("myNick").unwrap().try_into().unwrap(), + latency: input.remove("latency").unwrap().try_into().unwrap(), + current_server: input.remove("currentServer").unwrap().try_into().unwrap(), + is_connected: input.remove("isConnected").unwrap().try_into().unwrap(), connection_state: ConnectionState::from_i32( - input.get("connectionState").unwrap().try_into().unwrap(), + input.remove("connectionState").unwrap().try_into().unwrap(), ) .unwrap(), prefixes: Vec::new(), prefix_modes: Vec::new(), channel_modes: HashMap::with_capacity(4), irc_users: { - match users_and_channels.get("Users") { + match users_and_channels.remove("Users") { Some(users) => { let users: Vec<IrcUser> = Vec::<IrcUser>::from_network_map( &mut users.try_into().expect("failed to convert Users"), @@ -557,7 +558,7 @@ impl crate::message::signalproxy::NetworkMap for Network { } }, irc_channels: { - match users_and_channels.get("Channels") { + match users_and_channels.remove("Channels") { Some(channels) => { let channels: Vec<IrcChannel> = Vec::<IrcChannel>::from_network_map(&mut channels.try_into().unwrap()); @@ -572,20 +573,20 @@ impl crate::message::signalproxy::NetworkMap for Network { supports: VariantMap::try_from(input.get("Supports").unwrap()) .unwrap() .into_iter() - .map(|(k, v)| (k, v.into())) + .map(|(k, v)| (k, v.try_into().unwrap())) .collect(), caps: VariantMap::try_from(input.get("Caps").unwrap()) .unwrap() .into_iter() - .map(|(k, v)| (k, v.into())) + .map(|(k, v)| (k, v.try_into().unwrap())) .collect(), caps_enabled: VariantList::try_from(input.get("CapsEnabled").unwrap()) .unwrap() .into_iter() - .map(|v| v.into()) + .map(|v| v.try_into().unwrap()) .collect(), network_info: NetworkInfo::from_network_map(input), - }; + } } } @@ -627,7 +628,7 @@ impl NetworkList for Vec<NetworkServer> { } fn from_network_list(input: &mut super::VariantList) -> Self { - input.iter().map(|b| match_variant!(b, Variant::NetworkServer)).collect() + input.iter().map(|b| b.try_into().unwrap()).collect() } } diff --git a/src/message/signalproxy/rpccall/bufferinfo.rs b/src/message/signalproxy/rpccall/bufferinfo.rs index 7ba2757..cc8ad3a 100644 --- a/src/message/signalproxy/rpccall/bufferinfo.rs +++ b/src/message/signalproxy/rpccall/bufferinfo.rs @@ -28,7 +28,7 @@ impl RpcCallType for BufferInfoUpdated { Ok(( size, Self { - buffer: match_variant!(input.remove(0), Variant::BufferInfo), + buffer: input.remove(0).try_into().unwrap(), } .into(), )) diff --git a/src/message/signalproxy/rpccall/client.rs b/src/message/signalproxy/rpccall/client.rs index 5fb5326..818b32c 100644 --- a/src/message/signalproxy/rpccall/client.rs +++ b/src/message/signalproxy/rpccall/client.rs @@ -29,7 +29,7 @@ impl RpcCallType for KickClient { Ok(( size, Self { - id: match_variant!(input.remove(0), Variant::i32), + id: input.remove(0).try_into().unwrap(), } .into(), )) diff --git a/src/message/signalproxy/rpccall/identity.rs b/src/message/signalproxy/rpccall/identity.rs index 288dec5..1672e98 100644 --- a/src/message/signalproxy/rpccall/identity.rs +++ b/src/message/signalproxy/rpccall/identity.rs @@ -34,8 +34,8 @@ impl RpcCallType for CreateIdentity { Ok(( size, CreateIdentity { - identity: match_variant!(input.remove(0), Variant::Identity), - additional: match_variant!(input.remove(0), Variant::VariantMap), + identity: input.remove(0).try_into().unwrap(), + additional: input.remove(0).try_into().unwrap(), } .into(), )) @@ -68,7 +68,7 @@ impl RpcCallType for RemoveIdentity { Ok(( size, Self { - identity_id: match_variant!(input.remove(0), Variant::IdentityId), + identity_id: input.remove(0).try_into().unwrap(), } .into(), )) @@ -101,7 +101,7 @@ impl RpcCallType for IdentityCreated { Ok(( size, IdentityCreated { - identity: match_variant!(input.remove(0), Variant::Identity), + identity: input.remove(0).try_into().unwrap(), } .into(), )) @@ -134,7 +134,7 @@ impl RpcCallType for IdentityRemoved { Ok(( size, Self { - identity_id: match_variant!(input.remove(0), Variant::IdentityId), + identity_id: input.remove(0).try_into().unwrap(), } .into(), )) diff --git a/src/message/signalproxy/rpccall/message.rs b/src/message/signalproxy/rpccall/message.rs index 93888b5..bf0629a 100644 --- a/src/message/signalproxy/rpccall/message.rs +++ b/src/message/signalproxy/rpccall/message.rs @@ -29,7 +29,7 @@ impl RpcCallType for DisplayMessage { Ok(( size, RpcCall::DisplayMessage(DisplayMessage { - message: match_variant!(input.remove(0), Variant::Message), + message: input.remove(0).try_into().unwrap(), }), )) } @@ -64,8 +64,8 @@ impl RpcCallType for DisplayStatusMessage { Ok(( size, DisplayStatusMessage { - network: match_variant!(input.remove(0), Variant::String), - message: match_variant!(input.remove(0), Variant::String), + network: input.remove(0).try_into().unwrap(), + message: input.remove(0).try_into().unwrap(), } .into(), )) @@ -100,8 +100,8 @@ impl RpcCallType for SendInput { Ok(( size, Self { - buffer: match_variant!(input.remove(0), Variant::BufferInfo), - message: match_variant!(input.remove(0), Variant::String), + buffer: input.remove(0).try_into().unwrap(), + message: input.remove(0).try_into().unwrap(), } .into(), )) diff --git a/src/message/signalproxy/rpccall/mod.rs b/src/message/signalproxy/rpccall/mod.rs index 378d626..c30d462 100644 --- a/src/message/signalproxy/rpccall/mod.rs +++ b/src/message/signalproxy/rpccall/mod.rs @@ -110,7 +110,7 @@ impl Deserialize for RpcCall { res.remove(0); - let rpc = match_variant!(res.remove(0), Variant::ByteArray); + let rpc: String = res.remove(0).try_into().unwrap(); match rpc.as_str() { DisplayMessage::NAME => DisplayMessage::from_network(size, &mut res), diff --git a/src/message/signalproxy/rpccall/network.rs b/src/message/signalproxy/rpccall/network.rs index 18f9f74..aeb3f80 100644 --- a/src/message/signalproxy/rpccall/network.rs +++ b/src/message/signalproxy/rpccall/network.rs @@ -33,8 +33,8 @@ impl RpcCallType for CreateNetwork { Ok(( size, Self { - network: match_variant!(input.remove(0), Variant::NetworkInfo), - channels: match_variant!(input.remove(0), Variant::StringList), + network: input.remove(0).try_into().unwrap(), + channels: input.remove(0).try_into().unwrap(), } .into(), )) @@ -67,7 +67,7 @@ impl RpcCallType for RemoveNetwork { Ok(( size, Self { - network_id: match_variant!(input.remove(0), Variant::NetworkId), + network_id: input.remove(0).try_into().unwrap(), } .into(), )) @@ -100,7 +100,7 @@ impl RpcCallType for NetworkCreated { Ok(( size, Self { - network_id: match_variant!(input.remove(0), Variant::NetworkId), + network_id: input.remove(0).try_into().unwrap(), } .into(), )) @@ -133,7 +133,7 @@ impl RpcCallType for NetworkRemoved { Ok(( size, Self { - network_id: match_variant!(input.remove(0), Variant::NetworkId), + network_id: input.remove(0).try_into().unwrap(), } .into(), )) diff --git a/src/message/signalproxy/rpccall/objectrenamed.rs b/src/message/signalproxy/rpccall/objectrenamed.rs index d103345..1d698ef 100644 --- a/src/message/signalproxy/rpccall/objectrenamed.rs +++ b/src/message/signalproxy/rpccall/objectrenamed.rs @@ -33,9 +33,9 @@ impl RpcCallType for ObjectRenamed { Ok(( size, Self { - classname: match_variant!(input.remove(0), Variant::ByteArray), - oldname: match_variant!(input.remove(0), Variant::String), - newname: match_variant!(input.remove(0), Variant::String), + classname: input.remove(0).try_into().unwrap(), + oldname: input.remove(0).try_into().unwrap(), + newname: input.remove(0).try_into().unwrap(), } .into(), )) diff --git a/src/message/signalproxy/rpccall/passwordchange.rs b/src/message/signalproxy/rpccall/passwordchange.rs index 38bfc97..b96b926 100644 --- a/src/message/signalproxy/rpccall/passwordchange.rs +++ b/src/message/signalproxy/rpccall/passwordchange.rs @@ -38,10 +38,10 @@ impl RpcCallType for ChangePassword { Ok(( size, Self { - peer: match_variant!(input.remove(0), Variant::PeerPtr), - user: match_variant!(input.remove(0), Variant::String), - before: match_variant!(input.remove(0), Variant::String), - after: match_variant!(input.remove(0), Variant::String), + peer: input.remove(0).try_into().unwrap(), + user: input.remove(0).try_into().unwrap(), + before: input.remove(0).try_into().unwrap(), + after: input.remove(0).try_into().unwrap(), } .into(), )) @@ -79,8 +79,8 @@ impl RpcCallType for PasswordChanged { Ok(( size, Self { - peer: match_variant!(input.remove(0), Variant::PeerPtr), - success: match_variant!(input.remove(0), Variant::bool), + peer: input.remove(0).try_into().unwrap(), + success: input.remove(0).try_into().unwrap(), } .into(), )) diff --git a/src/message/signalproxy/syncmessage.rs b/src/message/signalproxy/syncmessage.rs index 94930af..bb61d7c 100644 --- a/src/message/signalproxy/syncmessage.rs +++ b/src/message/signalproxy/syncmessage.rs @@ -105,16 +105,18 @@ impl Serialize for SyncMessage { impl Deserialize for SyncMessage { fn parse(b: &[std::primitive::u8]) -> Result<(std::primitive::usize, Self), ProtocolError> { - let (size, mut res) = VariantList::parse(&b)?; + let (size, mut res) = VariantList::parse(b)?; res.remove(0); + let class_name: String = res.remove(0).try_into().unwrap(); + Ok(( size, Self { - class_name: Class::from(match_variant!(res.remove(0), Variant::ByteArray)), - object_name: match_variant!(res.remove(0), Variant::ByteArray), - slot_name: match_variant!(res.remove(0), Variant::ByteArray), + class_name: Class::from(class_name), + object_name: res.remove(0).try_into().unwrap(), + slot_name: res.remove(0).try_into().unwrap(), params: res, }, )) |
