| 1 | package Linux::Event::Framer::Varint; | ||||||||||||||||||||||||||||||||||||||||||
| 2 | 10 | ▶ | use v5.36; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 3 | 10 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 4 | 10 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||||||||||||||||
| 6 | 10 | our $VERSION = '0.120'; | |||||||||||||||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||||||||||||||||
| 8 | 10 | ▶ | use Carp qw(croak); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 9 | 10 | ▶ | use bytes (); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||||||||||||||||
| 11 | 10 | ▶ | sub _build_definition ($class, @args) { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_build_definition: called CC=8 SCAR=22.0
| |||||||||||||||||||||||||||||||||||||||||||
| 12 | 10 | ▶ | croak 'Varint options must be key/value pairs' if @args % 2; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 13 | 10 | my %opt = @args; | |||||||||||||||||||||||||||||||||||||||||
| 14 | 10 | ▶ | my $include_prefix = delete $opt{include_prefix} // 0; | ||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
delete $opt{"include_prefix"} // 0
MC/DC100%1/1
delete $opt{"include_prefix"} // 0
delete $opt{"include_prefix"}
Truth table100%2/2
A
A= delete $opt{"include_prefix"}
| |||||||||||||||||||||||||||||||||||||||||||
| 15 | 10 | my $max_frame = delete $opt{max_frame}; | |||||||||||||||||||||||||||||||||||||||||
| 16 | 10 | ▶ | croak 'max_frame must be a non-negative integer' | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition50%3/6
defined $max_frame and !($max_frame =~ /\A\d+\z/u) || $max_frame < 0
not $max_frame =~ /\A\d+\z/u or $max_frame < 0
MC/DC0%0/3
defined $max_frame and !($max_frame =~ /\A\d+\z/u) || $max_frame < 0
defined $max_frame
not $max_frame =~ /\A\d+\z/u
$max_frame < 0
Truth table50%2/4
A and not(B) or C
A= defined $max_frameB= not $max_frame =~ /\A\d+\z/uC= $max_frame < 0
| |||||||||||||||||||||||||||||||||||||||||||
| 17 | if defined($max_frame) && ($max_frame !~ /\A\d+\z/ || $max_frame < 0); | ||||||||||||||||||||||||||||||||||||||||||
| 18 | 10 | ▶ | croak 'unknown Varint options: ' . join(', ', sort keys %opt) if %opt; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||||||||||||||||
| 20 | 10 | ▶ | my $native = { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 21 | read_mode => 6, | ||||||||||||||||||||||||||||||||||||||||||
| 22 | include_prefix => $include_prefix ? 1 : 0, | ||||||||||||||||||||||||||||||||||||||||||
| 23 | max_frame => $max_frame, | ||||||||||||||||||||||||||||||||||||||||||
| 24 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 25 | 10 | return { native => $native, frame => \&_frame }; | |||||||||||||||||||||||||||||||||||||||||
| 26 | } | ||||||||||||||||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||||||||||||||||
| 28 | 26 | ▶ | sub _frame ($config, $payload) { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_frame: called CC=7 SCAR=19.5
| |||||||||||||||||||||||||||||||||||||||||||
| 29 | 26 | ▶ | $payload = '' if !defined $payload; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 30 | 26 | my $length = bytes::length($payload); | |||||||||||||||||||||||||||||||||||||||||
| 31 | croak "send(): payload length $length exceeds max_frame=$config->{max_frame}" | ||||||||||||||||||||||||||||||||||||||||||
| 32 | 26 | ▶ | if defined($config->{max_frame}) && $length > $config->{max_frame}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
defined $config->{"max_frame"} and $length > $config->{"max_frame"}
MC/DC50%1/2
defined $config->{"max_frame"} and $length > $config->{"max_frame"}
defined $config->{"max_frame"}
$length > $config->{"max_frame"}
Truth table66%2/3
A and B
A= defined $config->{"max_frame"}B= $length > $config->{"max_frame"}
| |||||||||||||||||||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||||||||||||||||
| 34 | 25 | ▶ | return pack('C', $length) . $payload if $length < 128; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||||||||||||||||
| 36 | 9 | my @octets; | |||||||||||||||||||||||||||||||||||||||||
| 37 | 9 | my $value = $length; | |||||||||||||||||||||||||||||||||||||||||
| 38 | 9 | ▶ | do { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 39 | 22 | my $byte = $value & 0x7f; | |||||||||||||||||||||||||||||||||||||||||
| 40 | 22 | $value >>= 7; | |||||||||||||||||||||||||||||||||||||||||
| 41 | 22 | ▶ | $byte |= 0x80 if $value; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 42 | 22 | push @octets, $byte; | |||||||||||||||||||||||||||||||||||||||||
| 43 | } while ($value); | ||||||||||||||||||||||||||||||||||||||||||
| 44 | 9 | return pack('C*', @octets) . $payload; | |||||||||||||||||||||||||||||||||||||||||
| 45 | } | ||||||||||||||||||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||||||||||||||||
| 47 | 10 | 1; | |||||||||||||||||||||||||||||||||||||||||
| 48 | |||||||||||||||||||||||||||||||||||||||||||
| 49 | __END__ | ||||||||||||||||||||||||||||||||||||||||||