File Coverage

blib/lib/Protocol/HTTP2/Frame/Priority.pm
Criterion Covered Total %
statement 27 31 87.1
branch 2 4 50.0
condition n/a
subroutine 6 6 100.0
pod 0 2 0.0
total 35 43 81.4


line stmt bran cond sub pod time code
1             package Protocol::HTTP2::Frame::Priority;
2 10     10   43 use strict;
  10         13  
  10         325  
3 10     10   44 use warnings;
  10         12  
  10         253  
4 10     10   42 use Protocol::HTTP2::Constants qw(:flags :errors);
  10         13  
  10         1812  
5 10     10   52 use Protocol::HTTP2::Trace qw(tracer);
  10         16  
  10         2596  
6              
7             sub decode {
8 1     1 0 1 my ( $con, $buf_ref, $buf_offset, $length ) = @_;
9 1         3 my $frame_ref = $con->decode_context->{frame};
10              
11             # Priority frames MUST be associated with a stream
12 1 50       4 if ( $frame_ref->{stream} == 0 ) {
13 0         0 $con->error(PROTOCOL_ERROR);
14 0         0 return undef;
15             }
16              
17 1 50       3 if ( $length != 5 ) {
18 0         0 $con->error(FRAME_SIZE_ERROR);
19 0         0 return undef;
20             }
21              
22 1         4 my ( $stream_dep, $weight ) =
23             unpack( 'NC', substr( $$buf_ref, $buf_offset, 5 ) );
24 1         2 my $exclusive = $stream_dep >> 31;
25 1         1 $stream_dep &= 0x7FFF_FFFF;
26 1         2 $weight++;
27              
28 1         6 $con->stream_weight( $frame_ref->{stream}, $weight );
29 1         5 $con->stream_reprio( $frame_ref->{stream}, $exclusive, $stream_dep );
30              
31 1         4 return $length;
32             }
33              
34             sub encode {
35 1     1 0 2 my ( $con, $flags_ref, $stream, $data_ref ) = @_;
36 1         2 my $stream_dep = $data_ref->[0];
37 1         2 my $weight = $data_ref->[1] - 1;
38 1         7 pack( 'NC', $stream_dep, $weight );
39             }
40              
41             1;