| 1 | package Set::SegmentTree::node; | ||||||||||||||||||||||||||||||
| 2 | # table package auto-generated by Data::FlatTables | ||||||||||||||||||||||||||||||
| 3 | 1 | ▶ | use strict; | ||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||
| 4 | 1 | ▶ | use warnings; | ||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||||
| 6 | 1 | our $VERSION = '0.05'; | |||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||||
| 8 | sub new { | ||||||||||||||||||||||||||||||
| 9 | 116 | ▶ | my ($class, %args) = @_; | ||||||||||||||||||||||||||||
|
Subroutine
new: called CC=12 SCAR=25.4
Pod
undocumented
| |||||||||||||||||||||||||||||||
| 10 | 116 | my $self = bless {}, $class; | |||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||||
| 12 | 116 | ▶ | $self->{min} = $args{min} if defined $args{min} and $args{min} != 0; | ||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
defined $args{"min"} and $args{"min"} != 0
MC/DC50%1/2
defined $args{"min"} and $args{"min"} != 0
defined $args{"min"}
$args{"min"} != 0
Truth table66%2/3
A and B
A= defined $args{"min"}B= $args{"min"} != 0
| |||||||||||||||||||||||||||||||
| 13 | 116 | ▶ | $self->{low} = $args{low} if defined $args{low} and $args{low} != 0; | ||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
defined $args{"low"} and $args{"low"} != 0
MC/DC100%2/2
defined $args{"low"} and $args{"low"} != 0
defined $args{"low"}
$args{"low"} != 0
Truth table100%3/3
A and B
A= defined $args{"low"}B= $args{"low"} != 0
| |||||||||||||||||||||||||||||||
| 14 | 116 | ▶ | $self->{max} = $args{max} if defined $args{max} and $args{max} != 0; | ||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
defined $args{"max"} and $args{"max"} != 0
MC/DC50%1/2
defined $args{"max"} and $args{"max"} != 0
defined $args{"max"}
$args{"max"} != 0
Truth table66%2/3
A and B
A= defined $args{"max"}B= $args{"max"} != 0
| |||||||||||||||||||||||||||||||
| 15 | 116 | ▶ | $self->{high} = $args{high} if defined $args{high} and $args{high} != 0; | ||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
defined $args{"high"} and $args{"high"} != 0
MC/DC50%1/2
defined $args{"high"} and $args{"high"} != 0
defined $args{"high"}
$args{"high"} != 0
Truth table66%2/3
A and B
A= defined $args{"high"}B= $args{"high"} != 0
| |||||||||||||||||||||||||||||||
| 16 | 116 | ▶ | $self->{split} = $args{split} if defined $args{split} and $args{split} != 0; | ||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
defined $args{"split"} and $args{"split"} != 0
MC/DC0%0/2
defined $args{"split"} and $args{"split"} != 0
defined $args{"split"}
$args{"split"} != 0
Truth table33%1/3
A and B
A= defined $args{"split"}B= $args{"split"} != 0
| |||||||||||||||||||||||||||||||
| 17 | 116 | ▶ | $self->{segments} = $args{segments} if exists $args{segments}; | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||||
| 19 | 116 | return $self; | |||||||||||||||||||||||||||||
| 20 | } | ||||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||||
| 22 | 4 | ▶ | sub flatbuffers_type { 'table' } | ||||||||||||||||||||||||||||
|
Subroutine
flatbuffers_type: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||||
| 24 | 1 | my %basic_types = ( | |||||||||||||||||||||||||||||
| 25 | bool => { format => 'C', length => 1 }, | ||||||||||||||||||||||||||||||
| 26 | byte => { format => 'c', length => 1 }, | ||||||||||||||||||||||||||||||
| 27 | ubyte => { format => 'C', length => 1 }, | ||||||||||||||||||||||||||||||
| 28 | short => { format => 's<', length => 2 }, | ||||||||||||||||||||||||||||||
| 29 | ushort => { format => 'S<', length => 2 }, | ||||||||||||||||||||||||||||||
| 30 | int => { format => 'l<', length => 4 }, | ||||||||||||||||||||||||||||||
| 31 | uint => { format => 'L<', length => 4 }, | ||||||||||||||||||||||||||||||
| 32 | float => { format => 'f<', length => 4 }, | ||||||||||||||||||||||||||||||
| 33 | long => { format => 'q<', length => 8 }, | ||||||||||||||||||||||||||||||
| 34 | ulong => { format => 'Q<', length => 8 }, | ||||||||||||||||||||||||||||||
| 35 | double => { format => 'd<', length => 8 }, | ||||||||||||||||||||||||||||||
| 36 | ); | ||||||||||||||||||||||||||||||
| 37 | 0 | ▶ | sub min { @_ > 1 ? $_[0]{min} = ( $_[1] == 0 ? undef : $_[1]) : $_[0]{min} // 0 } | ||||||||||||||||||||||||||||
|
Subroutine
min: not called CC=4 SCAR=30.0
Pod
undocumented
Branch: 2 branches
Condition0%0/2
$_[0]{"min"} // 0
MC/DC0%0/1
$_[0]{"min"} // 0
$_[0]{"min"}
Truth table0%0/2
A
A= $_[0]{"min"}
| |||||||||||||||||||||||||||||||
| 38 | 286 | ▶ | sub low { @_ > 1 ? $_[0]{low} = ( $_[1] == 0 ? undef : $_[1]) : $_[0]{low} // 0 } | ||||||||||||||||||||||||||||
|
Subroutine
low: called CC=4 SCAR=16.6
Pod
undocumented
Branch: 2 branches
Condition100%2/2
$_[0]{"low"} // 0
MC/DC100%1/1
$_[0]{"low"} // 0
$_[0]{"low"}
Truth table100%2/2
A
A= $_[0]{"low"}
| |||||||||||||||||||||||||||||||
| 39 | 0 | ▶ | sub max { @_ > 1 ? $_[0]{max} = ( $_[1] == 0 ? undef : $_[1]) : $_[0]{max} // 0 } | ||||||||||||||||||||||||||||
|
Subroutine
max: not called CC=4 SCAR=30.0
Pod
undocumented
Branch: 2 branches
Condition0%0/2
$_[0]{"max"} // 0
MC/DC0%0/1
$_[0]{"max"} // 0
$_[0]{"max"}
Truth table0%0/2
A
A= $_[0]{"max"}
| |||||||||||||||||||||||||||||||
| 40 | 290 | ▶ | sub high { @_ > 1 ? $_[0]{high} = ( $_[1] == 0 ? undef : $_[1]) : $_[0]{high} // 0 } | ||||||||||||||||||||||||||||
|
Subroutine
high: called CC=4 SCAR=16.6
Pod
undocumented
Branch: 2 branches
Condition100%2/2
$_[0]{"high"} // 0
MC/DC100%1/1
$_[0]{"high"} // 0
$_[0]{"high"}
Truth table100%2/2
A
A= $_[0]{"high"}
| |||||||||||||||||||||||||||||||
| 41 | 0 | ▶ | sub split { @_ > 1 ? $_[0]{split} = ( $_[1] == 0 ? undef : $_[1]) : $_[0]{split} // 0 } | ||||||||||||||||||||||||||||
|
Subroutine
split: not called CC=4 SCAR=30.0
Pod
undocumented
Branch: 2 branches
Condition0%0/2
$_[0]{"split"} // 0
MC/DC0%0/1
$_[0]{"split"} // 0
$_[0]{"split"}
Truth table0%0/2
A
A= $_[0]{"split"}
| |||||||||||||||||||||||||||||||
| 42 | 170 | ▶ | sub segments { @_ > 1 ? $_[0]{segments} = $_[1] : $_[0]{segments} } | ||||||||||||||||||||||||||||
|
Subroutine
segments: called CC=2 SCAR=7.6
Pod
undocumented
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||||
| 44 | sub deserialize { | ||||||||||||||||||||||||||||||
| 45 | 58 | ▶ | my ($self, $data, $offset) = @_; | ||||||||||||||||||||||||||||
|
Subroutine
deserialize: called CC=9 SCAR=22.4
Pod
undocumented
| |||||||||||||||||||||||||||||||
| 46 | 58 | ▶ | $offset //= 0; | ||||||||||||||||||||||||||||
|
Condition50%1/2
$offset //= 0
MC/DC0%0/1
$offset //= 0
$offset
Truth table50%1/2
A
A= $offset
| |||||||||||||||||||||||||||||||
| 47 | 58 | ▶ | $self = $self->new unless ref $self; | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 48 | |||||||||||||||||||||||||||||||
| 49 | 58 | my $object_offset = $offset + unpack "L<", substr $data, $offset, 4; | |||||||||||||||||||||||||||||
| 50 | 58 | my $vtable_offset = $object_offset - unpack "l<", substr $data, $object_offset, 4; | |||||||||||||||||||||||||||||
| 51 | 58 | my @offsets = map unpack ("S<", $_), map substr ($data, $vtable_offset + $_ * 2, 2), 2 .. 7; | |||||||||||||||||||||||||||||
| 52 | |||||||||||||||||||||||||||||||
| 53 | 58 | ▶ | $self->{min} = unpack 'l<', substr $data, $object_offset + $offsets[0], 4 if $offsets[0] != 0; | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 54 | 58 | ▶ | $self->{low} = unpack 'l<', substr $data, $object_offset + $offsets[1], 4 if $offsets[1] != 0; | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 55 | 58 | ▶ | $self->{max} = unpack 'l<', substr $data, $object_offset + $offsets[2], 4 if $offsets[2] != 0; | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 56 | 58 | ▶ | $self->{high} = unpack 'l<', substr $data, $object_offset + $offsets[3], 4 if $offsets[3] != 0; | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 57 | 58 | ▶ | $self->{split} = unpack 'l<', substr $data, $object_offset + $offsets[4], 4 if $offsets[4] != 0; | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 58 | 58 | ▶ | $self->{segments} = $self->deserialize_array('[string]', $data, $object_offset + $offsets[5]) if $offsets[5] != 0; | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||||
| 60 | 58 | return $self | |||||||||||||||||||||||||||||
| 61 | } | ||||||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||||
| 65 | sub deserialize_string { | ||||||||||||||||||||||||||||||
| 66 | 48 | ▶ | my ($self, $data, $offset) = @_; | ||||||||||||||||||||||||||||
|
Subroutine
deserialize_string: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||||
| 68 | 48 | my $string_offset = $offset + unpack "L<", substr $data, $offset, 4; # dereference the string pointer | |||||||||||||||||||||||||||||
| 69 | 48 | my $string_length = unpack "L<", substr $data, $string_offset, 4; # get the length | |||||||||||||||||||||||||||||
| 70 | 48 | return substr $data, $string_offset + 4, $string_length # return a substring | |||||||||||||||||||||||||||||
| 71 | } | ||||||||||||||||||||||||||||||
| 72 | |||||||||||||||||||||||||||||||
| 73 | sub deserialize_array { | ||||||||||||||||||||||||||||||
| 74 | 30 | ▶ | my ($self, $array_type, $data, $offset) = @_; | ||||||||||||||||||||||||||||
|
Subroutine
deserialize_array: called CC=6 SCAR=26.9
Pod
undocumented
| |||||||||||||||||||||||||||||||
| 75 | |||||||||||||||||||||||||||||||
| 76 | 30 | $array_type = $array_type =~ s/\A\[(.*)\]\Z/$1/sr; | |||||||||||||||||||||||||||||
| 77 | |||||||||||||||||||||||||||||||
| 78 | 30 | $offset = $offset + unpack "L<", substr $data, $offset, 4; # dereference the array pointer | |||||||||||||||||||||||||||||
| 79 | 30 | my $array_length = unpack "L<", substr $data, $offset, 4; # get the length | |||||||||||||||||||||||||||||
| 80 | 30 | $offset += 4; | |||||||||||||||||||||||||||||
| 81 | |||||||||||||||||||||||||||||||
| 82 | 30 | my @array; | |||||||||||||||||||||||||||||
| 83 | 30 | ▶ | if (exists $basic_types{$array_type}) { # if its an array of numerics | ||||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||||
| 84 | 0 | @array = map { unpack $basic_types{$array_type}{format}, $_ } | |||||||||||||||||||||||||||||
| 85 | 0 | map { substr $data, $offset + $_, $basic_types{$array_type}{length} } | |||||||||||||||||||||||||||||
| 86 | map $_ * $basic_types{$array_type}{length}, | ||||||||||||||||||||||||||||||
| 87 | 0 | 0 .. ($array_length - 1); | |||||||||||||||||||||||||||||
| 88 | |||||||||||||||||||||||||||||||
| 89 | } elsif ($array_type eq "string") { # if its an array of strings | ||||||||||||||||||||||||||||||
| 90 | 30 | @array = map { $self->deserialize_string($data, $offset + $_) } | |||||||||||||||||||||||||||||
| 91 | map $_ * 4, | ||||||||||||||||||||||||||||||
| 92 | 0 .. ($array_length - 1); | ||||||||||||||||||||||||||||||
| 93 | |||||||||||||||||||||||||||||||
| 94 | } elsif ($array_type =~ /\A\[/) { # if its an array of strings | ||||||||||||||||||||||||||||||
| 95 | 0 | @array = map { $self->deserialize_array($array_type, $data, $offset + $_) } | |||||||||||||||||||||||||||||
| 96 | map $_ * 4, | ||||||||||||||||||||||||||||||
| 97 | 0 .. ($array_length - 1); | ||||||||||||||||||||||||||||||
| 98 | |||||||||||||||||||||||||||||||
| 99 | } else { # if its an array of objects | ||||||||||||||||||||||||||||||
| 100 | 0 | ▶ | if ($array_type->flatbuffers_type eq "table") { | ||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||
| 101 | 0 | @array = map { $array_type->deserialize($data, $offset + $_) } | |||||||||||||||||||||||||||||
| 102 | map $_ * 4, | ||||||||||||||||||||||||||||||
| 103 | 0 .. ($array_length - 1); | ||||||||||||||||||||||||||||||
| 104 | } elsif ($array_type->flatbuffers_type eq "struct") { | ||||||||||||||||||||||||||||||
| 105 | 0 | my $length = $array_type->flatbuffers_struct_length; | |||||||||||||||||||||||||||||
| 106 | 0 | @array = map { $array_type->deserialize($data, $offset + $_) } | |||||||||||||||||||||||||||||
| 107 | map $_ * $length, | ||||||||||||||||||||||||||||||
| 108 | 0 .. ($array_length - 1); | ||||||||||||||||||||||||||||||
| 109 | } else { | ||||||||||||||||||||||||||||||
| 110 | ... | ||||||||||||||||||||||||||||||
| 111 | 0 | } | |||||||||||||||||||||||||||||
| 112 | } | ||||||||||||||||||||||||||||||
| 113 | |||||||||||||||||||||||||||||||
| 114 | return \@array | ||||||||||||||||||||||||||||||
| 115 | 30 | } | |||||||||||||||||||||||||||||
| 116 | |||||||||||||||||||||||||||||||
| 117 | |||||||||||||||||||||||||||||||
| 118 | sub serialize { | ||||||||||||||||||||||||||||||
| 119 | 58 | ▶ | my ($self, $cache) = @_; | ||||||||||||||||||||||||||||
|
Subroutine
serialize: called CC=15 SCAR=29.2
Pod
undocumented
| |||||||||||||||||||||||||||||||
| 120 | 58 | ▶ | if (not defined $cache) { | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 121 | 0 | $cache = {}; | |||||||||||||||||||||||||||||
| 122 | |||||||||||||||||||||||||||||||
| 123 | 0 | my @objects = $self->serialize($cache); | |||||||||||||||||||||||||||||
| 124 | 0 | my $root = $objects[0]; # get the root data structure | |||||||||||||||||||||||||||||
| 125 | |||||||||||||||||||||||||||||||
| 126 | # header pointer to root data structure | ||||||||||||||||||||||||||||||
| 127 | 0 | unshift @objects, { type => "header", data => "\0\0\0\0", reloc => [{ offset => 0, item => $root, type => "unsigned delta" }] }; | |||||||||||||||||||||||||||||
| 128 | |||||||||||||||||||||||||||||||
| 129 | 0 | return $self->serialize_objects(@objects); | |||||||||||||||||||||||||||||
| 130 | } else { | ||||||||||||||||||||||||||||||
| 131 | |||||||||||||||||||||||||||||||
| 132 | my $vtable = $self->serialize_vtable( | ||||||||||||||||||||||||||||||
| 133 | defined $self->{min} ? 4 : 0, | ||||||||||||||||||||||||||||||
| 134 | defined $self->{low} ? 4 : 0, | ||||||||||||||||||||||||||||||
| 135 | defined $self->{max} ? 4 : 0, | ||||||||||||||||||||||||||||||
| 136 | defined $self->{high} ? 4 : 0, | ||||||||||||||||||||||||||||||
| 137 | defined $self->{split} ? 4 : 0, | ||||||||||||||||||||||||||||||
| 138 | 58 | ▶ | defined $self->{segments} ? 4 : 0, | ||||||||||||||||||||||||||||
|
Branch: 6 branches
| |||||||||||||||||||||||||||||||
| 139 | ); | ||||||||||||||||||||||||||||||
| 140 | 58 | my $data = "\0\0\0\0"; | |||||||||||||||||||||||||||||
| 141 | |||||||||||||||||||||||||||||||
| 142 | 58 | my @reloc = ({ offset => 0, item => $vtable, type => "signed negative delta" }); | |||||||||||||||||||||||||||||
| 143 | # flatbuffers vtable offset is stored in negative form | ||||||||||||||||||||||||||||||
| 144 | 58 | my @objects = ($vtable); | |||||||||||||||||||||||||||||
| 145 | |||||||||||||||||||||||||||||||
| 146 | 58 | ▶ | if (defined $self->{min}) { | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 147 | 58 | $data .= pack 'l<', $self->{min}; | |||||||||||||||||||||||||||||
| 148 | } | ||||||||||||||||||||||||||||||
| 149 | |||||||||||||||||||||||||||||||
| 150 | 58 | ▶ | if (defined $self->{low}) { | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 151 | 26 | $data .= pack 'l<', $self->{low}; | |||||||||||||||||||||||||||||
| 152 | } | ||||||||||||||||||||||||||||||
| 153 | |||||||||||||||||||||||||||||||
| 154 | 58 | ▶ | if (defined $self->{max}) { | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 155 | 58 | $data .= pack 'l<', $self->{max}; | |||||||||||||||||||||||||||||
| 156 | } | ||||||||||||||||||||||||||||||
| 157 | |||||||||||||||||||||||||||||||
| 158 | 58 | ▶ | if (defined $self->{high}) { | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 159 | 28 | $data .= pack 'l<', $self->{high}; | |||||||||||||||||||||||||||||
| 160 | } | ||||||||||||||||||||||||||||||
| 161 | |||||||||||||||||||||||||||||||
| 162 | 58 | ▶ | if (defined $self->{split}) { | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 163 | 0 | $data .= pack 'l<', $self->{split}; | |||||||||||||||||||||||||||||
| 164 | } | ||||||||||||||||||||||||||||||
| 165 | |||||||||||||||||||||||||||||||
| 166 | 58 | ▶ | if (defined $self->{segments}) { | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 167 | 30 | my ($array_object, @array_objects) = $self->serialize_array('[string]', $self->{segments}, $cache); | |||||||||||||||||||||||||||||
| 168 | 30 | push @objects, $array_object, @array_objects; | |||||||||||||||||||||||||||||
| 169 | 30 | push @reloc, { offset => length ($data), item => $array_object, type => 'unsigned delta'}; | |||||||||||||||||||||||||||||
| 170 | 30 | $data .= "\0\0\0\0"; | |||||||||||||||||||||||||||||
| 171 | } | ||||||||||||||||||||||||||||||
| 172 | |||||||||||||||||||||||||||||||
| 173 | # pad to 4 byte boundary | ||||||||||||||||||||||||||||||
| 174 | 58 | ▶ | $data .= pack "x" x (4 - (length ($data) % 4)) if length ($data) % 4; | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 175 | |||||||||||||||||||||||||||||||
| 176 | # return table data and other objects that we've created | ||||||||||||||||||||||||||||||
| 177 | 58 | return { type => "table", data => $data, reloc => \@reloc }, @objects | |||||||||||||||||||||||||||||
| 178 | } | ||||||||||||||||||||||||||||||
| 179 | } | ||||||||||||||||||||||||||||||
| 180 | |||||||||||||||||||||||||||||||
| 181 | |||||||||||||||||||||||||||||||
| 182 | sub serialize_objects { | ||||||||||||||||||||||||||||||
| 183 | 0 | ▶ | my ($self, @objects) = @_; | ||||||||||||||||||||||||||||
|
Subroutine
serialize_objects: not called CC=10 SCAR=47.0
Pod
undocumented
| |||||||||||||||||||||||||||||||
| 184 | |||||||||||||||||||||||||||||||
| 185 | |||||||||||||||||||||||||||||||
| 186 | 0 | my $data = ""; | |||||||||||||||||||||||||||||
| 187 | 0 | my $offset = 0; | |||||||||||||||||||||||||||||
| 188 | |||||||||||||||||||||||||||||||
| 189 | # concatentate the data | ||||||||||||||||||||||||||||||
| 190 | 0 | for my $object (@objects) { | |||||||||||||||||||||||||||||
| 191 | 0 | $object->{serialized_offset} = $offset; | |||||||||||||||||||||||||||||
| 192 | 0 | $data .= $object->{data}; | |||||||||||||||||||||||||||||
| 193 | 0 | $offset += length $object->{data}; | |||||||||||||||||||||||||||||
| 194 | } | ||||||||||||||||||||||||||||||
| 195 | |||||||||||||||||||||||||||||||
| 196 | # second pass for writing offsets to other parts | ||||||||||||||||||||||||||||||
| 197 | 0 | for my $object (@objects) { | |||||||||||||||||||||||||||||
| 198 | 0 | ▶ | if (defined $object->{reloc}) { | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 199 | # perform address relocation | ||||||||||||||||||||||||||||||
| 200 | 0 | for my $reloc (@{$object->{reloc}}) { | |||||||||||||||||||||||||||||
| 201 | 0 | my $value; | |||||||||||||||||||||||||||||
| 202 | 0 | ▶ | if (defined $reloc->{lambda}) { # allow the reloc to have a custom format | ||||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||||
| 203 | 0 | $value = $reloc->{lambda}($object, $reloc); | |||||||||||||||||||||||||||||
| 204 | ▶ | } elsif (defined $reloc->{type} and $reloc->{type} eq "unsigned delta") { | |||||||||||||||||||||||||||||
|
Condition0%0/3
defined $reloc->{"type"} and $reloc->{"type"} eq "unsigned delta"
MC/DC0%0/2
defined $reloc->{"type"} and $reloc->{"type"} eq "unsigned delta"
defined $reloc->{"type"}
$reloc->{"type"} eq "unsigned delta"
Truth table0%0/3
A and B
A= defined $reloc->{"type"}B= $reloc->{"type"} eq "unsigned delta"
| |||||||||||||||||||||||||||||||
| 205 | 0 | $value = pack "L<", $reloc->{item}{serialized_offset} - $object->{serialized_offset} - $reloc->{offset}; | |||||||||||||||||||||||||||||
| 206 | ▶ | } elsif (defined $reloc->{type} and $reloc->{type} eq "signed negative delta") { | |||||||||||||||||||||||||||||
|
Condition0%0/3
defined $reloc->{"type"} and $reloc->{"type"} eq "signed negative delta"
MC/DC0%0/2
defined $reloc->{"type"} and $reloc->{"type"} eq "signed negative delta"
defined $reloc->{"type"}
$reloc->{"type"} eq "signed negative delta"
Truth table0%0/3
A and B
A= defined $reloc->{"type"}B= $reloc->{"type"} eq "signed negative delta"
| |||||||||||||||||||||||||||||||
| 207 | 0 | $value = pack "l<", $object->{serialized_offset} + $reloc->{offset} - $reloc->{item}{serialized_offset}; | |||||||||||||||||||||||||||||
| 208 | } else { | ||||||||||||||||||||||||||||||
| 209 | ... | ||||||||||||||||||||||||||||||
| 210 | 0 | } | |||||||||||||||||||||||||||||
| 211 | 0 | substr $data, $object->{serialized_offset} + $reloc->{offset}, length($value), $value; | |||||||||||||||||||||||||||||
| 212 | } | ||||||||||||||||||||||||||||||
| 213 | } | ||||||||||||||||||||||||||||||
| 214 | } | ||||||||||||||||||||||||||||||
| 215 | |||||||||||||||||||||||||||||||
| 216 | # done, the data is now ready to be deserialized | ||||||||||||||||||||||||||||||
| 217 | 0 | return $data | |||||||||||||||||||||||||||||
| 218 | } | ||||||||||||||||||||||||||||||
| 219 | |||||||||||||||||||||||||||||||
| 220 | sub serialize_vtable { | ||||||||||||||||||||||||||||||
| 221 | 58 | ▶ | my ($self, @lengths) = @_; | ||||||||||||||||||||||||||||
|
Subroutine
serialize_vtable: called CC=4 SCAR=13.9
Pod
undocumented
| |||||||||||||||||||||||||||||||
| 222 | |||||||||||||||||||||||||||||||
| 223 | 58 | my $offset = 4; | |||||||||||||||||||||||||||||
| 224 | 58 | my @table; | |||||||||||||||||||||||||||||
| 225 | |||||||||||||||||||||||||||||||
| 226 | 58 | for (@lengths) { # parse table offsets | |||||||||||||||||||||||||||||
| 227 | 348 | ▶ | push @table, $_ ? $offset : 0; | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 228 | 348 | $offset += $_; | |||||||||||||||||||||||||||||
| 229 | } | ||||||||||||||||||||||||||||||
| 230 | |||||||||||||||||||||||||||||||
| 231 | 58 | unshift @table, $offset; # prefix data length | |||||||||||||||||||||||||||||
| 232 | 58 | unshift @table, 2 * (@table + 1); #prefix vtable length | |||||||||||||||||||||||||||||
| 233 | 58 | ▶ | push @table, 0 if @table % 2; # pad if odd count | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 234 | # compile object | ||||||||||||||||||||||||||||||
| 235 | 58 | return { type => "vtable", data => pack "S<" x @table, @table } | |||||||||||||||||||||||||||||
| 236 | } | ||||||||||||||||||||||||||||||
| 237 | |||||||||||||||||||||||||||||||
| 238 | sub serialize_string { | ||||||||||||||||||||||||||||||
| 239 | 48 | ▶ | my ($self, $string) = @_; | ||||||||||||||||||||||||||||
|
Subroutine
serialize_string: called CC=2 SCAR=7.0
Pod
undocumented
| |||||||||||||||||||||||||||||||
| 240 | |||||||||||||||||||||||||||||||
| 241 | 48 | my $len = pack "L<", length $string; | |||||||||||||||||||||||||||||
| 242 | 48 | $string .= "\0"; # null termination byte because why the fuck not (it's part of flatbuffers) | |||||||||||||||||||||||||||||
| 243 | |||||||||||||||||||||||||||||||
| 244 | 48 | my $data = "$len$string"; | |||||||||||||||||||||||||||||
| 245 | 48 | ▶ | $data .= pack "x" x (4 - (length ($data) % 4)) if length ($data) % 4; # pad to 4 byte boundary | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 246 | |||||||||||||||||||||||||||||||
| 247 | 48 | return { type => "string", data => $data } | |||||||||||||||||||||||||||||
| 248 | } | ||||||||||||||||||||||||||||||
| 249 | |||||||||||||||||||||||||||||||
| 250 | |||||||||||||||||||||||||||||||
| 251 | sub serialize_array { | ||||||||||||||||||||||||||||||
| 252 | 30 | ▶ | my ($self, $array_type, $array, $cache) = @_; | ||||||||||||||||||||||||||||
|
Subroutine
serialize_array: called CC=10 SCAR=37.8
Pod
undocumented
| |||||||||||||||||||||||||||||||
| 253 | |||||||||||||||||||||||||||||||
| 254 | 30 | $array_type = $array_type =~ s/\A\[(.*)\]\Z/$1/sr; | |||||||||||||||||||||||||||||
| 255 | |||||||||||||||||||||||||||||||
| 256 | 30 | my $data = pack "L<", scalar @$array; | |||||||||||||||||||||||||||||
| 257 | 30 | my @array_objects; | |||||||||||||||||||||||||||||
| 258 | my @reloc; | ||||||||||||||||||||||||||||||
| 259 | |||||||||||||||||||||||||||||||
| 260 | 30 | ▶ | if (exists $basic_types{$array_type}) { # array of scalar values | ||||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||||
| 261 | 0 | $data .= join "", map { pack $basic_types{$array_type}{format}, $_ } @$array; | |||||||||||||||||||||||||||||
| 262 | |||||||||||||||||||||||||||||||
| 263 | } elsif ($array_type eq "string") { # array of strings | ||||||||||||||||||||||||||||||
| 264 | 30 | $data .= "\0\0\0\0" x @$array; | |||||||||||||||||||||||||||||
| 265 | 30 | for my $i (0 .. $#$array) { | |||||||||||||||||||||||||||||
| 266 | 48 | my $string_object = $self->serialize_string($array->[$i]); | |||||||||||||||||||||||||||||
| 267 | 48 | push @array_objects, $string_object; | |||||||||||||||||||||||||||||
| 268 | 48 | push @reloc, { offset => 4 + $i * 4, item => $string_object, type => "unsigned delta" }; | |||||||||||||||||||||||||||||
| 269 | } | ||||||||||||||||||||||||||||||
| 270 | } elsif ($array_type =~ /\A\[/) { # array of arrays | ||||||||||||||||||||||||||||||
| 271 | 0 | $data .= "\0\0\0\0" x @$array; | |||||||||||||||||||||||||||||
| 272 | 0 | for my $i (0 .. $#$array) { | |||||||||||||||||||||||||||||
| 273 | 0 | my ($array_object, @child_array_objects) = $self->serialize_array($array_type, $array->[$i], $cache); | |||||||||||||||||||||||||||||
| 274 | 0 | push @array_objects, $array_object, @child_array_objects; | |||||||||||||||||||||||||||||
| 275 | 0 | push @reloc, { offset => 4 + $i * 4, item => $array_object, type => "unsigned delta" }; | |||||||||||||||||||||||||||||
| 276 | } | ||||||||||||||||||||||||||||||
| 277 | |||||||||||||||||||||||||||||||
| 278 | } else { # else an array of objects | ||||||||||||||||||||||||||||||
| 279 | 0 | ▶ | if ($array_type->flatbuffers_type eq "table") { | ||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||
| 280 | 0 | $data .= "\0\0\0\0" x @$array; | |||||||||||||||||||||||||||||
| 281 | 0 | for my $i (0 .. $#$array) { | |||||||||||||||||||||||||||||
| 282 | 0 | my ($root_object, @table_objects) = $array->[$i]->serialize($cache); | |||||||||||||||||||||||||||||
| 283 | 0 | push @array_objects, $root_object, @table_objects; | |||||||||||||||||||||||||||||
| 284 | 0 | push @reloc, { offset => 4 + $i * 4, item => $root_object, type => "unsigned delta" }; | |||||||||||||||||||||||||||||
| 285 | } | ||||||||||||||||||||||||||||||
| 286 | } elsif ($array_type->flatbuffers_type eq "struct") { | ||||||||||||||||||||||||||||||
| 287 | 0 | for my $i (0 .. $#$array) { | |||||||||||||||||||||||||||||
| 288 | 0 | my ($root_object, @struct_objects) = $array->[$i]->serialize($cache); | |||||||||||||||||||||||||||||
| 289 | 0 | push @array_objects, @struct_objects; | |||||||||||||||||||||||||||||
| 290 | 0 | push @reloc, map { $_->{offset} += length ($data); $_ } @{$root_object->{reloc}}; | |||||||||||||||||||||||||||||
| 291 | 0 | $data .= $root_object->{data}; | |||||||||||||||||||||||||||||
| 292 | |||||||||||||||||||||||||||||||
| 293 | } | ||||||||||||||||||||||||||||||
| 294 | } else { | ||||||||||||||||||||||||||||||
| 295 | ... | ||||||||||||||||||||||||||||||
| 296 | 0 | } | |||||||||||||||||||||||||||||
| 297 | } | ||||||||||||||||||||||||||||||
| 298 | |||||||||||||||||||||||||||||||
| 299 | 30 | return { type => "array", data => $data, reloc => \@reloc }, @array_objects | |||||||||||||||||||||||||||||
| 300 | } | ||||||||||||||||||||||||||||||
| 301 | |||||||||||||||||||||||||||||||
| 302 | |||||||||||||||||||||||||||||||
| 303 | |||||||||||||||||||||||||||||||
| 304 | 1 | 1 # true return from package | |||||||||||||||||||||||||||||
| 305 | |||||||||||||||||||||||||||||||