Why GVariant? (Re: Starting the kdbus discussions

Lennart Poettering mzqohf at 0pointer.de
Thu Jan 2 06:53:14 PST 2014


On Thu, 02.01.14 14:20, rony (rony at wu.ac.at) wrote:

> > I am certainly not going to wdiff this against the bus spec for
> > you... Note that in the dbus spec we should not document this anyway,
> > but simply refer to glib's/ryan's spec for the marshalling.
> >
> >> If I can connect with AF_UNIX and communicate the same way on the
> >> wire, then it's still D-Bus and I really don't see the problem here.
> > Yes you can, it's compatbile with that.
> Two questions:
> 
>   * Why did you chose to use a GVariant encoding and not sticking to the standardized and
>     established dbus encoding? What were the pro and what were the cons arguments for that
>     (surprising) decision?

This requirement has been adopted on request of Canonical's Ryan Lortie,
who designed GVariant. In a way GVariant is just version 2.0 of the dbus
marshalling. In the user interface it is mostly identical (i.e. all
dbus1 signature strings are also gvariant signature strings, though the
reverse is not true), however it is slightly more powerful (as it knows
MAYBE types), a bit cleaner (since in gvariant the serialization of a
specific data object is always the same regardless what comes before it,
which is not the case for dbus1 marshalling), and more efficient (as you
can seek to any element in an array or struct freely in O(1) time, even
if the elements have a variable length, which was O(n) before with n
being the number of elements).

GVariant has been part of GLib since a long time, and is used as storage
format of dconf among other things. Using GVariant as transport
marshalling hence makes usecases like this (i.e. where you frequently
use the same data on disk and on IPC) particularly efficient.

Note that the format string extensions GVariant makes on top of dbus1
are already listed in the dbus spec, and marked for future extension
there, so the groundwork for actually making Gvariant work as dbus
marshalling has alraedy been laid.

>   * Also, I was surprised to learn that (among other things) using
>     GVariant one must not transfer strings that contain nul bytes
>     (0x00) byte (cf. section 2.4.5 Strings in the above mentioned
>     pdf)?  Why is that?

You cannot do that on dbus1 marshalling either. This is not a change.

For security reasons it is always a good idea to enforce certain things
on the data you transfer, like compatibility with C strings or UTF-8
validity.

Lennart

-- 
Lennart Poettering, Red Hat


More information about the dbus mailing list