| 1 | package BERT::Decoder; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2 | 6 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 3 | 6 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 5 | 6 | ▶ | use 5.008; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 7 | 6 | ▶ | use Carp 'croak'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 8 | 6 | ▶ | use BERT::Constants; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 9 | 6 | ▶ | use BERT::Types; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 11 | 34 | ▶ | sub new { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
new: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 12 | 34 | my $class = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 13 | 34 | return bless { }, $class; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 14 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 16 | 34 | ▶ | sub decode { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
decode: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 17 | 34 | my ($self, $bert) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 19 | 34 | (my $magic, $bert) = unpack('Ca*', $bert); | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 21 | 34 | ▶ | croak sprintf('Bad magic number. Expected %d found %d', MAGIC_NUMBER, $magic) | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 22 | unless MAGIC_NUMBER == $magic; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 24 | 33 | return $self->extract_any($bert); | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 25 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 27 | 33 | ▶ | sub extract_any { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
extract_any: called CC=3 SCAR=11.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 28 | 33 | my ($self, $bert) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 30 | 33 | (my $value, $bert) = $self->read_any($bert); | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 32 | 33 | ▶ | $value = $self->extract_complex_type($value) | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 33 | if ref $value eq 'BERT::Tuple'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 35 | 33 | ▶ | return [ $value, $self->extract_any($bert) ] if $bert; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 36 | 33 | return $value; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 37 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 39 | 9 | ▶ | sub extract_complex_type { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
extract_complex_type: called CC=13 SCAR=27.6
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 40 | 9 | my ($self, $tuple) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 42 | 9 | my @array = @{ $tuple->value }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 43 | 9 | ▶ | return $tuple unless $array[0] eq 'bert'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 45 | 8 | ▶ | if ($array[1] eq 'nil') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 6 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 46 | 1 | return undef; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 47 | } elsif ($array[1] eq 'true') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 48 | 1 | return BERT::Boolean->true; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 49 | } elsif ($array[1] eq 'false') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 50 | 1 | return BERT::Boolean->false; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 51 | } elsif ($array[1] eq 'dict') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 52 | 3 | my @dict = map(@{ $_->value }, @{ $array[2] }); | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 54 | # Someday I should add an option to allow hashref to be returned instead | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 55 | 3 | return BERT::Dict->new(\@dict); | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 56 | } elsif ($array[1] eq 'time') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 57 | 1 | my ($megasec, $sec, $microsec) = @array[2, 3, 4]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 58 | 1 | return BERT::Time->new($megasec * 1_000_000 + $sec, $microsec); | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 59 | } elsif ($array[1] eq 'regex') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 60 | 1 | my ($source, $options) = @array[2, 3]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 61 | 1 | my $opt = ''; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 62 | 1 | for (@{ $options }) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 63 | 1 | ▶ | if ($_ eq 'caseless') { $opt .= 'i' } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 4 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 64 | 0 | elsif ($_ eq 'dotall') { $opt .= 's' } | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 65 | 0 | elsif ($_ eq 'extended') { $opt .= 'x' } | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 66 | 0 | elsif ($_ eq 'multiline') { $opt .= 'm' } | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 67 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 68 | 1 | return eval "qr/$source/$opt"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 69 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 70 | 0 | croak "Unknown complex type $array[1]"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 71 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 72 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 73 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 74 | 80 | ▶ | sub read_any { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
read_any: called CC=13 SCAR=25.8
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 75 | 80 | my ($self, $bert) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 76 | 80 | my $value; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 77 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 78 | 80 | (my $type, $bert) = unpack('Ca*', $bert); | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 79 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 80 | 80 | ▶ | if (SMALL_INTEGER_EXT == $type) { return $self->read_small_integer($bert) } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 12 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 81 | 7 | elsif (INTEGER_EXT == $type) { return $self->read_integer($bert) } | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 82 | 2 | elsif (FLOAT_EXT == $type) { return $self->read_float($bert) } | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 83 | 25 | elsif (ATOM_EXT == $type) { return $self->read_atom($bert) } | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 84 | 12 | elsif (SMALL_TUPLE_EXT == $type) { return $self->read_small_tuple($bert) } | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 85 | 0 | elsif (LARGE_TUPLE_EXT == $type) { return $self->read_large_tuple($bert) } | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 86 | 2 | elsif (NIL_EXT == $type) { return $self->read_nil($bert) } | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 87 | 3 | elsif (STRING_EXT == $type) { return $self->read_string($bert) } | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 88 | 7 | elsif (LIST_EXT == $type) { return $self->read_list($bert) } | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 89 | 10 | elsif (BINARY_EXT == $type) { return $self->read_binary($bert) } | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 90 | 3 | elsif (SMALL_BIG_EXT == $type) { return $self->read_small_big($bert) } | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 91 | 1 | elsif (LARGE_BIG_EXT == $type) { return $self->read_large_big($bert) } | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 92 | 0 | else { croak "Unknown type $type" } | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 93 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 94 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 95 | 8 | ▶ | sub read_small_integer { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
read_small_integer: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 96 | 8 | my ($self, $bert) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 97 | 8 | (my $value, $bert) = unpack('Ca*', $bert); | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 98 | 8 | return ($value, $bert); | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 99 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 100 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 101 | 7 | ▶ | sub read_integer { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
read_integer: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 102 | 7 | my ($self, $bert) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 103 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 104 | # This should have been unpack('l>a*',...) only and not have extra unpack('l',...) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 105 | # but I don't want to require perl >= v5.10 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 106 | 7 | (my $value, $bert) = unpack('Na*', $bert); | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 107 | 7 | $value = unpack('l', pack('L', $value)); | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 108 | 7 | return ($value, $bert); | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 109 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 110 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 111 | 2 | ▶ | sub read_float { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
read_float: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 112 | 2 | my ($self, $bert) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 113 | 2 | (my $value, $bert) = unpack('Z31a*', $bert); | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 114 | 2 | return ($value, $bert); | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 115 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 116 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 117 | 25 | ▶ | sub read_atom { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
read_atom: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 118 | 25 | my ($self, $bert) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 119 | 25 | (my $len, $bert) = unpack('na*', $bert); | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 120 | 25 | (my $value, $bert) = unpack("a$len a*", $bert); | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 121 | 25 | $value = BERT::Atom->new($value); | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 122 | 25 | return ($value, $bert); | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 123 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 124 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 125 | 12 | ▶ | sub read_small_tuple { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
read_small_tuple: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 126 | 12 | my ($self, $bert) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 127 | 12 | (my $len, $bert) = unpack('Ca*', $bert); | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 128 | 12 | (my $value, $bert) = $self->read_array($bert, $len, []); | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 129 | 12 | $value = BERT::Tuple->new($value); | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 130 | 12 | return ($value, $bert); | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 131 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 132 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 133 | 0 | ▶ | sub read_large_tuple { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
read_large_tuple: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 134 | 0 | my ($self, $bert) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 135 | 0 | (my $len, $bert) = unpack('Na*', $bert); | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 136 | 0 | (my $value, $bert) = $self->read_array($bert, $len, []); | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 137 | 0 | $value = BERT::Tuple->new($value); | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 138 | 0 | return ($value, $bert); | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 139 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 140 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 141 | 2 | ▶ | sub read_nil { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
read_nil: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 142 | 2 | my ($self, $bert) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 143 | 2 | my $value = []; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 144 | 2 | return ($value, $bert); | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 145 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 146 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 147 | 3 | ▶ | sub read_string { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
read_string: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 148 | 3 | my ($self, $bert) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 149 | 3 | (my $len, $bert) = unpack('na*', $bert); | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 150 | 3 | my @values = unpack("C$len a*", $bert); | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 151 | 3 | $bert = pop @values; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 152 | 3 | my $value = \@values; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 153 | 3 | return ($value, $bert); | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 154 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 155 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 156 | 7 | ▶ | sub read_list { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
read_list: called CC=2 SCAR=7.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 157 | 7 | my ($self, $bert) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 158 | 7 | (my $len, $bert) = unpack('Na*', $bert); | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 159 | 7 | (my $value, $bert) = $self->read_array($bert, $len, []); | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 160 | 7 | (my $type, $bert) = unpack('Ca*', $bert); | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 161 | 7 | ▶ | croak 'Lists with non NIL tails are not supported' | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 162 | unless NIL_EXT == $type; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 163 | 7 | return ($value, $bert); | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 164 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 165 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 166 | 10 | ▶ | sub read_binary { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
read_binary: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 167 | 10 | my ($self, $bert) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 168 | 10 | (my $len, $bert) = unpack('Na*', $bert); | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 169 | 10 | (my $value, $bert) = unpack("a$len a*", $bert); | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 170 | 10 | return ($value, $bert); | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 171 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 172 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 173 | 3 | ▶ | sub read_small_big { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
read_small_big: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 174 | 3 | my ($self, $bert) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 175 | 3 | (my $len, $bert) = unpack('Ca*', $bert); | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 176 | 3 | (my $value, $bert) = $self->read_bigint($bert, $len); | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 177 | 3 | return ($value, $bert); | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 178 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 179 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 180 | 1 | ▶ | sub read_large_big { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
read_large_big: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 181 | 1 | my ($self, $bert) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 182 | 1 | (my $len, $bert) = unpack('Na*', $bert); | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 183 | 1 | (my $value, $bert) = $self->read_bigint($bert, $len); | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 184 | 1 | return ($value, $bert); | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 185 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 186 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 187 | 4 | ▶ | sub read_bigint { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
read_bigint: called CC=3 SCAR=11.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 188 | 4 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 189 | 4 | my ($bert, $len) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 190 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 191 | 4 | my($sign, @values) = unpack("CC$len a*", $bert); | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 192 | 4 | $bert = pop @values; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 193 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 194 | 4 | require Math::BigInt; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 195 | 4 | my $i = Math::BigInt->new(0); | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 196 | 4 | my $value = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 197 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 198 | 4 | foreach my $item (@values) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 199 | 274 | $value += $item * 256 ** $i++; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 200 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 201 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 202 | 4 | ▶ | $value->bneg() if $sign != 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 203 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 204 | 4 | return ($value, $bert); | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 205 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 206 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 207 | 66 | ▶ | sub read_array { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
read_array: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 208 | 66 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 209 | 66 | my ($bert, $len, $array) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 210 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 211 | 66 | ▶ | if ($len > 0) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 212 | 47 | (my $value, $bert) = $self->read_any($bert); | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 213 | 47 | return $self->read_array($bert, $len - 1, [@{ $array }, $value]); | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 214 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 215 | 19 | return ($array, $bert); | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 216 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 217 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 218 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 219 | 6 | 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 220 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 221 | __END__ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||