Using empty arrays for passing of variable structures as arguments

Simon McVittie simon.mcvittie at collabora.co.uk
Fri Jun 17 04:49:08 PDT 2011


On Fri, 17 Jun 2011 at 13:38:10 +0200, Bogdan Lotko wrote:
> struct A
> {
>   bool       hasB; // just as example
>   structB *sB;     // Must not be NULL if hasB == true
> ....
> }

hasB is redundant, its value appears to be always (sB != NULL).

> The sent type will be always coded as (ba(ii)) where the array can
> have 0 or 1 entries.

The boolean is redundant; you can just use a(ii) and document that it has
at most one entry.

GVariant's extension of the D-Bus type system has the "maybe" type, e.g. m(ii),
which is an array with at most one (ii) entry. D-Bus doesn't, yet -
https://bugs.freedesktop.org/show_bug.cgi?id=27857 tracks progress on this.

Emulating "maybe" via an array and some documentation seems a good approach,
at the moment.

    S


More information about the dbus mailing list