Skip to content

Draft: Serialize and deserialize with standard serde instances

Addresses issue #176 (closed) .

This adds a new pseudo-signature type, which is like (ABC) but actually serializes as a{sv} (and writes the signatures accordingly). This therefore does not break API (no existing users use < or > in signatures) and allows vanilla Serialize/Deserialize instances to be used with SerializeDict-style serializations.

Advantages:

  • No API compatibility break.
  • Picks up all serde annotations because it uses standard serde instances
  • Lets you serialize to dbus as dict and to JSON with the same serialize instance

Problems:

  • Signature types are no longer literally one-to-one with dbus, now have to be converted before serializing (which can be done, but is a bit hackish)
  • There's no way (I have found yet!) to recover this signature through a variant in deserialization, which means that these can't be used inside DeserializeDict or DeserializeValue. I had the idea of sneaking the signature in here:

https://gitlab.freedesktop.org/dbus/zbus/-/blob/main/zvariant/src/deserialize_value.rs#L41

... but couldn't figure out a way not to leak memory. This means that you can't use this inside a SerializeDict or a variant. But given that it offers a replacement to SerializeDict, that's not perhaps as big a problem. And I'm confident I can figure out that last issue.

Edited by Jimmy Hartzell

Merge request reports

Loading