in reply to Extending with C functions - some basic questions
It may also be useful to contemplate pack and unpack. “Tearing apart an in-memory structure” is what they do. Your module would use that bit of voodoo (and yes, it is voodoo) to automagically come up with a Perl data structure containing the requisite elements, concealing all that ugliness from any and all humble supplicants.
There’s a fair amount of this stuff in CPAN, e.g. in crufty code like DBI drivers, which you can refer to.