/* coroutine context if @buffered is TRUE,
   system context if @buffered is FALSE */
static void spice_channel_send_msg(SpiceChannel *channel, spice_msg_out *out, gboolean buffered)
{
    uint8_t *data;
    int free_data;
    size_t len;
    SPICE_DEBUG("spice_channel_send_msg:%d",buffered);

    g_return_if_fail(channel != NULL);
    g_return_if_fail(out != NULL);

    data = spice_marshaller_linearize(out->marshaller, 0,
                                      &len, &free_data);
    /* spice_msg_out_hexdump(out, data, len); */
    if (buffered)
        spice_channel_buffered_write(channel, data, len);
    else
        spice_channel_write(channel, data, len);
    if (free_data) {
        free(data);
    }
}
                                   0xef, 0xcd, 0xab, 0x90, 0x78, 0x56, 0x34, 0x12, /* data */
};

int main(int argc G_GNUC_UNUSED, char **argv G_GNUC_UNUSED)
{
    SpiceMarshaller *marshaller;
    SpiceMsgMainShortDataSubMarshall *msg;
    size_t len;
    int free_res;
    uint8_t *data;

    msg = spice_malloc0(sizeof(SpiceMsgMainShortDataSubMarshall) + 2 * sizeof(uint64_t));
    msg->data_size = 2;
    msg->data[0] = 0x1234567890abcdef;
    msg->data[1] = 0x1234567890abcdef;

    marshaller = spice_marshaller_new();
    spice_marshall_msg_main_ShortDataSubMarshall(marshaller, msg);
    spice_marshaller_flush(marshaller);
    data = spice_marshaller_linearize(marshaller, 0, &len, &free_res);
    g_assert_cmpint(len, ==, G_N_ELEMENTS(expected_data));
    g_assert_true(memcmp(data, expected_data, len) == 0);
    if (free_res) {
        free(data);
    }
    spice_marshaller_destroy(marshaller);
    free(msg);

    return 0;
}