Convert::Binary::C 0.64 review

Download
by rbytes.net on

Convert::Binary::C is a Binary Data Conversion using C Types. SYNOPSIS Simple use Convert::Binary::C; #--------------

License: Perl Artistic License
File size: 1371K
Developer: Marcus Holland-Moritz
0 stars award from rbytes.net

Convert::Binary::C is a Binary Data Conversion using C Types.

SYNOPSIS

Simple
use Convert::Binary::C;

#---------------------------------------------
# Create a new object and parse embedded code
#---------------------------------------------
my $c = Convert::Binary::C->new->parse( 'DEC', day => 24 };

my $packed = $c->pack( 'Date', $date );
Advanced
use Convert::Binary::C;
use Data::Dumper;

#---------------------
# Create a new object
#---------------------
my $c = new Convert::Binary::C ByteOrder => 'BigEndian';

#---------------------------------------------------
# Add include paths and global preprocessor defines
#---------------------------------------------------
$c->Include( '/usr/lib/gcc-lib/i686-pc-linux-gnu/3.3.6/include',
'/usr/include' )
->Define( qw( __USE_POSIX __USE_ISOC99=1 ) );

#----------------------------------
# Parse the 'time.h' header file
#----------------------------------
$c->parse_file( 'time.h' );

#---------------------------------------
# See which files the object depends on
#---------------------------------------
print Dumper( [$c->dependencies] );

#-----------------------------------------------------------
# See if struct timespec is defined and dump its definition
#-----------------------------------------------------------
if( $c->def( 'struct timespec' ) ) {
print Dumper( $c->struct( 'timespec' ) );
}

#-------------------------------
# Create some binary dummy data
#-------------------------------
my $data = "binaryteststring";

#--------------------------------------------------------
# Unpack $data according to 'struct timespec' definition
#--------------------------------------------------------
if( length($data) >= $c->sizeof( 'timespec' ) ) {
my $perl = $c->unpack( 'timespec', $data );
print Dumper( $perl );
}

#--------------------------------------------------------
# See which member lies at offset 5 of 'struct timespec'
#--------------------------------------------------------
my $member = $c->member( 'timespec', 5 );
print "member( 'timespec', 5 ) = '$member'n";

Convert::Binary::C is a preprocessor and parser for C type definitions. It is highly configurable and should support 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 the 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.

Requirements:
Perl

Convert::Binary::C 0.64 search tags