Reading binary data is not that easy in Ruby. The `Pragmatic Programmers - Programming Ruby` guide, has documented `pack', `unpack' methods for `String' class, with which we can convert data (integer, float etc.) into binary format and vice-versa. But the problem was, everytime, I will have to refer the documentation, and see, things into details. In C/C++, assigning the data to a type specific pointer variable, and accessing the value, will do (which is so easy). In Java, they have made it more easier. `DataInputStream' class, defines specific methods for that.
Well, that was my inspiration. Moreover, referring the documentation for unpacking a binary stream, was like looking into logarithms. I came up with this.
Not a good piece of code, but it works, and is gone in production.
Comments