bit-struct and arrays of members?

Discussion in 'Ruby' started by Markus Fischer, May 24, 2009.

  1. Hi,

    I'm using the bit-struct [1] (which is just awesome, btw) and wondering
    how I can realize arrays of members.

    I'm reading binary data from pre-existing files which are based on C
    structs which look similar to this basic example:

    struct {
    int vector[5];
    ...
    } vector_t;

    My current solution is to just write:

    class Vector < BitStruct
    default_options :endian => :little
    signed vector_1, 32
    signed vector_2, 32
    signed vector_3, 32
    ....

    I would prefer to use an array. I couldn't figure out how to do it,
    there's no example with it and I start to think it's not possible ... ?

    thanks,
    - Markus

    [1] http://redshift.sourceforge.net/bit-struct/
    Markus Fischer, May 24, 2009
    #1
    1. Advertising

  2. Markus Fischer wrote:
    > Hi,
    >
    > I'm using the bit-struct [1] (which is just awesome, btw) and wondering
    > how I can realize arrays of members.
    >
    > I'm reading binary data from pre-existing files which are based on C
    > structs which look similar to this basic example:
    >
    > struct {
    > int vector[5];
    > ...
    > } vector_t;
    >
    > My current solution is to just write:
    >
    > class Vector < BitStruct
    > default_options :endian => :little
    > signed vector_1, 32
    > signed vector_2, 32
    > signed vector_3, 32
    > ...
    >
    > I would prefer to use an array. I couldn't figure out how to do it,
    > there's no example with it and I start to think it's not possible ... ?
    >
    > thanks,
    > - Markus
    >
    > [1] http://redshift.sourceforge.net/bit-struct/


    Sorry, no support for that (yet). IIRC one of the other libs has
    something for this, maybe it was binstruct or binaryparse.

    It's not really too different from the #nest construct, so maybe it
    could be added along those lines, as long as the array length is static.
    Will think about it...

    --
    vjoel : Joel VanderWerf : path berkeley edu : 510 665 3407
    Joel VanderWerf, May 25, 2009
    #2
    1. Advertising

  3. Markus Fischer wrote:
    > I'm using the bit-struct [1] (which is just awesome, btw) and wondering
    > how I can realize arrays of members.


    Here's a quick implementation and some examples. The main limitation
    (that I'm aware of) is that a Vector cannot yet be embedded in another
    BitStruct. Will think about that (note hypothetical syntax)...

    http://pastebin.com/ma74d15d

    --
    vjoel : Joel VanderWerf : path berkeley edu : 510 665 3407
    Joel VanderWerf, May 27, 2009
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Pratap Das
    Replies:
    1
    Views:
    430
    Richard Heathfield
    Oct 14, 2003
  2. Chris Fogelklou
    Replies:
    36
    Views:
    1,353
    Chris Fogelklou
    Apr 20, 2004
  3. Philipp
    Replies:
    21
    Views:
    1,105
    Philipp
    Jan 20, 2009
  4. Richard Mathis

    Issues with declaring struct arrays inside of a struct

    Richard Mathis, Oct 10, 2003, in forum: ASP .Net Building Controls
    Replies:
    0
    Views:
    231
    Richard Mathis
    Oct 10, 2003
  5. John Reye
    Replies:
    28
    Views:
    1,333
    Tim Rentsch
    May 8, 2012
Loading...

Share This Page