AMF-Perl
view release on metacpan or search on metacpan
lib/AMF/Perl/IO/Deserializer.pm view on Meta::CPAN
{
my ($self)=@_;
# ignore the first two bytes -- version or something
$self->{inputStream}->readInt();
# find the total number of header elements
$self->{header_count} = $self->{inputStream}->readInt();
# loop over all of the header elements
while($self->{header_count}--)
{
my $name = $self->{inputStream}->readUTF();
# find the must understand flag
my $required = $self->readBoolean();
# grab the length of the header element
my $length = $self->{inputStream}->readLong();
# grab the type of the element
my $type = $self->{inputStream}->readByte();
# turn the element into real data
my $content = $self->readData($type);
# save the name/value into the headers array
$self->{amfdata}->addHeader($name, $required, $content);
}
lib/AMF/Perl/IO/OutputStream.pm view on Meta::CPAN
{
$self->{byteorder} = 'little-endian';
}
return $self;
}
# write a single byte
sub writeByte
{
my ($self, $b)=@_;
# use pack with the c flag
$self->{outBuffer} .= pack("c", $b);
}
# write 2 bytes
sub writeInt
{
my ($self, $n) = @_;
# use pack with the n flag
$self->{outBuffer} .= pack("n", $n);
}
# write 4 bytes
sub writeLong
{
my ($self, $l)=@_;
# use pack with the N flag
$self->{outBuffer} .= pack("N", $l);
}
# write a string
sub writeUTF
{
my ($self, $s)=@_;
$s = "" unless defined($s);
# write the string length - max 65536
if (length($s) <= 65535)
{
lib/AMF/Perl/IO/OutputStream.pm view on Meta::CPAN
$self->{outBuffer} .= $s;
}
sub writeDouble
{
my ($self, $d)=@_;
# pack the bytes
my $b = pack("d", $d);
my @b = split //, $b;
# atleast on *nix the bytes have to be reversed
# maybe not on windows, in php there in not flag to
# force whether the bytes are little or big endian
# for a double
my $r = "";
# reverse the bytes
if ($self->{byteorder} eq 'little-endian')
{
for(my $byte = 7 ; $byte >= 0 ; $byte--)
{
$r .= $b[$byte];
}
lib/AMF/Perl/IO/Serializer.pm view on Meta::CPAN
# always, always there is four bytes of FF, which is -1 of course
$self->{out}->writeLong(-1);
# write the data to the output stream
$self->writeData($body->{"value"}, $body->{"type"});
}
# writes a boolean
sub writeBoolean
{
my ($self, $d)=@_;
# write the boolean flag
$self->{out}->writeByte(1);
# write the boolean byte
$self->{out}->writeByte($d);
}
# writes a string under 65536 chars, a longUTF is used and isn't complete yet
sub writeString
{
my ($self, $d)=@_;
# write the string code
$self->{out}->writeByte(2);
lib/AMF/Perl/IO/Serializer.pm view on Meta::CPAN
my ($self, $d)=@_;
# write the number code
$self->{out}->writeByte(0);
# write the number as a double
$self->{out}->writeDouble($d);
}
# write null
sub writeNull
{
my ($self)=@_;
# null is only a 0x05 flag
$self->{out}->writeByte(5);
}
# write array
# since everything in php is an array this includes arrays with numeric and string indexes
sub writeArray
{
my ($self, $d)=@_;
# grab the total number of elements
lib/AMF/Perl/IO/Serializer.pm view on Meta::CPAN
# write the name of the object
$self->{out}->writeUTF($key);
if ($self->{__columnTypes__} && $key eq "initialData")
{
$self->{__writingRecordset__} = 1;
}
# write the value of the object
$self->writeData($data);
$self->{__writingRecordset__} = 0;
}
# write the end object flag 0x00, 0x00, 0x09
$self->{out}->writeInt(0);
$self->{out}->writeByte(9);
}
# write an AMF object
# The difference with regular object is that the code is different
# and the class name is explicitly sent. Good for RecordSets.
sub writeAMFObject
{
my ($self, $object)=@_;
( run in 1.352 second using v1.01-cache-2.11-cpan-94b05bcf43c )