ruby - How do I use BinData? -


i'm trying parse binary file, , can't quite figure out how use bindata properly.

the way binary set such:

  1. first 4 bytes (uint32) represent length of property name.
  2. next 8 * length represent property name (as string).
  3. next 4 bytes (uint32) represent length of property type.
  4. next 8 * length represent property type (as string).
  5. next 8 bytes (uint64) represent length of data.
  6. after data number of bytes (depending on type of data is, int (4), string (4 * len), float (4), or array).

after process repeats next property.

i guess questions are:

  1. when call mybindataclass.read() how feed correct portion read , not whole file, , since don't know how long each property (they vary type), how divide properly?

  2. how make single bindata handle different property types?