Debian Codegraph @

lib/Protocol/HTTP2/Frame/Priority.pm

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