line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Flash::FLAP::IO::OutputStream; |
2
|
|
|
|
|
|
|
# Copyright (c) 2003 by Vsevolod (Simon) Ilyushchenko. All rights reserved. |
3
|
|
|
|
|
|
|
# This program is free software; you can redistribute it and/or modify it |
4
|
|
|
|
|
|
|
# under the same terms as Perl itself. |
5
|
|
|
|
|
|
|
# The code is based on the -PHP project (http://amfphp.sourceforge.net/) |
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
=head1 NAME |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
Flash::FLAP::IO::OutputStream |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
=head1 DESCRIPTION |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
Class used to convert the perl stuff into binary |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
=cut |
16
|
|
|
|
|
|
|
|
17
|
1
|
|
|
1
|
|
6
|
use strict; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
449
|
|
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
# constructor |
20
|
|
|
|
|
|
|
sub new |
21
|
|
|
|
|
|
|
{ |
22
|
0
|
|
|
0
|
0
|
|
my ($proto)=@_; |
23
|
|
|
|
|
|
|
# the buffer |
24
|
0
|
|
|
|
|
|
my $self = {}; |
25
|
0
|
|
|
|
|
|
bless $self, $proto; |
26
|
0
|
|
|
|
|
|
$self->{outBuffer} = ""; |
27
|
0
|
|
|
|
|
|
return $self; |
28
|
|
|
|
|
|
|
} |
29
|
|
|
|
|
|
|
# write a single byte |
30
|
|
|
|
|
|
|
sub writeByte |
31
|
|
|
|
|
|
|
{ |
32
|
0
|
|
|
0
|
0
|
|
my ($self, $b)=@_; |
33
|
|
|
|
|
|
|
# use pack with the c flag |
34
|
0
|
|
|
|
|
|
$self->{outBuffer} .= pack("c", $b); |
35
|
|
|
|
|
|
|
} |
36
|
|
|
|
|
|
|
# write 2 bytes |
37
|
|
|
|
|
|
|
sub writeInt |
38
|
|
|
|
|
|
|
{ |
39
|
0
|
|
|
0
|
0
|
|
my ($self, $n) = @_; |
40
|
|
|
|
|
|
|
# use pack with the n flag |
41
|
0
|
|
|
|
|
|
$self->{outBuffer} .= pack("n", $n); |
42
|
|
|
|
|
|
|
} |
43
|
|
|
|
|
|
|
# write 4 bytes |
44
|
|
|
|
|
|
|
sub writeLong |
45
|
|
|
|
|
|
|
{ |
46
|
0
|
|
|
0
|
0
|
|
my ($self, $l)=@_; |
47
|
|
|
|
|
|
|
# use pack with the N flag |
48
|
0
|
|
|
|
|
|
$self->{outBuffer} .= pack("N", $l); |
49
|
|
|
|
|
|
|
} |
50
|
|
|
|
|
|
|
# write a string |
51
|
|
|
|
|
|
|
sub writeUTF |
52
|
|
|
|
|
|
|
{ |
53
|
0
|
|
|
0
|
0
|
|
my ($self, $s)=@_; |
54
|
|
|
|
|
|
|
# write the string length - max 65536 |
55
|
0
|
|
|
|
|
|
$self->writeInt(length($s)); |
56
|
|
|
|
|
|
|
# write the string chars |
57
|
0
|
|
|
|
|
|
$self->{outBuffer} .= $s; |
58
|
|
|
|
|
|
|
} |
59
|
|
|
|
|
|
|
#write a long string |
60
|
|
|
|
|
|
|
sub writeLongUTF |
61
|
|
|
|
|
|
|
{ |
62
|
0
|
|
|
0
|
0
|
|
my ($self, $s)=@_; |
63
|
|
|
|
|
|
|
# write the string length - max 65536 |
64
|
0
|
|
|
|
|
|
$self->writeLong(length($s)); |
65
|
|
|
|
|
|
|
# write the string chars |
66
|
0
|
|
|
|
|
|
$self->{outBuffer} .= $s; |
67
|
|
|
|
|
|
|
} |
68
|
|
|
|
|
|
|
# write a double |
69
|
|
|
|
|
|
|
sub writeDouble |
70
|
|
|
|
|
|
|
{ |
71
|
0
|
|
|
0
|
0
|
|
my ($self, $d)=@_; |
72
|
|
|
|
|
|
|
# pack the bytes |
73
|
0
|
|
|
|
|
|
my $b = pack("d", $d); |
74
|
0
|
|
|
|
|
|
my @b = split //, $b; |
75
|
|
|
|
|
|
|
# atleast on *nix the bytes have to be reversed |
76
|
|
|
|
|
|
|
# maybe not on windows, in php there in not flag to |
77
|
|
|
|
|
|
|
# force whether the bytes are little or big endian |
78
|
|
|
|
|
|
|
# for a double |
79
|
0
|
|
|
|
|
|
my $r = ""; |
80
|
|
|
|
|
|
|
# reverse the bytes |
81
|
0
|
|
|
|
|
|
for(my $byte = 7 ; $byte >= 0 ; $byte--) |
82
|
|
|
|
|
|
|
{ |
83
|
0
|
|
|
|
|
|
$r .= $b[$byte]; |
84
|
|
|
|
|
|
|
} |
85
|
|
|
|
|
|
|
# add the bytes to the output |
86
|
0
|
|
|
|
|
|
$self->{outBuffer} .= $r; |
87
|
|
|
|
|
|
|
} |
88
|
|
|
|
|
|
|
# send the output buffer |
89
|
|
|
|
|
|
|
sub flush |
90
|
|
|
|
|
|
|
{ |
91
|
0
|
|
|
0
|
0
|
|
my ($self) = @_; |
92
|
|
|
|
|
|
|
# flush typically empties the buffer |
93
|
|
|
|
|
|
|
# but this is not a persistent pipe so it's not needed really here |
94
|
|
|
|
|
|
|
# plus it's useful to be able to flush to a file and to the client simultaneously |
95
|
|
|
|
|
|
|
# with out have to create another method just to peek at the buffer contents. |
96
|
0
|
|
|
|
|
|
return $self->{outBuffer}; |
97
|
|
|
|
|
|
|
} |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
1; |