Skip to content

Commit

Permalink
🚚 zv: Drop weird Value type and field names when (de)serializing
Browse files Browse the repository at this point in the history
This is no longer needed.

While this doesn't completely fix dbus2#176, this goes as far as we can IMO.
For D-Bus we need the signature to be able to derialize any data to a
Value.
  • Loading branch information
zeenix committed Sep 4, 2024
1 parent 557ebb7 commit 8913e9c
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 12 deletions.
6 changes: 3 additions & 3 deletions zvariant/src/deserialize_value.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,10 @@ impl<'de, T: Type + Deserialize<'de>> Deserialize<'de> for DeserializeValue<'de,
where
D: Deserializer<'de>,
{
const FIELDS: &[&str] = &["zvariant::Value::Signature", "zvariant::Value::Value"];
const FIELDS: &[&str] = &["signature", "value"];
Ok(DeserializeValue(
deserializer.deserialize_struct(
"zvariant::Value",
"Variant",
FIELDS,
DeserializeValueVisitor(PhantomData),
)?,
Expand All @@ -53,7 +53,7 @@ impl<'de, T: Type + Deserialize<'de>> Visitor<'de> for DeserializeValueVisitor<T
type Value = T;

fn expecting(&self, formatter: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
formatter.write_str("zvariant::Value")
formatter.write_str("Variant")
}

fn visit_seq<V>(self, mut seq: V) -> Result<Self::Value, V::Error>
Expand Down
6 changes: 3 additions & 3 deletions zvariant/src/serialize_value.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,11 @@ impl<'a, T: Type + Serialize> Serialize for SerializeValue<'a, T> {
S: Serializer,
{
// Serializer implementation needs to ensure padding isn't added for Value.
let mut structure = serializer.serialize_struct("zvariant::Value", 2)?;
let mut structure = serializer.serialize_struct("Variant", 2)?;

let signature = T::signature();
structure.serialize_field("zvariant::Value::Signature", &signature)?;
structure.serialize_field("zvariant::Value::Value", self.0)?;
structure.serialize_field("signature", &signature)?;
structure.serialize_field("value", self.0)?;

structure.end()
}
Expand Down
1 change: 0 additions & 1 deletion zvariant/src/str.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ use crate::{Basic, Type};
/// [`&str`]: https://doc.rust-lang.org/std/str/index.html
/// [`String`]: https://doc.rust-lang.org/std/string/struct.String.html
#[derive(Default, PartialEq, Eq, PartialOrd, Ord, Hash, Clone, Serialize, Deserialize)]
#[serde(rename(serialize = "zvariant::Str", deserialize = "zvariant::Str"))]
pub struct Str<'a>(#[serde(borrow)] Inner<'a>);

#[derive(Eq, Clone)]
Expand Down
3 changes: 1 addition & 2 deletions zvariant/src/structure.rs
Original file line number Diff line number Diff line change
Expand Up @@ -309,8 +309,7 @@ impl<'a> Serialize for Structure<'a> {
where
S: Serializer,
{
let mut structure =
serializer.serialize_tuple_struct("zvariant::Structure", self.fields.len())?;
let mut structure = serializer.serialize_tuple_struct("Structure", self.fields.len())?;
for field in &self.fields {
field.serialize_value_as_tuple_struct_field(&mut structure)?;
}
Expand Down
6 changes: 3 additions & 3 deletions zvariant/src/value.rs
Original file line number Diff line number Diff line change
Expand Up @@ -582,12 +582,12 @@ impl<'a> Serialize for Value<'a> {
S: Serializer,
{
// Serializer implementation needs to ensure padding isn't added for Value.
let mut structure = serializer.serialize_struct("zvariant::Value", 2)?;
let mut structure = serializer.serialize_struct("Variant", 2)?;

let signature = self.value_signature();
structure.serialize_field("zvariant::Value::Signature", &signature)?;
structure.serialize_field("signature", &signature)?;

self.serialize_value_as_struct_field("zvariant::Value::Value", &mut structure)?;
self.serialize_value_as_struct_field("value", &mut structure)?;

structure.end()
}
Expand Down

0 comments on commit 8913e9c

Please sign in to comment.