modified serialize function
This commit is contained in:
parent
829a8741ee
commit
ac2dc744d5
@ -3,6 +3,7 @@ use serde_json::{Map, Value};
|
||||
use std::collections::HashMap;
|
||||
use zvariant::OwnedValue;
|
||||
|
||||
/// Serialize actions
|
||||
pub fn serialize_actions<S>(actions: &[String], serializer: S) -> Result<S::Ok, S::Error>
|
||||
where
|
||||
S: Serializer,
|
||||
@ -19,6 +20,7 @@ where
|
||||
map.serialize(serializer)
|
||||
}
|
||||
|
||||
/// Serialize hints
|
||||
pub fn serialize_hints<S>(
|
||||
hints: &HashMap<String, OwnedValue>,
|
||||
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::<u8>() {
|
||||
let raw_value = if let Ok(v) = self.0.downcast_ref::<u8>() { // BYTE: y
|
||||
Value::from(v)
|
||||
} else if let Ok(v) = self.0.downcast_ref::<i32>() {
|
||||
Value::from(v)
|
||||
} else if let Ok(v) = self.0.downcast_ref::<u64>() {
|
||||
Value::from(v)
|
||||
} else if let Ok(v) = self.0.downcast_ref::<bool>() {
|
||||
} else if let Ok(v) = self.0.downcast_ref::<bool>() { // BOOLEAN: b
|
||||
Value::Bool(v)
|
||||
} else if let Ok(v) = self.0.downcast_ref::<String>() {
|
||||
} else if let Ok(v) = self.0.downcast_ref::<i16>() { // INT16: n
|
||||
Value::from(v)
|
||||
} else if let Ok(v) = self.0.downcast_ref::<u16>() { // UINT16: q
|
||||
Value::from(v)
|
||||
} else if let Ok(v) = self.0.downcast_ref::<i32>() { // INT32: i
|
||||
Value::from(v)
|
||||
} else if let Ok(v) = self.0.downcast_ref::<u32>() { // UINT32: u
|
||||
Value::from(v)
|
||||
} else if let Ok(v) = self.0.downcast_ref::<i64>() { // INT64: x
|
||||
Value::from(v)
|
||||
} else if let Ok(v) = self.0.downcast_ref::<u64>() { // UINT64: t
|
||||
Value::from(v)
|
||||
} else if let Ok(v) = self.0.downcast_ref::<f64>() { // DOUBLE: d
|
||||
Value::from(v)
|
||||
} else if let Ok(v) = self.0.downcast_ref::<String>() { // 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
|
||||
|
Loading…
Reference in New Issue
Block a user