Debian Codegraph @

lib/Protocol/HTTP2/Frame/Ping.pm

raw
1 package Protocol::HTTP2::Frame::Ping;
2 use strict;
3 use warnings;
4 use Protocol::HTTP2::Constants qw(:flags :errors :limits);
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 # PING associated with connection
12 if ( $frame_ref->{stream} != 0 ) {
13 $con->error(PROTOCOL_ERROR);
14 return undef;
15 }
16
17 # payload is 8 octets
18 if ( $length != PING_PAYLOAD_SIZE ) {
19 $con->error(FRAME_SIZE_ERROR);
20 return undef;
21 }
22
23 $con->ack_ping( \substr $$buf_ref, $buf_offset, $length )
24 unless $frame_ref->{flags} & ACK;
25
26 return $length;
27 }
28
29 sub encode {
30 my ( $con, $flags_ref, $stream, $data_ref ) = @_;
31 if ( length($$data_ref) != PING_PAYLOAD_SIZE ) {
32 $con->error(INTERNAL_ERROR);
33 return undef;
34 }
35 return $$data_ref;
36 }
37
38 1;