nested arrays and get_element_type
Havoc Pennington
hp at redhat.com
Fri Jul 28 07:29:30 PDT 2006
Hi,
Evan Martin wrote:
> Imagine we have an iter i that points at the empty array. It seems
> obvious that get_arg_type(i) == ARRAY and get_element_type(i) ==
> ARRAY. It appears from the docs that you can recurse() into i, so
> let's call that iter j. (It's not clear to me what the utility of
> being able to recurse() into an empty i is...)
The reason is that it lets you avoid special cases I think; you can just
write your code normally and the loop that would traverse the array
values won't run any iterations.
> Q1) How can I tell that the iterator j is not pointing at anything?
> Should I have used get_array_len(i)?
If you wrote the code like:
recurse(i, j);
while (get_arg_type(j) != INVALID) {
recurse(j, k);
}
Then recurse(j,k) should never run right?
get_array_len is also an option of course.
> Q2) How can I discover what types j holds? Since it doesn't point at
> a value, it would seem that get_element_type(j) is probably invalid.
> If it does work, arg_type(j) and element_type(j) are should both be
> ARRAY.
You can call dbus_message_get_signature() or
dbus_message_iter_get_signature() for example.
> Q3) But you can't recurse further -- so is there any way to discover
> the existence of that innermost string in the type?
I may have forgotten something, but I think you have to use one of the
get_signature() for this.
> I need to know what the full type is so if I want to take this
> de-serialized message and re-serialize it back into a different
> DBusMessage I can pass the appropriate args to open_container()...
> right?
Yep, for something like this you would need the whole type.
Havoc
More information about the dbus
mailing list