| 1 | package Linux::Event::Stream::Codec::U32BE; | ||||||||||||||||||||||||||||
| 2 | 7 | ▶ | use v5.36; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 3 | 7 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | 7 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||
| 6 | 7 | our $VERSION = '0.002'; | |||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||
| 8 | 7 | ▶ | use Carp qw(croak); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||
| 10 | ▶ | sub new ($class, %opt) { | |||||||||||||||||||||||||||
|
Subroutine
new: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||
| 11 | 0 | my $max_frame = delete $opt{max_frame}; | |||||||||||||||||||||||||||
| 12 | 0 | ▶ | croak 'unknown options: ' . join(', ', sort keys %opt) if %opt; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||
| 14 | 0 | return bless { | |||||||||||||||||||||||||||
| 15 | max_frame => $max_frame, | ||||||||||||||||||||||||||||
| 16 | decode => \&_decode, | ||||||||||||||||||||||||||||
| 17 | encode => \&_encode, | ||||||||||||||||||||||||||||
| 18 | }, $class; | ||||||||||||||||||||||||||||
| 19 | } | ||||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||
| 21 | ▶ | sub _decode ($self, $inref, $outref) { | |||||||||||||||||||||||||||
|
Subroutine
_decode: not called CC=5 SCAR=34.0
| |||||||||||||||||||||||||||||
| 22 | 0 | while (1) { | |||||||||||||||||||||||||||
| 23 | 0 | ▶ | last if length($$inref) < 4; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||
| 25 | 0 | my $len = unpack('N', substr($$inref, 0, 4)); | |||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||
| 27 | 0 | my $max = $self->{max_frame}; | |||||||||||||||||||||||||||
| 28 | 0 | ▶ | if (defined($max) && $len > $max) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
defined $max and $len > $max
MC/DC0%0/2
defined $max and $len > $max
defined $max
$len > $max
Truth table0%0/3
A and B
A= defined $maxB= $len > $max
| |||||||||||||||||||||||||||||
| 29 | 0 | return (0, "frame too large (>$max bytes)"); | |||||||||||||||||||||||||||
| 30 | } | ||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||
| 32 | 0 | my $need = 4 + $len; | |||||||||||||||||||||||||||
| 33 | 0 | ▶ | last if length($$inref) < $need; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||
| 35 | 0 | my $payload = substr($$inref, 4, $len); | |||||||||||||||||||||||||||
| 36 | 0 | substr($$inref, 0, $need, ''); | |||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||
| 38 | 0 | push @$outref, $payload; | |||||||||||||||||||||||||||
| 39 | } | ||||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||
| 41 | 0 | return 1; | |||||||||||||||||||||||||||
| 42 | } | ||||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||
| 44 | ▶ | sub _encode ($self, $msg) { | |||||||||||||||||||||||||||
|
Subroutine
_encode: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||
| 45 | 0 | ▶ | $msg = '' if !defined $msg; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 46 | 0 | $msg = "$msg"; | |||||||||||||||||||||||||||
| 47 | 0 | return pack('N', length($msg)) . $msg; | |||||||||||||||||||||||||||
| 48 | } | ||||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||
| 50 | 7 | 1; | |||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||
| 52 | __END__ | ||||||||||||||||||||||||||||