Search code examples
csystemddbus

Get actual type of variant data in dbus message


To do some pre-verification of received property set messages I need to get the type of the message data and compare it to the type of the property.

When I try to peek the type (using sd_bus_message_peek_type) it returns "v" which is the signature of variant. Is it possible to get the signature of the actual data wrapped in the variant? And how to do that?


Solution

  • A variant is a container so one needs to enter that container to get the actual type.

    Entering the container is done with sd_bus_message_enter_container.

    Once the container is entered, the next data to read is the variant wrapped value.


    Note that the pre-verification step can be done by the call to sd_bus_message_enter_container itself.

    The type argument is the type of the property, and if it doesn't match the type of the message data then sd_bus_message_enter_container will return -ENXIO.