Daniel Martin wrote:
> Fabio Vitale <fabio / sferaconsulting.it> writes:
> 
>> I've the need to parse a binary file with the following structure:
>> How can I accomplish this in Ruby?
> 
> In addition to parsing this yourself using ruby's String#unpack
> method, you should also look at the BitStruct extension available at
> http://redshift.sourceforge.net/bit-struct/

I've found bit-struct very intresting, anyway I cannot figure how to 
load a binary file in a newly created bit-structure.
Any help appreciated.

Say I've an imap.mrk binary file,
I've defined class MRK as follows:

require 'bit-struct'

  class MRK < BitStruct
    unsigned    :version,             4,     "Version"
    unsigned    :uid_Validity,        4,     "UIDValidity"
    unsigned    :uid_next,            4,     "UIDNext"
    unsigned    :last_write_counter,  4,     "LastWriteCounter"
    rest        :unused,                     "Unused"
  end

  mrk = MRK.new

And now: how to populate the mrk instance just created from the imap.mrk 
binary file?


Thank you

-- 
Posted via http://www.ruby-forum.com/.