line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Data::BitStream::Code::BER; |
2
|
28
|
|
|
28
|
|
25180
|
use strict; |
|
28
|
|
|
|
|
66
|
|
|
28
|
|
|
|
|
1214
|
|
3
|
28
|
|
|
28
|
|
165
|
use warnings; |
|
28
|
|
|
|
|
66
|
|
|
28
|
|
|
|
|
1413
|
|
4
|
|
|
|
|
|
|
BEGIN { |
5
|
28
|
|
|
28
|
|
78
|
$Data::BitStream::Code::BER::AUTHORITY = 'cpan:DANAJ'; |
6
|
28
|
|
|
|
|
2738
|
$Data::BitStream::Code::BER::VERSION = '0.08'; |
7
|
|
|
|
|
|
|
} |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
our $CODEINFO = { package => __PACKAGE__, |
10
|
|
|
|
|
|
|
name => 'BER', |
11
|
|
|
|
|
|
|
universal => 1, |
12
|
|
|
|
|
|
|
params => 0, |
13
|
|
|
|
|
|
|
encodesub => sub {shift->put_BER(@_)}, |
14
|
|
|
|
|
|
|
decodesub => sub {shift->get_BER(@_)}, }; |
15
|
|
|
|
|
|
|
|
16
|
28
|
|
|
28
|
|
165
|
use Moo::Role; |
|
28
|
|
|
|
|
71
|
|
|
28
|
|
|
|
|
218
|
|
17
|
|
|
|
|
|
|
requires qw(maxbits read write); |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
# Big-endian base-128 |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
sub put_BER { |
22
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
23
|
0
|
0
|
|
|
|
|
$self->error_stream_mode('write') unless $self->writing; |
24
|
|
|
|
|
|
|
|
25
|
0
|
|
|
|
|
|
foreach my $val (@_) { |
26
|
0
|
0
|
0
|
|
|
|
$self->error_code('zeroval') unless defined $val and $val >= 0; |
27
|
|
|
|
|
|
|
|
28
|
0
|
0
|
|
|
|
|
if ($val <= 127) { |
29
|
0
|
|
|
|
|
|
$self->write(8, $val); |
30
|
|
|
|
|
|
|
} else { |
31
|
|
|
|
|
|
|
# Simple method using pack |
32
|
0
|
|
|
|
|
|
$self->put_string( unpack("B*", pack("w", $val)) ); |
33
|
|
|
|
|
|
|
#my @bytes; |
34
|
|
|
|
|
|
|
#my $v = $val; |
35
|
|
|
|
|
|
|
#do { |
36
|
|
|
|
|
|
|
# unshift @bytes, ($v & 0x7F) | 0x80; |
37
|
|
|
|
|
|
|
# $v >>= 7; |
38
|
|
|
|
|
|
|
#} while ($v > 0); |
39
|
|
|
|
|
|
|
#$bytes[-1] &= 0x7F; # clear mark on last byte |
40
|
|
|
|
|
|
|
#foreach my $byte (@bytes) { |
41
|
|
|
|
|
|
|
# $self->write(8, $byte); |
42
|
|
|
|
|
|
|
#} |
43
|
|
|
|
|
|
|
} |
44
|
|
|
|
|
|
|
} |
45
|
0
|
|
|
|
|
|
1; |
46
|
|
|
|
|
|
|
} |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
sub get_BER { |
49
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
50
|
0
|
0
|
|
|
|
|
$self->error_stream_mode('read') if $self->writing; |
51
|
0
|
|
|
|
|
|
my $count = shift; |
52
|
0
|
0
|
|
|
|
|
if (!defined $count) { $count = 1; } |
|
0
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
53
|
0
|
|
|
|
|
|
elsif ($count < 0) { $count = ~0; } # Get everything |
54
|
0
|
|
|
|
|
|
elsif ($count == 0) { return; } |
55
|
|
|
|
|
|
|
|
56
|
0
|
|
|
|
|
|
my @vals; |
57
|
0
|
|
|
|
|
|
$self->code_pos_start('BER'); |
58
|
0
|
|
|
|
|
|
while ($count-- > 0) { |
59
|
0
|
|
|
|
|
|
$self->code_pos_set; |
60
|
0
|
|
|
|
|
|
my $byte = $self->read(8); |
61
|
0
|
0
|
|
|
|
|
last unless defined $byte; |
62
|
0
|
|
|
|
|
|
my $val = $byte & 0x7F; |
63
|
0
|
|
|
|
|
|
while ($byte > 127) { |
64
|
0
|
|
|
|
|
|
$byte = $self->read(8); |
65
|
0
|
0
|
|
|
|
|
$self->error_off_stream unless defined $byte; |
66
|
0
|
0
|
|
|
|
|
$self->error_code('overflow') if (($val << 7) >> 7) != $val; |
67
|
0
|
|
|
|
|
|
$val = ($val << 7) | ($byte & 0x7F); |
68
|
|
|
|
|
|
|
} |
69
|
0
|
|
|
|
|
|
push @vals, $val; |
70
|
|
|
|
|
|
|
} |
71
|
0
|
|
|
|
|
|
$self->code_pos_end; |
72
|
0
|
0
|
|
|
|
|
wantarray ? @vals : $vals[-1]; |
73
|
|
|
|
|
|
|
} |
74
|
28
|
|
|
28
|
|
22138
|
no Moo::Role; |
|
28
|
|
|
|
|
70
|
|
|
28
|
|
|
|
|
160
|
|
75
|
|
|
|
|
|
|
1; |