static void write_stream(HioOutputStream *stream, const StreamDesc *desc) { StreamGenerator generator; gsize remaining; stream_generator_init(&generator, desc->seed); remaining = desc->length; while (remaining > 0) { char buf[48]; gsize count; HrtBuffer *buffer; count = MIN(G_N_ELEMENTS(buf), remaining); stream_generator_generate(&generator, &buf[0], count); buffer = hrt_buffer_new(HRT_BUFFER_ENCODING_UTF8, &allocator, NULL, NULL); hrt_buffer_append_ascii(buffer, &buf[0], count); hrt_buffer_lock(buffer); hio_output_stream_write(stream, buffer); hrt_buffer_unref(buffer); g_assert(count <= remaining); remaining -= count; } }
HrtBuffer* hrt_buffer_new_copy_utf8(const char *str) { HrtBuffer *buffer; buffer = hrt_buffer_new(HRT_BUFFER_ENCODING_UTF8, &g_allocator, NULL, NULL); /* FIXME append utf8 not ascii */ hrt_buffer_append_ascii(buffer, str, strlen(str)); return buffer; }