binary data through dbus-python
simon.mcvittie at collabora.co.uk
Thu Dec 21 08:15:31 PST 2006
Sorry, the vital piece of information I forgot to mention is that
calling a method on a proxy object (as returned by Bus.get_object),
or on a dbus.Interface, can also take the byte_arrays option (and
also utf8_strings, if you ever want more efficient string transmission).
So, call your proxy method as:
or whatever the method is, if you want a ByteArray back. Full details below...
On Thu, 21 Dec 2006 at 16:45:52 +0100, Tomeu Vizoso wrote:
> Sending a str, the other side receives a ByteArray (in a method with
> byte_arrays=True with a parameter signature of 'ay'). That's good.
What you do in the sender and what you do in the receiver are completely
independent, as long as it's the same bytes going through the Unix socket.
In 0.80, conversion from Python to D-Bus always works on the principle of
"accept anything sensible". The only exception to this is that if we
don't have a signature (perhaps the remote object isn't introspectable),
the types you use are used to guess what the signature should have been.
It's conversion from D-Bus to Python that's ambiguous (we can't know whether
the Python programmer wants a ByteArray or a list of Byte), so the
byte_arrays and utf8_strings options exist to allow the programmer to
influence that conversion.
Specifically, here are the places where byte_arrays matter:
- If you call a method of a proxy object (as provided by Bus.get_object)
or a method of a dbus.Interface, that method returns 'ay', and you call
it as object_or_interface.Method(..., byte_arrays=True), the return
value (if calling synchronously) or the value passed to the reply
handler (if calling asynchronously) will be a ByteArray.
- If you decorate a method whose 'in' parameters include 'ay' with
@dbus.service.method(..., byte_arrays=True), when it's called via D-Bus
it will get a ByteArray in its parameters.
- If you connect a signal handler to a signal whose parameters include
'ay' by doing connect_to_signal(..., byte_arrays=True) or
add_signal_receiver(..., byte_arrays=True), when D-Bus invokes the
callback it will get a ByteArray in its parameters.
utf8_strings (turns 's' D-Bus types into dbus.UTF8String instead of
dbus.String) can appear in the same places byte_arrays can.
Hope this helps,
More information about the dbus