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.
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, Paul S. [email protected] wrote:
I would start here:
http://raa.ruby-lang.org/search.rhtml?search=binary
(Also, check on rubyforge.org)
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 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
On 3/22/07, [email protected] [email protected] wrote:
look for joel’s bitstruct on rubyforge
-a
be kind whenever possible… it is always possible.
Which is a fast, better solution for simple structures, binary-parse
can handle very complex nested structures, arrays and the like.
pth