File Coverage

blib/lib/Protocol/SPDY/Frame/Data.pm
Criterion Covered Total %
statement 24 28 85.7
branch 2 4 50.0
condition n/a
subroutine 8 11 72.7
pod 7 7 100.0
total 41 50 82.0


line stmt bran cond sub pod time code
1             package Protocol::SPDY::Frame::Data;
2             {
3             $Protocol::SPDY::Frame::Data::VERSION = '0.999_007';
4             }
5 3     3   9 use strict;
  3         3  
  3         73  
6 3     3   8 use warnings;
  3         3  
  3         60  
7 3     3   9 use parent qw(Protocol::SPDY::Frame);
  3         2  
  3         10  
8              
9             =head1 NAME
10              
11             Protocol::SPDY::Frame::Data - data frame support
12              
13             =head1 VERSION
14              
15             version 0.999_007
16              
17             =head1 DESCRIPTION
18              
19             See L and L.
20              
21             =cut
22              
23 3     3   160 use Protocol::SPDY::Constants ':all';
  3         3  
  3         1041  
24              
25             =head1 METHODS
26              
27             =cut
28              
29             =head2 stream_id
30              
31             The stream ID for this data packet.
32              
33             =cut
34              
35 2     2 1 9 sub stream_id { shift->{stream_id} }
36              
37             =head2 payload
38              
39             The bytes comprising this data packet. Note that there are no guarantees
40             on boundaries: UTF-8 decoding for example could fail if this packet is
41             processed in isolation.
42              
43             =cut
44              
45 4     4 1 15 sub payload { shift->{payload} }
46              
47             =head2 from_data
48              
49             Generates an instance from the given data.
50              
51             =cut
52              
53             sub from_data {
54 2     2 1 4 my $class = shift;
55 2         6 my %args = @_;
56 2         12 my ($stream_id, $flags, $len, $len2) = unpack "N1C1n1c1", substr $args{data}, 0, 8, '';
57 2         8 $len = ($len << 8) | $len2;
58             return $class->new(
59             fin => $flags & FLAG_FIN,
60             stream_id => $stream_id,
61             payload => $args{data},
62 2         9 );
63             }
64              
65             =head2 as_packet
66              
67             Returns the scalar bytes representing this frame.
68              
69             =cut
70              
71             sub as_packet {
72 2     2 1 3 my $self = shift;
73 2         7 my $len = length(my $payload = $self->payload);
74 2 50       15 my $pkt = pack 'N1C1n1C1',
    50          
75             ($self->is_control ? 0x80000000 : 0x00000000) | ($self->stream_id & 0x7FFFFFFF),
76             ($self->fin ? FLAG_FIN : 0),
77             $len >> 8,
78             $len & 0xFF;
79 2         7 $pkt .= $payload;
80             # warn "done packet: $pkt\n";
81             # hexdump($pkt);
82 2         8 return $pkt;
83             }
84              
85             =head2 type_string
86              
87             Returns 'data' - data frames don't have a type field, so we pick a value
88             that isn't going to conflict with any control frame types.
89              
90             =cut
91              
92 0     0 1   sub type_string { 'data' }
93              
94             =head2 type_name
95              
96             Returns 'data' - data frames don't have a type field, so we pick a value
97             that isn't going to conflict with any control frame types.
98              
99             =cut
100              
101 0     0 1   sub type_name { 'data' }
102              
103             =head2 to_string
104              
105             String representation, for debugging.
106              
107             =cut
108              
109             sub to_string {
110 0     0 1   my $self = shift;
111 0           $self->SUPER::to_string . ', stream=' . $self->stream_id . ', payload ' . length($self->payload) . " bytes";
112             }
113              
114             1;
115              
116             __END__