Re: [Vala] gio: how to read N bytes into a buffer at offset M?



On Tue, 2011-12-20 at 00:39 -0800, Matto Marjanovic wrote:
Hi,

The subject line explains what I am trying to do.  In plain old C,
I would simply use plain old libgio:

    GInputStream* s = ...;
    guint8 buffer[4096];
    GError* error = NULL;
    ...
    g_input_stream_read(s, buffer + M, N, NULL, &error);

How do I do this in Vala?

The 0.12 GIO bindings seemed to allow this, since read() and related methods
took a 'string' buffer parameter and a separate 'size_t' count parameter.

The 0.14 bindings, however, only all take a uint8[] parameter, and magically
derive the read size from the (full) array size.  Is there some other magic
syntax I am supposed to use to access to the functionality of the underlying
C API?

Use array slicing. Something like stream.read (buffer[M:M + N]);


-Evan




[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]