chiark / gitweb /
bus-util: generalize helper for ID128 prpoerties
[elogind.git] / src / shared / bus-util.c
index c8b070b53b8b9e8885cce2e5ef5c75fa192f3aa2..fde3c3119a02875ebd60f311a7e59954021d6a43 100644 (file)
@@ -1334,6 +1334,23 @@ int bus_property_get_bool(
         return sd_bus_message_append_basic(reply, 'b', &b);
 }
 
+int bus_property_get_id128(
+                sd_bus *bus,
+                const char *path,
+                const char *interface,
+                const char *property,
+                sd_bus_message *reply,
+                void *userdata,
+                sd_bus_error *error) {
+
+        sd_id128_t *id = userdata;
+
+        if (sd_id128_is_null(*id)) /* Add an empty array if the ID is zero */
+                return sd_bus_message_append(reply, "ay", 0);
+        else
+                return sd_bus_message_append_array(reply, 'b', id->bytes, 16);
+}
+
 #if __SIZEOF_SIZE_T__ != 8
 int bus_property_get_size(
                 sd_bus *bus,