dicts

Havoc Pennington hp@redhat.com
Thu Jan 27 17:02:36 PST 2005


Hi,

I had yet another idea of how to do dicts.

Reviewing previous ideas, we have:

 - in the Introspect() data, hint that an array of struct is really a
dict

 - in the signature, have a typecode preceding the array of struct
indicating
   that it's really a dict

The problem with the Introspect() one I think is that it's a bit
fragile.

The problem with the signature one is that it makes the demarshaling
code all yucky:

next (iter):
 if (iter->current_typecode == dict)
   iter->array_is_really_dict = TRUE;

get_current_type (iter):
 if (iter->array_is_really_dict) 
   { if (type == struct) return dict_entry; else if (type == array)
return dict; }

etc. basically everywhere we look at a typecode you have to check
is_really_dict and reinterpret the typecode accordingly.

Here is my latest idea. The signature for a method that takes a
dict<string,int> is
"a{si}" or "array of dict entry of string,int"

In other words rather than introducing a dict type, introduce a dict
entry type.

This is sort of strange, because there would probably have to be a
special case that dict entries may only appear inside arrays. However,
it seems more natural than something like 
"ma(si)" (m = map)

In the public API this would look like "array of dict entry", i.e.
there's no DBUS_TYPE_DICT. That seems pretty OK to me, language bindings
will just cover it up. And it avoids a whole mess of special casing.

Havoc





More information about the dbus mailing list