I’m working on a project with a “customer made” database. He developed a C++/CLI application that stores and retrieves his data from a binary file using the BinaryWriter.Write(String) and BinaryReader.ReadString() methods.
I’m no C++/CLI expert but from what I understand these methods use a 7-bits encoding of the first bytes to determine the String length.
I need to access his data from a rail application, anyone’s got an idea of how to do the same think in ruby?
If you’re dealing with raw binary data, you’ll probably need to spend some time familiarizing yourself with the
packandunpackmethods and their various options. Maybe what you’re describing is a “Pascal string” where the length is encoded up front, or a variation on that.For example:
The double-
unpackis required because you don’t know the length of the string to unpack until you do the first step. You could probably do this using a substring as well, likedata[1,length]if you’re reasonably certain you’re not dealing with UTF-8 data.