<SUBSECTION>
g_variant_get_size
g_variant_get_data
+g_variant_get_data_as_bytes
g_variant_store
g_variant_new_from_data
+g_variant_new_from_bytes
g_variant_byteswap
g_variant_get_normal_form
g_variant_is_normal_form
g_variant_get_child_value
g_variant_get_size
g_variant_get_data
+g_variant_get_data_as_bytes
g_variant_store
g_variant_is_normal_form
g_variant_get_type
g_variant_is_container
g_variant_classify
g_variant_compare
+g_variant_new_from_bytes
g_variant_new_boolean
g_variant_new_byte
g_variant_new_int16
return value;
}
-/* -- internal -- */
-/* < internal >
+/**
* g_variant_new_from_bytes:
* @type: a #GVariantType
* @bytes: a #GBytes
* A reference is taken on @bytes.
*
* Returns: a new #GVariant with a floating reference
+ *
+ * Since: 2.36
*/
GVariant *
g_variant_new_from_bytes (const GVariantType *type,
return value;
}
+/* -- internal -- */
+
/* < internal >
* g_variant_new_from_children:
* @type: a #GVariantType
}
/**
+ * g_variant_get_data_as_bytes:
+ * @value: a #GVariant
+ *
+ * Returns a pointer to the serialised form of a #GVariant instance.
+ * The semantics of this function are exactly the same as
+ * g_variant_get_data(), except that the returned #GBytes holds
+ * a reference to the variant data.
+ *
+ * Returns: (transfer full): A new #GBytes representing the variant data
+ *
+ * Since: 2.36
+ */
+GBytes *
+g_variant_get_data_as_bytes (GVariant *value)
+{
+ g_variant_lock (value);
+ g_variant_ensure_serialised (value);
+ g_variant_unlock (value);
+
+ return g_bytes_ref (value->contents.serialised.bytes);
+}
+
+
+/**
* g_variant_n_children:
* @value: a container #GVariant
*
#include <glib/gbytes.h>
/* gvariant-core.c */
-G_GNUC_INTERNAL
-GVariant * g_variant_new_from_bytes (const GVariantType *type,
- GBytes *bytes,
- gboolean trusted);
G_GNUC_INTERNAL
GVariant * g_variant_new_from_children (const GVariantType *type,
#include <glib/gvarianttype.h>
#include <glib/gstring.h>
+#include <glib/gbytes.h>
G_BEGIN_DECLS
gsize g_variant_get_size (GVariant *value);
gconstpointer g_variant_get_data (GVariant *value);
+GLIB_AVAILABLE_IN_2_36
+GBytes * g_variant_get_data_as_bytes (GVariant *value);
void g_variant_store (GVariant *value,
gpointer data);
GVariant * g_variant_get_normal_form (GVariant *value);
gboolean g_variant_is_normal_form (GVariant *value);
GVariant * g_variant_byteswap (GVariant *value);
+
+GLIB_AVAILABLE_IN_2_36
+GVariant * g_variant_new_from_bytes (const GVariantType *type,
+ GBytes *bytes,
+ gboolean trusted);
GVariant * g_variant_new_from_data (const GVariantType *type,
gconstpointer data,
gsize size,
"(yvu)", 254, g_variant_new ("(^as)", strv), 42);
}
+static void
+test_gbytes (void)
+{
+ GVariant *a;
+ GBytes *bytes;
+ GBytes *bytes2;
+ const guint8 values[5] = { 1, 2, 3, 4, 5 };
+ const guint8 *elts;
+ gsize n_elts;
+ gint i;
+
+ bytes = g_bytes_new (&values, 5);
+ a = g_variant_new_from_bytes (G_VARIANT_TYPE_BYTESTRING, bytes, TRUE);
+ g_bytes_unref (bytes);
+ n_elts = 0;
+ elts = g_variant_get_fixed_array (a, &n_elts, sizeof (guint8));
+ g_assert (n_elts == 5);
+ for (i = 0; i < 5; i++)
+ g_assert_cmpint (elts[i], ==, i + 1);
+
+ bytes2 = g_variant_get_data_as_bytes (a);
+ g_variant_unref (a);
+
+ bytes = g_bytes_new (&values, 5);
+ g_assert (g_bytes_equal (bytes, bytes2));
+
+ g_bytes_unref (bytes);
+ g_bytes_unref (bytes2);
+}
+
int
main (int argc, char **argv)
{
g_test_add_func ("/gvariant/checksum-basic", test_checksum_basic);
g_test_add_func ("/gvariant/checksum-nested", test_checksum_nested);
+ g_test_add_func ("/gvariant/gbytes", test_gbytes);
+
return g_test_run ();
}