AMF-Perl
view release on metacpan or search on metacpan
lib/AMF/Perl/IO/Serializer.pm view on Meta::CPAN
my $count = $self->{amfout}->numHeader();
# write header count
$self->{out}->writeInt($count);
for (my $i=0; $i<$count; $i++)
{
$self->writeHeader($i);
}
$count = $self->{amfout}->numBody();
# write the body count
$self->{out}->writeInt($count);
for (my $i=0; $i<$count; $i++)
{
# start writing the body
$self->writeBody($i);
}
}
sub writeHeader
{
my ($self, $i)=@_;
# for all header values
# write the header to the output stream
# ignoring header for now
}
sub writeBody
{
my ($self, $i)=@_;
my $body = $self->{amfout}->getBodyAt($i);
# write the responseURI header
$self->{out}->writeUTF($body->{"target"});
# write null, haven't found another use for this
$self->{out}->writeUTF($body->{"response"});
# 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);
# write the string value
#$self->{out}->writeUTF(utf8_encode($d));
from_to($d, $self->{encoding}, "utf8") if $self->{encoding};
$self->{out}->writeUTF($d);
}
sub writeXML
{
my ($self, $d)=@_;
$self->{out}->writeByte(15);
#$self->{out}->writeLongUTF(utf8_encode($d));
from_to($d, $self->{encoding}, "utf8") if $self->{encoding};
$self->{out}->writeLongUTF($d);
}
# must be used PHPRemoting with the service to set the return type to date
# still needs a more in depth look at the timezone
sub writeDate
{
my ($self, $d)=@_;
# write date code
$self->{out}->writeByte(11);
# write date (milliseconds from 1970)
$self->{out}->writeDouble($d);
# write timezone
# ?? this is wierd -- put what you like and it pumps it back into flash at the current GMT ??
# have a look at the amf it creates...
$self->{out}->writeInt(0);
}
# write a number formatted as a double with the bytes reversed
# this may not work on a Win machine because i believe doubles are
# already reversed, to fix this comment out the reversing part
# of the writeDouble method
sub writeNumber
{
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
my $len = scalar(@$d);
# write the numeric array code
$self->{out}->writeByte(10);
# write the count of items in the array
$self->{out}->writeLong($len);
# write all of the array elements
for(my $i=0 ; $i < $len ; $i++)
{
#If this is a basic data type in a recordset, consider the column type.
if (!(ref $d->[$i]) && $self->{__writingRecordset__})
{
my $type = $self->{__columnTypes__}->[$i];
$self->dispatchBySqlType($d->[$i], $type);
}
( run in 2.000 seconds using v1.01-cache-2.11-cpan-39bf76dae61 )