[Vala] How to get the size of structure?



Hello.

I'm wrapping a non-glib library.

That library makes use of lot of structures,
and any instance of those structures must be initialized
with the size of the structure, and the version of the API used.

    http://github.com/tigrux/omx-vala/blob/master/libomxil-bellagio.vapi#L197

For example:

    Omx.Audio.Param.Mp3 param = {};
    param.size = sizeof (Omx.Audio.Param.Mp3);
    param.version = API_VERSION;

Vala restricts the use of sizeof to types only, so it fails
to compile when I try:

    param.size = sizeof (param);

So, the question is:

How to make Vala automatically assign the size of the structure to the
field `size`
of those structures?

The idea is that something like:

    Omx.Audio.Param.Mp3 param = Omx.Audio.Param.Mp3();

is automatically expanded to something like:

    OMX_AUDIO_PARAM_MP3 param;
    memset(&param, 0, sizeof(param));
    param.nSize = sizeof(param);
    param.nVersion = API_VERSION

Thanks in advance.



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