I posted over at the current general forums about pack/unpack ( 47065 ) as I thought the discussions warrants a wider audience. But I know some of us are spending most of time here on these forums, so I decided to post a note here about the other posting. I really hate cross-posting, so please forgive me.


rb doesn’t have a generic way to (de)serialize an object that some other languages do.

What I do is add a “.serizlize as string” and “.deserialize(data as string)” methods to any classes I need to serialize, and then the class handles the specifics. I’ve tried XML which is ok, and also JSON (which I like a little better).

Michael thanks. the file(s) that I need to (de)serialize are all binary files. with data put in them as a 44byte structure. that 44 bytes is then “unpacked” in to serial fields (as a lack of a better term). either characters, numbers, or even half-byte objects. and each data file has many (sometime many many many) of these entries in it.

I think I might have to find a way to put some glue code between the data files and RB. either use perl as middle man or write a plugin.

In the case of a fixed binary format, you can probably use Structures and the Structure.StringValue() command to get and set the data. Just beware that binary formats are fragile as they depend on implementation details such as little vs. big endian, floating point formats, etc. But you are probably aware of that :slight_smile:

If you don’t mind about size, XML or JSON are a very good choice. Instead, if you want to save space use a binary format.
However, XML or JSON data can be zipped very effectively, and you also have a better debugging with a human readable format, even if your data are binary.

the data files are coming to the user from a third party, so I have to be able to read them. at this point I have no need to write to them. but we all know that requirements change (scope creep) over time. XML or JSON are valid choice for writing them out to if I was keeping to the data to my app only. I would probably use SQLite instead since I can dump all in there, and pull whichever one out easily.

Plus I understand SQL better than I under XML/JSON docs.