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