From debcc8fbc623ae1b21ab4d5c905675f629d527a2 Mon Sep 17 00:00:00 2001 From: Tristan Hume Date: Sun, 23 Apr 2017 14:37:19 -0400 Subject: [PATCH] clean up things a little bit --- source/ddbus/conv.d | 17 ++++++----------- source/ddbus/thin.d | 4 +++- 2 files changed, 9 insertions(+), 12 deletions(-) diff --git a/source/ddbus/conv.d b/source/ddbus/conv.d index b2e346a..015bce5 100644 --- a/source/ddbus/conv.d +++ b/source/ddbus/conv.d @@ -36,8 +36,9 @@ void buildIter(TS...)(DBusMessageIter *iter, TS args) if(allCanDBus!TS) { static if(is(T == Variant!DBusAny)) { auto val = arg.data; val.explicitVariant = true; - } else + } else { auto val = arg; + } DBusMessageIter subStore; DBusMessageIter* sub = &subStore; char[] sig = [cast(char) val.type]; @@ -51,11 +52,9 @@ void buildIter(TS...)(DBusMessageIter *iter, TS args) if(allCanDBus!TS) { else dbus_message_iter_open_container(iter, 'v', sig.ptr, sub); if(val.type == 's') { - immutable(char)* cStr = val.str.toStringz(); - dbus_message_iter_append_basic(sub,'s',&cStr); + buildIter(sub, val.str); } else if(val.type == 'b') { - dbus_bool_t longerBool = val.boolean; // dbus bools are ints - dbus_message_iter_append_basic(sub,'b',&longerBool); + buildIter(sub,val.boolean); } else if(dbus_type_is_basic(val.type)) { dbus_message_iter_append_basic(sub,val.type,&val.int64); } else if(val.type == 'a') { @@ -160,13 +159,9 @@ T readIter(T)(DBusMessageIter *iter) if (canDBus!T) { ret.type = dbus_message_iter_get_arg_type(iter); ret.explicitVariant = false; if(ret.type == 's') { - const(char)* cStr; - dbus_message_iter_get_basic(iter, &cStr); - ret.str = cStr.fromStringz().idup; // copy string + ret.str = readIter!string(iter); } else if(ret.type == 'b') { - dbus_bool_t longerBool; - dbus_message_iter_get_basic(iter, &longerBool); - ret.boolean = cast(bool)longerBool; + ret.boolean = readIter!bool(iter); } else if(dbus_type_is_basic(ret.type)) { dbus_message_iter_get_basic(iter, &ret.int64); } else if(ret.type == 'a') { diff --git a/source/ddbus/thin.d b/source/ddbus/thin.d index f6e64f7..5f9346e 100644 --- a/source/ddbus/thin.d +++ b/source/ddbus/thin.d @@ -292,8 +292,10 @@ struct DBusAny { if(type != 'a' || !signature || signature[0] != '{') throw new Exception("Can't convert type " ~ cast(char) type ~ " to " ~ T.stringof); T ret; - foreach(pair; array) + foreach(pair; array) { + enforce(pair.type == 'e'); ret[pair.entry.key.to!(KeyType!T)] = pair.entry.value.to!(ValueType!T); + } return ret; } else static assert(false, "Can't convert variant to " ~ T.stringof); }