aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/message/signalproxy/objects/buffersyncer.rs157
-rw-r--r--src/message/signalproxy/objects/mod.rs8
2 files changed, 22 insertions, 143 deletions
diff --git a/src/message/signalproxy/objects/buffersyncer.rs b/src/message/signalproxy/objects/buffersyncer.rs
index cc26310..ecacbc9 100644
--- a/src/message/signalproxy/objects/buffersyncer.rs
+++ b/src/message/signalproxy/objects/buffersyncer.rs
@@ -1,150 +1,21 @@
-use std::{collections::HashMap, convert::TryInto};
+use std::collections::HashMap;
-use num_traits::{FromPrimitive, ToPrimitive};
+use crate::primitive::MessageType;
+use libquassel_derive::Network;
-use itertools::Itertools;
-
-use crate::{
- message::signalproxy::Network,
- primitive::{MessageType, Variant, VariantList},
-};
-
-#[derive(Debug, Clone, PartialEq)]
+#[derive(Debug, Clone, PartialEq, Network)]
+#[network(repr = "list")]
pub struct BufferSyncer {
+ #[network(rename = "Activities", network, variant = "VariantList")]
pub activities: HashMap<i32, MessageType>,
+ #[network(rename = "HighlightCounts", network, variant = "VariantList")]
pub highlight_counts: HashMap<i32, i32>,
+ #[network(rename = "LastSeenMsg", network, variant = "VariantList")]
pub last_seen_msg: HashMap<i32, i64>,
+ #[network(rename = "MarkerLines", network, variant = "VariantList")]
pub marker_line: HashMap<i32, i64>,
}
-impl Network for BufferSyncer {
- type Item = VariantList;
-
- fn to_network(&self) -> Self::Item {
- let mut res = Self::Item::new();
-
- res.push(Variant::ByteArray(s!("Activities")));
- res.push(Variant::VariantList({
- let mut res = VariantList::new();
-
- self.activities.iter().for_each(|(k, v)| {
- res.push(Variant::i32(*k));
- res.push(Variant::i32(v.to_i32().unwrap()));
- });
-
- res
- }));
-
- res.push(Variant::ByteArray(s!("HighlightCounts")));
- res.push(Variant::VariantList({
- let mut res = VariantList::new();
-
- self.highlight_counts.iter().for_each(|(k, v)| {
- res.push(Variant::i32(*k));
- res.push(Variant::i32(*v));
- });
-
- res
- }));
-
- res.push(Variant::ByteArray(s!("LastSeenMsg")));
- res.push(Variant::VariantList({
- let mut res = VariantList::new();
-
- self.last_seen_msg.iter().for_each(|(k, v)| {
- res.push(Variant::i32(*k));
- res.push(Variant::i64(*v));
- });
-
- res
- }));
-
- res.push(Variant::ByteArray(s!("MarkerLines")));
- res.push(Variant::VariantList({
- let mut res = VariantList::new();
-
- self.marker_line.iter().for_each(|(k, v)| {
- res.push(Variant::i32(*k));
- res.push(Variant::i64(*v));
- });
-
- res
- }));
-
- res
- }
-
- fn from_network(input: &mut Self::Item) -> Self {
- let mut i = input.iter().cycle();
-
- i.position(|x| *x == crate::primitive::Variant::ByteArray(s!("Activities")))
- .unwrap();
- let activities: VariantList = i.next().unwrap().try_into().unwrap();
- let activities = activities
- .iter()
- .batching(|it| match it.next() {
- None => None,
- Some(x) => match it.next() {
- None => None,
- Some(y) => Some((
- x.try_into().unwrap(),
- MessageType::from_i32(y.try_into().unwrap()).unwrap(),
- )),
- },
- })
- .collect();
-
- i.position(|x| *x == crate::primitive::Variant::ByteArray(s!("HighlightCounts")))
- .unwrap();
- let highlight_counts: VariantList = i.next().unwrap().try_into().unwrap();
- let highlight_counts = highlight_counts
- .iter()
- .batching(|it| match it.next() {
- None => None,
- Some(x) => match it.next() {
- None => None,
- Some(y) => Some((x.try_into().unwrap(), y.try_into().unwrap())),
- },
- })
- .collect();
-
- i.position(|x| *x == crate::primitive::Variant::ByteArray(s!("LastSeenMsg")))
- .unwrap();
- let last_seen_msg: VariantList = i.next().unwrap().try_into().unwrap();
- let last_seen_msg = last_seen_msg
- .iter()
- .batching(|it| match it.next() {
- None => None,
- Some(x) => match it.next() {
- None => None,
- Some(y) => Some((x.try_into().unwrap(), y.try_into().unwrap())),
- },
- })
- .collect();
-
- i.position(|x| *x == crate::primitive::Variant::ByteArray(s!("MarkerLines")))
- .unwrap();
- let marker_line: VariantList = i.next().unwrap().try_into().unwrap();
- let marker_line = marker_line
- .iter()
- .batching(|it| match it.next() {
- None => None,
- Some(x) => match it.next() {
- None => None,
- Some(y) => Some((x.try_into().unwrap(), y.try_into().unwrap())),
- },
- })
- .collect();
-
- Self {
- activities,
- highlight_counts,
- last_seen_msg,
- marker_line,
- }
- }
-}
-
pub trait BufferSyncerServer {
fn activities(self: &Self) -> &HashMap<u32, MessageType>;
fn activities_mut(self: &mut Self) -> &mut HashMap<u32, MessageType>;
@@ -275,11 +146,11 @@ mod tests {
fn get_runtime() -> BufferSyncer {
BufferSyncer {
activities: map! {
- 1 => MessageType::None,
- 2 => MessageType::None,
- 3 => MessageType::None,
- 4 => MessageType::None,
- 5 => MessageType::None,
+ 1 => MessageType::NONE,
+ 2 => MessageType::NONE,
+ 3 => MessageType::NONE,
+ 4 => MessageType::NONE,
+ 5 => MessageType::NONE,
},
highlight_counts: map! {
1 => 0,
diff --git a/src/message/signalproxy/objects/mod.rs b/src/message/signalproxy/objects/mod.rs
index 2fc4745..bc07dca 100644
--- a/src/message/signalproxy/objects/mod.rs
+++ b/src/message/signalproxy/objects/mod.rs
@@ -28,6 +28,7 @@ use crate::primitive::VariantList;
#[derive(Debug, Clone, PartialEq, From)]
pub enum Types {
AliasManager(AliasManager),
+ BufferSyncer(BufferSyncer),
Network(network::Network),
NetworkInfo(NetworkInfo),
NetworkConfig(NetworkConfig),
@@ -37,8 +38,10 @@ pub enum Types {
impl Types {
pub fn to_network(&self) -> VariantList {
+ debug!("converting to network object: {:#?}", self);
match self {
Types::AliasManager(val) => val.to_network(),
+ Types::BufferSyncer(val) => val.to_network(),
Types::Network(val) => val.to_network(),
Types::NetworkInfo(val) => val.to_network(),
Types::NetworkConfig(val) => val.to_network(),
@@ -48,11 +51,16 @@ impl Types {
}
pub fn from_network(class_name: &str, input: &mut VariantList) -> Self {
+ debug!(
+ "converting {} from network object: {:#?}",
+ class_name, input
+ );
match class_name {
"Network" => Types::Network(Network::from_network(input)),
"NetworkInfo" => Types::NetworkInfo(NetworkInfo::from_network(input)),
"NetworkConfig" => Types::NetworkConfig(NetworkConfig::from_network(input)),
"AliasManager" => Types::AliasManager(AliasManager::from_network(input)),
+ "BufferSyncer" => Types::BufferSyncer(BufferSyncer::from_network(input)),
"CoreData" => Types::CoreData(CoreData::from_network(
&mut input.remove(0).try_into().unwrap(),
)),