perl pack() in C
In order to interact with some net code written in Perl, certain information needs to be encoded using the pack() function. At the moment I'm not especially concerned with unpacking so much as packing data to send along. I'd like to write code in C to communicate with the Perl code, however, and it seems pointless to reinvent the wheel: I have trouble believing there's no C or C++ library available that implements the same functionality, but Googling has failed me and a friend of mine so far. My question is this:
Is there any easy way to pack() data in a C program to be unpack()ed in Perl, or is it going to be necessary to write the functionality we're interested in ourselves? It's surprising me how hard it's been to identify some library that handles this.
Yes, of course. pack() was designed explicitly to deal with C, so there's no real library needed. Simply define a struct with the appropriate fields, cast a memory pointer to the struct type, and read/write the fields. Make sure to disable struct padding.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement