Storable::AMF - serializing/deserializing AMF0/AMF3 data
use Storable::AMF0 qw(freeze thaw); # Handle AMF0 data use Storable::AMF3 qw(freeze thaw); # Handle AMF3 data $amf0 = freeze($perl_object); if ($@){ die "Can't freeze perl_object" }; $perl_object = thaw($amf0); if ($@){ die "It seems data is not valid AMF0 data"; } # Deparse one object and getting its length use Storable::AMF0 qw(deparse_amf); # reading stream of objects my $bytea = freeze($a1) . freeze($a2) . ...; # objects data stream my @objects; while( length $bytea ){ my( $obj, $length_of_packet ) = deparse_amf( my $bytea = freeze($a1) . freeze($a) ... ); if ( $@ ){ # We meet trouble with deparse die "This is not amf0 data"; } # have read one object and gets it's length # So put it in array and continue push @objects, $obj; # remove readed part of object bytearray substr $bytea, 0, $length_of_packet, ''; } # Dumping/Undumping amf0 objects to/from file store $perl_object, 'file'; $restored_perl_object = retrieve 'file'; # Same with locking lock_store \%table, 'file'; $hashref = lock_retrieve('file'); # Dates serializing/deserializing use Storable::AMF0 qw(new_amfdate perl_date); my $timestamp = time(); # UTC time --- seconds from epoch # new_amfdate( $time ) my $object = { now => new_amfdate( $timestamp ), name => "Object with DateTime" }; my $bytea = freeze ( $object ); # getting perl timestamp from thawed flash object; my $object = thaw $bytes; my $time = perl_date( $object->{field_with_date} ); - or use simple by your own risk my $time = $object->{field_with_date} ; # # return $time may be seconds from epoch, or milliseconds from epoch, or some kind of object . # Result are not defined at this time it depends of module version # Working with AMF0 and AMF3 format simultaneously use Storable::AMF0 (); use Storable::AMF3 (); $bytea = Storable::AMF0::freeze( ... ); $bytea = Storable::AMF3::freeze( ... ); ...
This module is (de)serializer for Adobe's AMF0/AMF3 (Action Message Format ver 0-3). To deserialize AMF3 objects you can export function from Storable::AMF3 package Almost all function implemented in XS/C for speed, except file operation.
Speed, simplicity and agile.
About 50-60 times faster than Data::AMF pure perl module. (2009) About 40% faster than Storable in big objects. (2009) About 6 times faster than Storable for small object (2009)
None by default.
At current moment and with restriction of AMF0/AMF3 format referrences to scalar are not serialized, and can't/ may not serialize tied variables. And dualvars (See Scalar::Util) are serialized as string value. Freezing CODEREF, IO, Regexp, GLOB referenses are restricted.
Data::AMF, Storable, Storable::AMF0, Storable::AMF3
Anatoliy Grishaev, <grian at cpan dot org>
Alberto Reggiori. ( basic externalized object support ) Adam Lounds. ( tests and some ideas and code for boolean support )
Copyright (C) 2011 by A. G. Grishaev
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself, either Perl version 5.8.8 or, at your option, any later version of Perl 5 you may have available.
To install Storable::AMF, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Storable::AMF
CPAN shell
perl -MCPAN -e shell install Storable::AMF
For more information on module installation, please visit the detailed CPAN module installation guide.