line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package RPC::Lite::MessageQuantizer;
|
2
|
|
|
|
|
|
|
|
3
|
3
|
|
|
3
|
|
15
|
use strict;
|
|
3
|
|
|
|
|
4
|
|
|
3
|
|
|
|
|
714
|
|
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
=pod
|
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
=head1 NAME
|
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
RPC::Lite::MessageQuantizer -- "Quantizes" messages to/from streams.
|
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
=head1 DESCRIPTION
|
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
RPC::Lite::MessageQuantizer packs and unpacks message to/from streams
|
14
|
|
|
|
|
|
|
that should be written using a transport layer.
|
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
=cut
|
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
sub new
|
19
|
|
|
|
|
|
|
{
|
20
|
0
|
|
|
0
|
0
|
|
my $class = shift;
|
21
|
0
|
|
|
|
|
|
my $self = {};
|
22
|
|
|
|
|
|
|
|
23
|
0
|
|
|
|
|
|
bless $self, $class;
|
24
|
|
|
|
|
|
|
}
|
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
=pod
|
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
=over 4
|
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
=item C
|
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
Retuns a hash ref with the following members:
|
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
=over 4
|
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
=item C
|
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
An array reference of the available messages.
|
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
=item C
|
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
The remainder of the stream.
|
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
=back
|
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
Returns undef if unable to quantize.
|
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
=cut
|
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
sub Quantize
|
51
|
|
|
|
|
|
|
{
|
52
|
0
|
|
|
0
|
1
|
|
my $self = shift;
|
53
|
0
|
|
|
|
|
|
my $stream = shift;
|
54
|
|
|
|
|
|
|
|
55
|
0
|
|
|
|
|
|
my @messages;
|
56
|
|
|
|
|
|
|
|
57
|
0
|
|
|
|
|
|
while( length( $stream ) )
|
58
|
|
|
|
|
|
|
{
|
59
|
0
|
|
|
|
|
|
my $messageLength = unpack( "N", $stream );
|
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
# if we find an incomplete message, break
|
62
|
0
|
0
|
|
|
|
|
if ( ( length( $stream ) - 4 ) < $messageLength )
|
63
|
|
|
|
|
|
|
{
|
64
|
0
|
|
|
|
|
|
last;
|
65
|
|
|
|
|
|
|
}
|
66
|
|
|
|
|
|
|
|
67
|
0
|
|
|
|
|
|
my ( undef, $message ) = unpack( "Na$messageLength", $stream );
|
68
|
|
|
|
|
|
|
|
69
|
0
|
|
|
|
|
|
$stream = substr( $stream, $messageLength + 4 ); # +4 to eat off the 4 bytes that compose the number we unpacked
|
70
|
|
|
|
|
|
|
|
71
|
0
|
|
|
|
|
|
push( @messages, $message );
|
72
|
|
|
|
|
|
|
}
|
73
|
|
|
|
|
|
|
|
74
|
0
|
|
|
|
|
|
return { 'messages' => \@messages, 'remainder' => $stream };
|
75
|
|
|
|
|
|
|
}
|
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
=pod
|
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
=item C
|
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
Packs a message for writing to a transport stream.
|
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
Returns the packed message.
|
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
=cut
|
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
sub Pack
|
88
|
|
|
|
|
|
|
{
|
89
|
0
|
|
|
0
|
1
|
|
my $self = shift;
|
90
|
0
|
|
|
|
|
|
my $message = shift;
|
91
|
|
|
|
|
|
|
|
92
|
0
|
|
|
|
|
|
my $messageLength = length( $message );
|
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
# pack a length-prefixed message
|
95
|
0
|
|
|
|
|
|
return pack( "Na$messageLength", $messageLength, $message );
|
96
|
|
|
|
|
|
|
}
|
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
=pod
|
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
=back
|
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
=cut
|
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
1; |