Monday, March 22, 2010


I stumbled across a new module this morning, Convert::Binary::C. The premise is simple and clever: rather than manually maintaining pack/unpack statements to read/write data from C structs, use this module to parse the c header files and create the pack/unpack routines for you. Oh and it takes into account compiler settings too. For the Win!

I don't have anything to use this in right now. But when I do? Blammo!


Convert::Binary::C is a preprocessor and parser for C type definitions. It is highly configurable and supports arbitrarily complex data structures. Its object-oriented interface has pack and unpack methods that act as replacements for Perl's pack and unpack and allow to use C types instead of a string representation of the data structure for conversion of binary data from and to Perl's complex data structures.

Actually, what Convert::Binary::C does is not very different from what a C compiler does, just that it doesn't compile the source code into an object file or executable, but only parses the code and allows Perl to use the enumerations, structs, unions and typedefs that have been defined within your C source for binary data conversion, similar to Perl's pack and unpack.

Beyond that, the module offers a lot of convenience methods to retrieve information about the C types that have been parsed.

No comments: