aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMax Audron <audron@cocaine.farm>2025-07-27 01:51:14 +0200
committerMax Audron <audron@cocaine.farm>2025-07-27 01:51:14 +0200
commitd45e0a687ed5aa78f3e80bc5c335312bd81b2d4c (patch)
treec93c3cb6839b707202f678d25dab0752182948c4 /src
parentfix sessioninit message wrongly using NetworkMap to convert a field (diff)
temporarly fix nested network repr parsing for variant types
Diffstat (limited to 'src')
-rw-r--r--src/message/signalproxy/objects/bufferviewconfig.rs10
-rw-r--r--src/message/signalproxy/objects/network.rs16
-rw-r--r--src/message/signalproxy/objects/networkinfo.rs2
-rw-r--r--src/primitive/bufferid.rs16
-rw-r--r--src/primitive/variantlist.rs30
5 files changed, 35 insertions, 39 deletions
diff --git a/src/message/signalproxy/objects/bufferviewconfig.rs b/src/message/signalproxy/objects/bufferviewconfig.rs
index 8ca6b82..286e83a 100644
--- a/src/message/signalproxy/objects/bufferviewconfig.rs
+++ b/src/message/signalproxy/objects/bufferviewconfig.rs
@@ -11,15 +11,11 @@ use crate::primitive::{BufferId, NetworkId, VariantList};
#[derive(Debug, Default, Clone, PartialEq, NetworkList, NetworkMap)]
pub struct BufferViewConfig {
- #[network(rename = "BufferList", network = "map", variant = "VariantList")]
+ #[network(rename = "BufferList", network = "list", variant = "VariantList")]
pub buffers: Vec<BufferId>,
- #[network(rename = "RemovedBuffers", network = "map", variant = "VariantList")]
+ #[network(rename = "RemovedBuffers", network = "list", variant = "VariantList")]
pub removed_buffers: Vec<BufferId>,
- #[network(
- rename = "TemporarilyRemovedBuffers",
- network = "map",
- variant = "VariantList"
- )]
+ #[network(rename = "TemporarilyRemovedBuffers", network = "list", variant = "VariantList")]
pub temporarily_removed_buffers: Vec<BufferId>,
#[network(rename = "bufferViewId", default, skip)]
diff --git a/src/message/signalproxy/objects/network.rs b/src/message/signalproxy/objects/network.rs
index 693abfe..138f63f 100644
--- a/src/message/signalproxy/objects/network.rs
+++ b/src/message/signalproxy/objects/network.rs
@@ -9,7 +9,7 @@ use libquassel_derive::{sync, NetworkMap, Setters};
use crate::error::ProtocolError;
use crate::message::signalproxy::translation::NetworkMap;
-use crate::message::{Class, Syncable};
+use crate::message::{Class, NetworkList, Syncable};
use crate::primitive::{Variant, VariantList, VariantMap};
use crate::serialize::{Deserialize, Serialize, UserType};
@@ -617,6 +617,20 @@ pub struct NetworkServer {
pub proxy_pass: String,
}
+// TODO this is not correct usage, it's technically not really network repr were converting from
+// but just the conversion of VariantList -> Self directly
+// we have this problem since now we have generic VariantList impls
+// for all the variants and this type is now also directly a variant
+impl NetworkList for Vec<NetworkServer> {
+ fn to_network_list(&self) -> super::VariantList {
+ self.iter().map(|b| Variant::NetworkServer(b.clone())).collect()
+ }
+
+ fn from_network_list(input: &mut super::VariantList) -> Self {
+ input.iter().map(|b| match_variant!(b, Variant::NetworkServer)).collect()
+ }
+}
+
impl UserType for NetworkServer {
const NAME: &str = "Network::Server";
}
diff --git a/src/message/signalproxy/objects/networkinfo.rs b/src/message/signalproxy/objects/networkinfo.rs
index f81a3e7..4cd84dc 100644
--- a/src/message/signalproxy/objects/networkinfo.rs
+++ b/src/message/signalproxy/objects/networkinfo.rs
@@ -14,7 +14,7 @@ pub struct NetworkInfo {
pub network_name: String,
#[setter(skip)]
- #[network(rename = "ServerList", variant = "VariantList", network = "map")]
+ #[network(rename = "ServerList", variant = "VariantList", network = "list")]
pub server_list: Vec<NetworkServer>,
#[network(rename = "perform")]
pub perform: StringList,
diff --git a/src/primitive/bufferid.rs b/src/primitive/bufferid.rs
index e987d85..59e1ace 100644
--- a/src/primitive/bufferid.rs
+++ b/src/primitive/bufferid.rs
@@ -2,10 +2,13 @@
#[repr(transparent)]
pub struct BufferId(pub i32);
+use crate::message::NetworkList;
use crate::{error::ProtocolError, serialize::*};
use crate::serialize::UserType;
+use super::Variant;
+
impl Serialize for BufferId {
fn serialize(&self) -> Result<Vec<u8>, ProtocolError> {
let mut res = Vec::new();
@@ -42,6 +45,19 @@ impl UserType for BufferId {
const NAME: &str = "BufferId";
}
+// TODO this is not correct usage, it's technically not really network repr were converting from
+// but just the conversion of VariantList -> Self directly
+impl NetworkList for Vec<BufferId> {
+ fn to_network_list(&self) -> super::VariantList {
+ self.iter().map(|b| Variant::BufferId(*b)).collect()
+ }
+
+ fn from_network_list(input: &mut super::VariantList) -> Self {
+ input.iter().map(|b| match_variant!(b, Variant::BufferId)).collect()
+ }
+}
+
+
#[cfg(test)]
mod tests {
use super::*;
diff --git a/src/primitive/variantlist.rs b/src/primitive/variantlist.rs
index 0f0f4e0..20913ff 100644
--- a/src/primitive/variantlist.rs
+++ b/src/primitive/variantlist.rs
@@ -50,33 +50,3 @@ impl Deserialize for VariantList {
impl VariantType for VariantList {
const TYPE: u32 = crate::primitive::QVARIANTLIST;
}
-
-impl<S> crate::message::NetworkMap for Vec<S>
-where
- S: std::convert::TryFrom<Variant> + Into<Variant> + Clone + std::hash::Hash + std::cmp::Eq,
- <S as TryFrom<Variant>>::Error: std::fmt::Debug,
-{
- type Item = VariantList;
-
- fn to_network_map(&self) -> VariantList {
- self.iter().map(|i| i.clone().into()).collect()
- }
-
- fn from_network_map(input: &mut VariantList) -> Self {
- input.iter().map(|i| i.clone().try_into().unwrap()).collect()
- }
-}
-
-impl<S> crate::message::NetworkList for Vec<S>
-where
- S: std::convert::TryFrom<Variant> + Into<Variant> + Clone + std::hash::Hash + std::cmp::Eq,
- <S as TryFrom<Variant>>::Error: std::fmt::Debug,
-{
- fn to_network_list(&self) -> VariantList {
- self.iter().map(|i| i.clone().into()).collect()
- }
-
- fn from_network_list(input: &mut VariantList) -> Self {
- input.iter().map(|i| i.clone().try_into().unwrap()).collect()
- }
-}