I am trying to a byte array over D-Bus using the GDBus bindings. Can you please let me know how I can achive that. I tried googling but didnt help.
Byte array contains a image file so cannot be converted to charbytearray
Any help is appriciated
I am trying to a byte array over D-Bus using the GDBus bindings. Can you please let me know how I can achive that. I tried googling but didnt help.
Byte array contains a image file so cannot be converted to charbytearray
Any help is appriciated
This question has some good ideas in the answers including for passing large amounts of data by writing the data to a file and passing the filename, or using a named pipe. Writing to a file and passing the file name might be the easiest to implement.
Actually, instead of using type "ay", you can use "a(y)". The glib binding would translate "a(y)" to GVariant*.
And then you can use "GVariant" handling to deal with the parameter.
e.g. the xml file
Generated method:
You can extract and insert data using "GVariant" method.
Insert data at client side:
Extract data at server side:
I did some tests using an XML where I used the type
ay
. This works well with the QT binding (generated withqdbusxml2cpp
) where it translates intoQByteArray
however it seems that it doesn't work with the glib binding (generated withgdbus-codegen
) where it translates ingchar *
and it seems you lose what's after\0
- because somehow it's handled as a string. However you will find that:Which means according to https://developer.gnome.org/gio/stable/gdbus-codegen.html that you could handle it as
GVariant
. I tested this by adding the tag for annotationorg.gtk.GDBus.C.ForceGVariant
<annotation name="org.gtk.GDBus.C.ForceGVariant" value="true"/>
on each arg and it works.At the client side, you could do it easier by calling the g_variant_new_from_data() method:
Or, if you have a populated a GByteArray*, you could do it like this: