| 1 | package BERT::Encoder; | ||||||||||||||||||||||||||||||||||||||||||||||
| 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 | # stolen from Regexp::Common :-) | ||||||||||||||||||||||||||||||||||||||||||||||
| 12 | 6 | ▶ | use constant { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 13 | 6 | INT_RE => qr/^(?:(?:[+-]?)(?:[0123456789]+))$/, | |||||||||||||||||||||||||||||||||||||||||||||
| 14 | FLOAT_RE => qr/^(?:(?i)(?:[+-]?)(?:(?=[.]?[0123456789])(?:[0123456789]*)(?:(?:[.])(?:[0123456789]{0,}))?)(?:(?:[E])(?:(?:[+-]?)(?:[0123456789]+))|))$/, | ||||||||||||||||||||||||||||||||||||||||||||||
| 15 | 6 | }; | |||||||||||||||||||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||||||||||||||||||||
| 17 | 36 | ▶ | sub new { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
new: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 18 | 36 | my $class = shift; | |||||||||||||||||||||||||||||||||||||||||||||
| 19 | 36 | return bless { }, $class; | |||||||||||||||||||||||||||||||||||||||||||||
| 20 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||||||||||||||||||||
| 22 | 36 | ▶ | sub encode { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
encode: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 23 | 36 | my ($self, $value) = @_; | |||||||||||||||||||||||||||||||||||||||||||||
| 24 | 36 | return pack('C', MAGIC_NUMBER) . $self->encode_any($value); | |||||||||||||||||||||||||||||||||||||||||||||
| 25 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||||||||||||||||||||
| 27 | 98 | ▶ | sub encode_any { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
encode_any: called CC=14 SCAR=26.4
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 28 | 98 | my ($self, $value) = @_; | |||||||||||||||||||||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||||||||||||||||||||
| 30 | 98 | ▶ | return $self->encode_nil unless defined $value; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||||||||||||||||||||
| 32 | 96 | my $type = ref $value; | |||||||||||||||||||||||||||||||||||||||||||||
| 33 | 96 | ▶ | if ($type eq 'ARRAY') { return $self->encode_array($value) } | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 10 branches
| |||||||||||||||||||||||||||||||||||||||||||||||
| 34 | 2 | elsif ($type eq 'HASH') { return $self->encode_dict($value) } | |||||||||||||||||||||||||||||||||||||||||||||
| 35 | 1 | elsif ($type eq 'Regexp') { return $self->encode_regex($value) } | |||||||||||||||||||||||||||||||||||||||||||||
| 36 | 29 | elsif ($type eq 'BERT::Atom') { return $self->encode_atom($value) } | |||||||||||||||||||||||||||||||||||||||||||||
| 37 | 14 | elsif ($type eq 'BERT::Tuple') { return $self->encode_tuple($value) } | |||||||||||||||||||||||||||||||||||||||||||||
| 38 | 2 | elsif ($type eq 'BERT::Boolean') { return $self->encode_boolean($value) } | |||||||||||||||||||||||||||||||||||||||||||||
| 39 | 2 | elsif ($type eq 'BERT::Dict') { return $self->encode_dict($value) } | |||||||||||||||||||||||||||||||||||||||||||||
| 40 | 1 | elsif ($type eq 'BERT::Time') { return $self->encode_time($value) } | |||||||||||||||||||||||||||||||||||||||||||||
| 41 | 4 | elsif ($type eq 'Math::BigInt') { return $self->encode_integer($value) } | |||||||||||||||||||||||||||||||||||||||||||||
| 42 | 1 | elsif ($type) { croak "Can't encode type $type" } | |||||||||||||||||||||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||||||||||||||||||||
| 44 | # I didn't use B::svref_2object on this because by only looking at variables | ||||||||||||||||||||||||||||||||||||||||||||||
| 45 | # in Perl can actually modify them | ||||||||||||||||||||||||||||||||||||||||||||||
| 46 | 27 | ▶ | if ($value =~ INT_RE) { return $self->encode_integer($value) } | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||
| 47 | 2 | elsif ($value =~ FLOAT_RE) { return $self->encode_float($value) } | |||||||||||||||||||||||||||||||||||||||||||||
| 48 | 10 | else { return $self->encode_binary($value) } | |||||||||||||||||||||||||||||||||||||||||||||
| 49 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 50 | |||||||||||||||||||||||||||||||||||||||||||||||
| 51 | 2 | ▶ | sub encode_nil { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
encode_nil: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 52 | 2 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||||||
| 53 | 2 | my $perl = BERT::Tuple->new([BERT::Atom->new('bert'), BERT::Atom->new('nil')]); | |||||||||||||||||||||||||||||||||||||||||||||
| 54 | 2 | return $self->encode_any($perl); | |||||||||||||||||||||||||||||||||||||||||||||
| 55 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||||||||||||||||||||
| 57 | 10 | ▶ | sub is_erl_string { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
is_erl_string: called CC=6 SCAR=18.3
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 58 | 10 | my ($self, $value) = @_; | |||||||||||||||||||||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||||||||||||||||||||
| 60 | # Although it works I'm not sure it's the best way to test whether a | ||||||||||||||||||||||||||||||||||||||||||||||
| 61 | # scalar is within the byte range | ||||||||||||||||||||||||||||||||||||||||||||||
| 62 | 10 | foreach my $item (@{ $value }) { | |||||||||||||||||||||||||||||||||||||||||||||
| 63 | 17 | ▶ | if ($item =~ /^\d+$/) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 64 | 9 | ▶ | return 0 if 0 > $item or $item > 255; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
0 > $item or $item > 255
MC/DC0%0/2
0 > $item or $item > 255
0 > $item
$item > 255
Truth table33%1/3
A or B
A= 0 > $itemB= $item > 255
| |||||||||||||||||||||||||||||||||||||||||||||||
| 65 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||
| 66 | 8 | ▶ | return 0 if length $item != 1; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 67 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 68 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 69 | 3 | return 1; | |||||||||||||||||||||||||||||||||||||||||||||
| 70 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||||||||||||||||||||
| 72 | 13 | ▶ | sub encode_array { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
encode_array: called CC=3 SCAR=11.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 73 | 13 | my ($self, $value) = @_; | |||||||||||||||||||||||||||||||||||||||||||||
| 74 | 13 | my @value = @{ $value }; | |||||||||||||||||||||||||||||||||||||||||||||
| 75 | |||||||||||||||||||||||||||||||||||||||||||||||
| 76 | 13 | ▶ | return pack('C', NIL_EXT) unless @value; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 77 | 10 | ▶ | return $self->encode_bytelist(\@value) if $self->is_erl_string(\@value); | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 78 | |||||||||||||||||||||||||||||||||||||||||||||||
| 79 | 7 | my $array = $self->encode_list(\@value, []); | |||||||||||||||||||||||||||||||||||||||||||||
| 80 | 7 | return pack('CN', LIST_EXT, scalar @{ $array }) . join('', @{ $array }) . pack('C', NIL_EXT); | |||||||||||||||||||||||||||||||||||||||||||||
| 81 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 82 | |||||||||||||||||||||||||||||||||||||||||||||||
| 83 | 73 | ▶ | sub encode_list { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
encode_list: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 84 | 73 | my ($self, $value, $array) = @_; | |||||||||||||||||||||||||||||||||||||||||||||
| 85 | |||||||||||||||||||||||||||||||||||||||||||||||
| 86 | 73 | ▶ | if (@{ $value }) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 87 | 52 | my $head = shift @{ $value }; | |||||||||||||||||||||||||||||||||||||||||||||
| 88 | 52 | return $self->encode_list($value, [@{ $array }, $self->encode_any($head)]); | |||||||||||||||||||||||||||||||||||||||||||||
| 89 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||
| 90 | 21 | return $array; | |||||||||||||||||||||||||||||||||||||||||||||
| 91 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 92 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 93 | |||||||||||||||||||||||||||||||||||||||||||||||
| 94 | 4 | ▶ | sub encode_dict { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
encode_dict: called CC=3 SCAR=11.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 95 | 4 | my ($self, $value) = @_; | |||||||||||||||||||||||||||||||||||||||||||||
| 96 | |||||||||||||||||||||||||||||||||||||||||||||||
| 97 | 4 | my @array; | |||||||||||||||||||||||||||||||||||||||||||||
| 98 | 4 | ▶ | my @value = ref $value eq 'BERT::Dict' ? @{ $value->value } : %{ $value }; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 99 | 4 | ▶ | while (my @key_value = splice(@value, 0, 2)) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 100 | 3 | push @array, BERT::Tuple->new(\@key_value); | |||||||||||||||||||||||||||||||||||||||||||||
| 101 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 102 | |||||||||||||||||||||||||||||||||||||||||||||||
| 103 | 4 | my $perl = BERT::Tuple->new([BERT::Atom->new('bert'), BERT::Atom->new('dict'), \@array]); | |||||||||||||||||||||||||||||||||||||||||||||
| 104 | 4 | return $self->encode_any($perl); | |||||||||||||||||||||||||||||||||||||||||||||
| 105 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 106 | |||||||||||||||||||||||||||||||||||||||||||||||
| 107 | 1 | ▶ | sub encode_regex { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
encode_regex: called CC=7 SCAR=24.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 108 | 1 | my ($self, $value) = @_; | |||||||||||||||||||||||||||||||||||||||||||||
| 109 | |||||||||||||||||||||||||||||||||||||||||||||||
| 110 | 1 | for ($value) { s/^\(\?//; s/\)$// } | |||||||||||||||||||||||||||||||||||||||||||||
| 111 | 1 | my ($modifiers, $pattern) = split /:/, $value, 2; | |||||||||||||||||||||||||||||||||||||||||||||
| 112 | 1 | my ($on, $off) = split /-/, $modifiers; | |||||||||||||||||||||||||||||||||||||||||||||
| 113 | |||||||||||||||||||||||||||||||||||||||||||||||
| 114 | 1 | my @options; | |||||||||||||||||||||||||||||||||||||||||||||
| 115 | 1 | for ($on) { | |||||||||||||||||||||||||||||||||||||||||||||
| 116 | 1 | ▶ | if (/i/) { push @options, BERT::Atom->new('caseless') } | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 4 branches
| |||||||||||||||||||||||||||||||||||||||||||||||
| 117 | 0 | elsif (/s/) { push @options, BERT::Atom->new('dotall') } | |||||||||||||||||||||||||||||||||||||||||||||
| 118 | 0 | elsif (/x/) { push @options, BERT::Atom->new('extended') } | |||||||||||||||||||||||||||||||||||||||||||||
| 119 | 0 | elsif (/m/) { push @options, BERT::Atom->new('multiline') } | |||||||||||||||||||||||||||||||||||||||||||||
| 120 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 121 | |||||||||||||||||||||||||||||||||||||||||||||||
| 122 | 1 | my $perl = BERT::Tuple->new([BERT::Atom->new('bert'), BERT::Atom->new('regex'), $pattern, \@options]); | |||||||||||||||||||||||||||||||||||||||||||||
| 123 | 1 | return $self->encode_any($perl); | |||||||||||||||||||||||||||||||||||||||||||||
| 124 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 125 | |||||||||||||||||||||||||||||||||||||||||||||||
| 126 | 29 | ▶ | sub encode_atom { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
encode_atom: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 127 | 29 | my ($self, $value) = @_; | |||||||||||||||||||||||||||||||||||||||||||||
| 128 | 29 | return pack('Cna*', ATOM_EXT, length $value, $value); | |||||||||||||||||||||||||||||||||||||||||||||
| 129 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 130 | |||||||||||||||||||||||||||||||||||||||||||||||
| 131 | 14 | ▶ | sub encode_tuple { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
encode_tuple: called CC=2 SCAR=7.6
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 132 | 14 | my ($self, $value) = @_; | |||||||||||||||||||||||||||||||||||||||||||||
| 133 | |||||||||||||||||||||||||||||||||||||||||||||||
| 134 | 14 | my @array = @{ $value->value }; | |||||||||||||||||||||||||||||||||||||||||||||
| 135 | 14 | ▶ | return pack('C*', SMALL_TUPLE_EXT, scalar @array) . join('', @{ $self->encode_list(\@array, []) }) if @array < 256; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 136 | 0 | return pack('CN', LARGE_TUPLE_EXT, scalar @array) . join('', @{ $self->encode_list(\@array, []) }); | |||||||||||||||||||||||||||||||||||||||||||||
| 137 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 138 | |||||||||||||||||||||||||||||||||||||||||||||||
| 139 | 3 | ▶ | sub encode_bytelist { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
encode_bytelist: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 140 | 3 | my ($self, $value) = @_; | |||||||||||||||||||||||||||||||||||||||||||||
| 141 | 3 | return pack('CnC*', STRING_EXT, scalar @{ $value }, @{ $value }); | |||||||||||||||||||||||||||||||||||||||||||||
| 142 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 143 | |||||||||||||||||||||||||||||||||||||||||||||||
| 144 | 2 | ▶ | sub encode_boolean { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
encode_boolean: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 145 | 2 | my ($self, $value) = @_; | |||||||||||||||||||||||||||||||||||||||||||||
| 146 | |||||||||||||||||||||||||||||||||||||||||||||||
| 147 | 2 | ▶ | my $boolean = $value ? BERT::Atom->new('true') : BERT::Atom->new('false'); | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 148 | 2 | my $perl = BERT::Tuple->new([BERT::Atom->new('bert'), $boolean]); | |||||||||||||||||||||||||||||||||||||||||||||
| 149 | 2 | return $self->encode_any($perl); | |||||||||||||||||||||||||||||||||||||||||||||
| 150 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 151 | |||||||||||||||||||||||||||||||||||||||||||||||
| 152 | 1 | ▶ | sub encode_time { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
encode_time: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 153 | 1 | my ($self, $value) = @_; | |||||||||||||||||||||||||||||||||||||||||||||
| 154 | |||||||||||||||||||||||||||||||||||||||||||||||
| 155 | 6 | ▶ | use integer; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 156 | 1 | my ($seconds, $microseconds) = $value->value; | |||||||||||||||||||||||||||||||||||||||||||||
| 157 | 1 | my $megaseconds = $seconds / 1_000_000; | |||||||||||||||||||||||||||||||||||||||||||||
| 158 | 1 | $seconds = $seconds % 1_000_000; | |||||||||||||||||||||||||||||||||||||||||||||
| 159 | 1 | my $perl = BERT::Tuple->new([BERT::Atom->new('bert'), BERT::Atom->new('time'), $megaseconds, $seconds, $microseconds]); | |||||||||||||||||||||||||||||||||||||||||||||
| 160 | 1 | return $self->encode_any($perl); | |||||||||||||||||||||||||||||||||||||||||||||
| 161 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 162 | |||||||||||||||||||||||||||||||||||||||||||||||
| 163 | 19 | ▶ | sub encode_integer { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
encode_integer: called CC=8 SCAR=20.8
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 164 | 19 | my ($self, $value) = @_; | |||||||||||||||||||||||||||||||||||||||||||||
| 165 | |||||||||||||||||||||||||||||||||||||||||||||||
| 166 | 19 | ▶ | return pack('C2', SMALL_INTEGER_EXT, $value) | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
0 <= $value and $value <= 255
MC/DC100%2/2
0 <= $value and $value <= 255
0 <= $value
$value <= 255
Truth table100%3/3
A and B
A= 0 <= $valueB= $value <= 255
| |||||||||||||||||||||||||||||||||||||||||||||||
| 167 | if 0 <= $value and $value <= 255; | ||||||||||||||||||||||||||||||||||||||||||||||
| 168 | |||||||||||||||||||||||||||||||||||||||||||||||
| 169 | # I think newer versions of erlang no longer have the 28bit limit, | ||||||||||||||||||||||||||||||||||||||||||||||
| 170 | # so maybe I should add an option to extend the limit to max_int | ||||||||||||||||||||||||||||||||||||||||||||||
| 171 | 11 | ▶ | return pack('CN', INTEGER_EXT, $value) | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
-134217728 <= $value and $value <= 134217727
MC/DC100%2/2
-134217728 <= $value and $value <= 134217727
-134217728 <= $value
$value <= 134217727
Truth table100%3/3
A and B
A= -134217728 <= $valueB= $value <= 134217727
| |||||||||||||||||||||||||||||||||||||||||||||||
| 172 | if ERL_MIN <= $value and $value <= ERL_MAX; | ||||||||||||||||||||||||||||||||||||||||||||||
| 173 | |||||||||||||||||||||||||||||||||||||||||||||||
| 174 | 4 | ▶ | my $sign = $value < 0 ? 1 : 0; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 175 | 4 | $value = abs($value); | |||||||||||||||||||||||||||||||||||||||||||||
| 176 | |||||||||||||||||||||||||||||||||||||||||||||||
| 177 | 4 | my @bytes; | |||||||||||||||||||||||||||||||||||||||||||||
| 178 | 4 | ▶ | while ($value > 0) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 179 | 274 | push @bytes, $value & 0xFF; | |||||||||||||||||||||||||||||||||||||||||||||
| 180 | 274 | $value >>= 8; | |||||||||||||||||||||||||||||||||||||||||||||
| 181 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 182 | |||||||||||||||||||||||||||||||||||||||||||||||
| 183 | 4 | ▶ | return pack('C*', SMALL_BIG_EXT, scalar @bytes, $sign, @bytes) if @bytes < 256; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 184 | 1 | return pack('CNC*', LARGE_BIG_EXT, scalar @bytes, $sign, @bytes); | |||||||||||||||||||||||||||||||||||||||||||||
| 185 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 186 | |||||||||||||||||||||||||||||||||||||||||||||||
| 187 | 2 | ▶ | sub encode_float { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
encode_float: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 188 | 2 | my ($self, $value) = @_; | |||||||||||||||||||||||||||||||||||||||||||||
| 189 | 2 | return pack('CZ31', FLOAT_EXT, sprintf('%.20e', $value)); | |||||||||||||||||||||||||||||||||||||||||||||
| 190 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 191 | |||||||||||||||||||||||||||||||||||||||||||||||
| 192 | 10 | ▶ | sub encode_binary { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
encode_binary: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 193 | 10 | my ($self, $value) = @_; | |||||||||||||||||||||||||||||||||||||||||||||
| 194 | 10 | return pack('CNa*', BINARY_EXT, length $value, $value); | |||||||||||||||||||||||||||||||||||||||||||||
| 195 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 196 | |||||||||||||||||||||||||||||||||||||||||||||||
| 197 | 6 | 1; | |||||||||||||||||||||||||||||||||||||||||||||
| 198 | |||||||||||||||||||||||||||||||||||||||||||||||
| 199 | __END__ | ||||||||||||||||||||||||||||||||||||||||||||||