+static GByteArray *
+flatten_vectors (GVariantVectors *v)
+{
+ GByteArray *result;
+ guint i;
+
+ result = g_byte_array_new ();
+
+ for (i = 0; i < v->vectors->len; i++)
+ {
+ GVariantVector vec = g_array_index (v->vectors, GVariantVector, i);
+
+ if (vec.gbytes)
+ g_byte_array_append (result, vec.data.pointer, vec.size);
+ else
+ g_byte_array_append (result, v->extra_bytes->data + vec.data.offset, vec.size);
+ }
+
+ return result;
+}
+
+static void
+test_vector_serialiser (void)
+{
+ GVariantVectors vectors;
+ GByteArray *flattened;
+ GVariant *value;
+ guint i;
+
+ for (i = 0; i < 100; i++)
+ {
+ value = create_random_gvariant (4);
+
+ GLIB_PRIVATE_CALL(g_variant_to_vectors) (value, &vectors);
+ flattened = flatten_vectors (&vectors);
+ g_byte_array_free (vectors.extra_bytes, TRUE);
+ g_byte_array_free (vectors.offsets, TRUE);
+ g_array_free (vectors.vectors, TRUE);
+
+#if 0
+ if (flattened->len != g_variant_get_size (value) ||
+ memcmp (flattened->data, g_variant_get_data (value), flattened->len) != 0)
+ {
+ g_file_set_contents ("flattened", flattened->data, flattened->len, NULL);
+ g_file_set_contents ("serialised", g_variant_get_data (value), g_variant_get_size (value), NULL);
+ g_print ("type is %s\n", g_variant_get_type_string (value));
+ g_assert_not_reached ();
+ }
+#endif
+
+ g_assert_cmpint (flattened->len, ==, g_variant_get_size (value));
+ g_assert (memcmp (flattened->data, g_variant_get_data (value), flattened->len) == 0);
+
+ g_byte_array_free (flattened, TRUE);
+ g_variant_unref (value);
+ }
+}
+