Hi all,
I've learned some basic of Ruby and I need to write a program that can read
data from binary files written by a C program. I was supposed to use the
company library to do this using C++ but I really feel that this job could
be done more quickly with the advanced features of Ruby. The binary files
are generally directly dumped by C structs. Is there a "ruby way" of doing
this? Thanks in advance.
···
--
Alex
I would start here:
http://raa.ruby-lang.org/search.rhtml?search=binary
(Also, check on rubyforge.org)
You might want to look at Array#pack and String#unpack.
Also, make sure to open up the file as binary!
Enjoy.
···
On 3/22/07, Yacao Wang <yacaowang@gmail.com> wrote:
Hi all,
I've learned some basic of Ruby and I need to write a program that can read
data from binary files written by a C program. I was supposed to use the
company library to do this using C++ but I really feel that this job could
be done more quickly with the advanced features of Ruby. The binary files
are generally directly dumped by C structs. Is there a "ruby way" of doing
this? Thanks in advance.
--
Alex
look for joel's bitstruct on rubyforge
-a
···
On Fri, 23 Mar 2007, Yacao Wang wrote:
Hi all,
I've learned some basic of Ruby and I need to write a program that can read
data from binary files written by a C program. I was supposed to use the
company library to do this using C++ but I really feel that this job could
be done more quickly with the advanced features of Ruby. The binary files
are generally directly dumped by C structs. Is there a "ruby way" of doing
this? Thanks in advance.
--
be kind whenever possible... it is always possible.
- the dalai lama
in there you will see the binary-parse gem, I wrote it to do exactly
what you are describing for my own needs.
pth
···
On 3/22/07, Paul Stickney <pstickne@gmail.com> wrote:
I would start here:
http://raa.ruby-lang.org/search.rhtml?search=binary
(Also, check on rubyforge.org)
Which is a fast, better solution for simple structures, binary-parse
can handle very complex nested structures, arrays and the like.
pth
···
On 3/22/07, ara.t.howard@noaa.gov <ara.t.howard@noaa.gov> wrote:
On Fri, 23 Mar 2007, Yacao Wang wrote:
> Hi all,
>
> I've learned some basic of Ruby and I need to write a program that can read
> data from binary files written by a C program. I was supposed to use the
> company library to do this using C++ but I really feel that this job could
> be done more quickly with the advanced features of Ruby. The binary files
> are generally directly dumped by C structs. Is there a "ruby way" of doing
> this? Thanks in advance.
look for joel's bitstruct on rubyforge
-a
--
be kind whenever possible... it is always possible.
- the dalai lama