From ac2dc744d5cccbbb66e2b73e01b95b0c05b1c129 Mon Sep 17 00:00:00 2001 From: candifloss Date: Tue, 3 Dec 2024 14:00:52 +0530 Subject: [PATCH] modified serialize function --- src/formats/serde.rs | 38 +++++++++++++++++++++++++------------- 1 file changed, 25 insertions(+), 13 deletions(-) diff --git a/src/formats/serde.rs b/src/formats/serde.rs index 3e1fa97..a7fd1e5 100644 --- a/src/formats/serde.rs +++ b/src/formats/serde.rs @@ -3,6 +3,7 @@ use serde_json::{Map, Value}; use std::collections::HashMap; use zvariant::OwnedValue; +/// Serialize actions pub fn serialize_actions(actions: &[String], serializer: S) -> Result where S: Serializer, @@ -19,6 +20,7 @@ where map.serialize(serializer) } +/// Serialize hints pub fn serialize_hints( hints: &HashMap, serializer: S, @@ -43,24 +45,34 @@ impl Serialize for HintValueSerializer<'_> { where S: Serializer, { - // Signature - let signature = self.0.value_signature().to_string(); + let signature = self.0.value_signature().to_string(); // Signature // Extract the raw value correctly - let raw_value = if let Ok(v) = self.0.downcast_ref::() { + let raw_value = if let Ok(v) = self.0.downcast_ref::() { // BYTE: y Value::from(v) - } else if let Ok(v) = self.0.downcast_ref::() { - Value::from(v) - } else if let Ok(v) = self.0.downcast_ref::() { - Value::from(v) - } else if let Ok(v) = self.0.downcast_ref::() { + } else if let Ok(v) = self.0.downcast_ref::() { // BOOLEAN: b Value::Bool(v) - } else if let Ok(v) = self.0.downcast_ref::() { + } else if let Ok(v) = self.0.downcast_ref::() { // INT16: n + Value::from(v) + } else if let Ok(v) = self.0.downcast_ref::() { // UINT16: q + Value::from(v) + } else if let Ok(v) = self.0.downcast_ref::() { // INT32: i + Value::from(v) + } else if let Ok(v) = self.0.downcast_ref::() { // UINT32: u + Value::from(v) + } else if let Ok(v) = self.0.downcast_ref::() { // INT64: x + Value::from(v) + } else if let Ok(v) = self.0.downcast_ref::() { // UINT64: t + Value::from(v) + } else if let Ok(v) = self.0.downcast_ref::() { // DOUBLE: d + Value::from(v) + } else if let Ok(v) = self.0.downcast_ref::() { // STRING: s Value::String(v.clone()) - } else if let Ok(v) = self.0.downcast_ref::<&str>() { + } else if let Ok(v) = self.0.downcast_ref::<&str>() { // str Value::String(v.to_string()) - } else { - Value::Null // Unsupported types fallback to Null + } else { // Unsupported types + Value::Null // Fallback to Null + // Not implemented: UNIX_FD: h, OBJECT_PATH: o, SIGNATURE: g }; // Serialize the final structure as a map @@ -69,4 +81,4 @@ impl Serialize for HintValueSerializer<'_> { map.serialize_entry("value", &raw_value)?; map.end() } -} +} \ No newline at end of file