tags:

views:

28

answers:

1

I have a binary file, inside of which has multiple frames. Each frame starts with FF FF FF followed by random data of varying length. For example:

FF FF FF XX XX XX XX ......... FF FF FF XX XX XX XX XX XX ......... FF FF FF XX XX XX .... FF FF FF XX XX XX XX XX XX XX XX XX ........

It's safe to assume that FF FF FF will only appear in the frame header and not as part of the random data.

I'm looking for a way of parsing this binary file and extracting each frame into an array using ruby.

Can anyone help?

+2  A: 

For Ruby 1.8, you can just split the input string on "\xFF\xFF\xFF". The first entry will be before the first frame, and with such a format you cannot know whether the last frame is complete or not. They are simple enough to remove, though:

input.split("\xFF\xFF\xFF")[1..-2]
grddev