packing an array of dictionaries

koorapati, koundinya Koundinya.Koorapati at dellteam.com
Mon May 18 13:20:00 UTC 2020


Hi dbus developers,
	How do we pack an array of dictionaries using the glib gdbus APIs. We want to pack the following data using the glib gdbus APIs, but are getting some or the other issue.


   array [
      dict entry(
         string "config"
         variant             array [
               dict entry(
                  string "origin"
                  variant                      string "compat:suse:/etc/sysconfig/network/ifcfg-eth2"
               )
               dict entry(
                  string "uuid"
                  variant                      array of bytes [
                        70 4f d6 77 5d 73 5d 80 83 90 3b 2b b0 57 2d ff
                     ]
               )
               dict entry(
                  string "owner-uid"
                  variant                      uint32 4294967295
               )
            ]
      )
   ]

       GVariantBuilder *b1 = NULL;
        g_variant_builder_add (b1, "{sv}", "origin", g_variant_new_string("compat:suse:/etc/sysconfig/network/ifcfg-eth2"));
        gchar array[] = {0x70, 0x4f, 0xd6, 0x77, 0x5d, 0x73, 0x5d, 0x80, 0x83, 0x90, 0x3b, 0x2b, 0xb0, 0x57, 0x2d, 0xff};
        g_variant_builder_add (b1, "{sv}", "uuid", g_variant_new_fixed_array(G_VARIANT_TYPE_BYTE, array, 16, sizeof(gchar)));
        g_variant_builder_add (b1, "{sv}", "owner-uid", g_variant_new_uint32(4294967295));
        GVariant *v2 = g_variant_builder_end(b1);
        g_variant_builder_unref(b1);

        GVariantBuilder *b2 = NULL;
        b2 = g_variant_builder_new (G_VARIANT_TYPE ("a{sv}"));
        g_variant_builder_add (b2, "{sv}", "config", g_variant_new_array(NULL, &v2, 3));
        GVariant *v3 = g_variant_builder_end(b2);
        g_variant_builder_unref(b2);

        g_dbus_proxy_call_sync (proxy, "setClientConfig", g_variant_new_tuple(&v3, 1), G_DBUS_CALL_FLAGS_NONE, -1, NULL, &error);

What is going wrong with the above code? Any help will be appreciated.

Thank You,
Koundinya




More information about the dbus mailing list