genie/typeof.gs \
genie/while.gs \
glib/conditional-glib-api.vala \
+ bindings/gio/memoryoutputstream.vala \
$(LINUX_TESTS) \
$(NULL)
--- /dev/null
+void test_stack_data () {
+ uint8 buffer[7];
+ var mos = MemoryOutputStream.with_data (buffer);
+ var dos = new DataOutputStream (mos);
+ try {
+ dos.put_string ("foobar\0");
+ assert (buffer.length == 7);
+ assert ((string) buffer == "foobar");
+ } catch {
+ assert_not_reached ();
+ }
+}
+
+void test_heap_data () {
+ uint8[] buffer = new uint8[7];
+ var mos = MemoryOutputStream.with_data (buffer);
+ var dos = new DataOutputStream (mos);
+ try {
+ dos.put_string ("foobar\0");
+ assert ((string) buffer == "foobar");
+ } catch {
+ assert_not_reached ();
+ }
+}
+
+void test_owned_data () {
+ uint8[] buffer = new uint8[7];
+ var mos = MemoryOutputStream.with_owned_data ((owned) buffer);
+ var dos = new DataOutputStream (mos);
+ try {
+ dos.put_string ("foobar\0");
+ unowned uint8[] data = mos.get_data ();
+ assert ((string) data == "foobar");
+ } catch {
+ assert_not_reached ();
+ }
+}
+
+void main () {
+ test_stack_data ();
+ test_heap_data ();
+ test_owned_data ();
+}
public class MemoryOutputStream : GLib.OutputStream, GLib.PollableOutputStream, GLib.Seekable {
[CCode (has_construct_function = false, type = "GOutputStream*")]
public MemoryOutputStream ([CCode (array_length_type = "gsize")] owned uint8[]? data, GLib.ReallocFunc? realloc_function = GLib.g_realloc, GLib.DestroyNotify? destroy_function = GLib.g_free);
+ [CCode (cname = "g_memory_output_stream_new", has_construct_function = false, type = "GOutputStream*")]
+ public MemoryOutputStream.from_data (void* data, size_t size, GLib.ReallocFunc? realloc_function = null, GLib.DestroyNotify? destroy_function = null);
[CCode (array_length = false)]
public unowned uint8[] get_data ();
[Version (since = "2.18")]
[CCode (array_length = false)]
[Version (since = "2.26")]
public uint8[] steal_data ();
+ [CCode (cname = "vala_g_memory_output_stream_with_data")]
+ public static GLib.MemoryOutputStream with_data ([CCode (array_length_type = "gsize")] uint8[] data) {
+ return new GLib.MemoryOutputStream.from_data (data, data.length, null, null);
+ }
+ [CCode (cname = "vala_g_memory_output_stream_with_owned_data")]
+ public static GLib.MemoryOutputStream with_owned_data ([CCode (array_length_type = "gsize")] owned uint8[] data) {
+ size_t size = data.length;
+ return new GLib.MemoryOutputStream.from_data ((owned) data, size, GLib.g_realloc, GLib.g_free);
+ }
[Version (since = "2.24")]
public void* data { get; construct; }
[Version (since = "2.24")]
public class MemoryOutputStream : GLib.OutputStream {
[CCode (has_construct_function = false, type = "GOutputStream*")]
public MemoryOutputStream ([CCode (array_length_type = "gsize")] owned uint8[]? data, GLib.ReallocFunc? realloc_function = GLib.g_realloc, GLib.DestroyNotify? destroy_function = GLib.g_free);
+ [CCode (cname = "g_memory_output_stream_new", has_construct_function = false, type = "GOutputStream*")]
+ public MemoryOutputStream.from_data (void* data, size_t size, GLib.ReallocFunc? realloc_function = null, GLib.DestroyNotify? destroy_function = null);
+ [CCode (cname = "vala_g_memory_output_stream_with_data")]
+ public static MemoryOutputStream with_data ([CCode (array_length_type = "gsize")] uint8[] data) {
+ return new MemoryOutputStream.from_data (data, data.length);
+ }
+ [CCode (cname = "vala_g_memory_output_stream_with_owned_data")]
+ public static MemoryOutputStream with_owned_data ([CCode (array_length_type = "gsize")] owned uint8[] data) {
+ size_t size = data.length;
+ return new MemoryOutputStream.from_data ((owned) data, size, GLib.g_realloc, GLib.g_free);
+ }
}
public abstract class NativeVolumeMonitor : GLib.VolumeMonitor {