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 std::collections::HashMap;
|
||||||
use zvariant::OwnedValue;
|
use zvariant::OwnedValue;
|
||||||
|
|
||||||
|
/// Serialize actions
|
||||||
pub fn serialize_actions<S>(actions: &[String], serializer: S) -> Result<S::Ok, S::Error>
|
pub fn serialize_actions<S>(actions: &[String], serializer: S) -> Result<S::Ok, S::Error>
|
||||||
where
|
where
|
||||||
S: Serializer,
|
S: Serializer,
|
||||||
@ -19,6 +20,7 @@ where
|
|||||||
map.serialize(serializer)
|
map.serialize(serializer)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Serialize hints
|
||||||
pub fn serialize_hints<S>(
|
pub fn serialize_hints<S>(
|
||||||
hints: &HashMap<String, OwnedValue>,
|
hints: &HashMap<String, OwnedValue>,
|
||||||
serializer: S,
|
serializer: S,
|
||||||
@ -43,24 +45,34 @@ impl Serialize for HintValueSerializer<'_> {
|
|||||||
where
|
where
|
||||||
S: Serializer,
|
S: Serializer,
|
||||||
{
|
{
|
||||||
// Signature
|
let signature = self.0.value_signature().to_string(); // Signature
|
||||||
let signature = self.0.value_signature().to_string();
|
|
||||||
|
|
||||||
// Extract the raw value correctly
|
// 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)
|
Value::from(v)
|
||||||
} else if let Ok(v) = self.0.downcast_ref::<i32>() {
|
} else if let Ok(v) = self.0.downcast_ref::<bool>() { // BOOLEAN: b
|
||||||
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>() {
|
|
||||||
Value::Bool(v)
|
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())
|
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())
|
Value::String(v.to_string())
|
||||||
} else {
|
} else { // Unsupported types
|
||||||
Value::Null // Unsupported types fallback to Null
|
Value::Null // Fallback to Null
|
||||||
|
// Not implemented: UNIX_FD: h, OBJECT_PATH: o, SIGNATURE: g
|
||||||
};
|
};
|
||||||
|
|
||||||
// Serialize the final structure as a map
|
// Serialize the final structure as a map
|
||||||
|
Loading…
Reference in New Issue
Block a user