Using ruby to find frames in a binary protocol and store each frame in an array -


I have a binary file, many of which are frames each frame starts with FF FF FF, after which - There is random data of different lengths. For example:

FF FF FF XX XX XX XX ... FF FF FAF XX XX XX XX XX XX FF FF FX XX XX XX ... .ff ff ff xx xx xx xx xx xx xx xx xx xx xx xx xx ........

It is safe to assume that FF FF Only random data as it will appear in the frame header part.

I am looking for a way to parse this binary file and remove each frame from the array using ruby.

Can anyone help?

For Ruby 1.8, you can simply split the input string on "\ xFF \ xFF \ xFF" Are there. The first entry will be before the first frame, and with such a format you can not know whether the last frame is full or not. They are quite simple, however, to remove:

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

Comments

Popular posts from this blog

Eclipse CDT variable colors in editor -

AJAX doesn't send POST query -

wpf - Custom Message Box Advice -