| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package Sereal::Decoder; |
|
2
|
|
|
|
|
|
|
use 5.008; |
|
3
|
|
|
|
|
|
|
use strict; |
|
4
|
|
|
|
|
|
|
use warnings; |
|
5
|
|
|
|
|
|
|
use Carp qw/croak/; |
|
6
|
|
|
|
|
|
|
use XSLoader; |
|
7
|
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
our $VERSION= '4.011'; # Don't forget to update the TestCompat set for testing against installed encoders! |
|
9
|
|
|
|
|
|
|
our $XS_VERSION= $VERSION; $VERSION= eval $VERSION; |
|
10
|
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
# not for public consumption, just for testing. |
|
12
|
|
|
|
|
|
|
( my $num_version= $VERSION ) =~ s/_//; |
|
13
|
|
|
|
|
|
|
my $TestCompat= [ map sprintf( "%.2f", $_ / 100 ), reverse( 400 .. int( $num_version * 100 ) ) ]; # compat with 4.00 to ... |
|
14
|
0
|
|
|
0
|
|
|
sub _test_compat { return ( @$TestCompat, $VERSION ) } |
|
15
|
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
use Exporter 'import'; |
|
17
|
|
|
|
|
|
|
our @EXPORT_OK= qw( |
|
18
|
|
|
|
|
|
|
decode_sereal |
|
19
|
|
|
|
|
|
|
looks_like_sereal |
|
20
|
|
|
|
|
|
|
decode_sereal_with_header_data |
|
21
|
|
|
|
|
|
|
scalar_looks_like_sereal |
|
22
|
|
|
|
|
|
|
sereal_decode_with_object |
|
23
|
|
|
|
|
|
|
sereal_decode_with_header_with_object |
|
24
|
|
|
|
|
|
|
sereal_decode_only_header_with_object |
|
25
|
|
|
|
|
|
|
sereal_decode_only_header_with_offset_with_object |
|
26
|
|
|
|
|
|
|
sereal_decode_with_header_and_offset_with_object |
|
27
|
|
|
|
|
|
|
sereal_decode_with_offset_with_object |
|
28
|
|
|
|
|
|
|
); |
|
29
|
|
|
|
|
|
|
our %EXPORT_TAGS= ( all => \@EXPORT_OK ); |
|
30
|
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
# export by default if run from command line |
|
32
|
|
|
|
|
|
|
our @EXPORT= ( ( caller() )[1] eq '-e' ? @EXPORT_OK : () ); |
|
33
|
|
|
|
|
|
|
|
|
34
|
0
|
|
|
0
|
|
|
sub CLONE_SKIP { 1 } |
|
35
|
|
|
|
|
|
|
XSLoader::load( 'Sereal::Decoder', $XS_VERSION ); |
|
36
|
|
|
|
|
|
|
#start-no-tidy |
|
37
|
|
|
|
|
|
|
use constant #begin generated |
|
38
|
|
|
|
|
|
|
{ |
|
39
|
|
|
|
|
|
|
'SRL_F_DECODER_ALIAS_CHECK_FLAGS' => 28672, |
|
40
|
|
|
|
|
|
|
'SRL_F_DECODER_ALIAS_SMALLINT' => 4096, |
|
41
|
|
|
|
|
|
|
'SRL_F_DECODER_ALIAS_VARINT' => 8192, |
|
42
|
|
|
|
|
|
|
'SRL_F_DECODER_DECOMPRESS_SNAPPY' => 8, |
|
43
|
|
|
|
|
|
|
'SRL_F_DECODER_DECOMPRESS_ZLIB' => 16, |
|
44
|
|
|
|
|
|
|
'SRL_F_DECODER_DECOMPRESS_ZSTD' => 131072, |
|
45
|
|
|
|
|
|
|
'SRL_F_DECODER_DESTRUCTIVE_INCREMENTAL' => 1024, |
|
46
|
|
|
|
|
|
|
'SRL_F_DECODER_DIRTY' => 2, |
|
47
|
|
|
|
|
|
|
'SRL_F_DECODER_NEEDS_FINALIZE' => 4, |
|
48
|
|
|
|
|
|
|
'SRL_F_DECODER_NO_BLESS_OBJECTS' => 512, |
|
49
|
|
|
|
|
|
|
'SRL_F_DECODER_PROTOCOL_V1' => 2048, |
|
50
|
|
|
|
|
|
|
'SRL_F_DECODER_READONLY_FLAGS' => 98304, |
|
51
|
|
|
|
|
|
|
'SRL_F_DECODER_REFUSE_OBJECTS' => 128, |
|
52
|
|
|
|
|
|
|
'SRL_F_DECODER_REFUSE_SNAPPY' => 32, |
|
53
|
|
|
|
|
|
|
'SRL_F_DECODER_REFUSE_ZLIB' => 64, |
|
54
|
|
|
|
|
|
|
'SRL_F_DECODER_REFUSE_ZSTD' => 262144, |
|
55
|
|
|
|
|
|
|
'SRL_F_DECODER_REUSE' => 1, |
|
56
|
|
|
|
|
|
|
'SRL_F_DECODER_SET_READONLY' => 32768, |
|
57
|
|
|
|
|
|
|
'SRL_F_DECODER_SET_READONLY_SCALARS' => 65536, |
|
58
|
|
|
|
|
|
|
'SRL_F_DECODER_USE_UNDEF' => 16384, |
|
59
|
|
|
|
|
|
|
'SRL_F_DECODER_VALIDATE_UTF8' => 256, |
|
60
|
|
|
|
|
|
|
'SRL_F_DECODER_VOLATILE_FLAGS' => 133150, |
|
61
|
|
|
|
|
|
|
'_FLAG_NAME' => [ |
|
62
|
|
|
|
|
|
|
'REUSE', |
|
63
|
|
|
|
|
|
|
'DIRTY', |
|
64
|
|
|
|
|
|
|
'NEEDS_FINALIZE', |
|
65
|
|
|
|
|
|
|
'DECOMPRESS_SNAPPY', |
|
66
|
|
|
|
|
|
|
'DECOMPRESS_ZLIB', |
|
67
|
|
|
|
|
|
|
'REFUSE_SNAPPY', |
|
68
|
|
|
|
|
|
|
'REFUSE_ZLIB', |
|
69
|
|
|
|
|
|
|
'REFUSE_OBJECTS', |
|
70
|
|
|
|
|
|
|
'VALIDATE_UTF8', |
|
71
|
|
|
|
|
|
|
'NO_BLESS_OBJECTS', |
|
72
|
|
|
|
|
|
|
'DESTRUCTIVE_INCREMENTAL', |
|
73
|
|
|
|
|
|
|
'PROTOCOL_V1', |
|
74
|
|
|
|
|
|
|
'ALIAS_SMALLINT', |
|
75
|
|
|
|
|
|
|
'ALIAS_VARINT', |
|
76
|
|
|
|
|
|
|
'USE_UNDEF', |
|
77
|
|
|
|
|
|
|
'SET_READONLY', |
|
78
|
|
|
|
|
|
|
'SET_READONLY_SCALARS', |
|
79
|
|
|
|
|
|
|
'DECOMPRESS_ZSTD', |
|
80
|
|
|
|
|
|
|
'REFUSE_ZSTD' |
|
81
|
|
|
|
|
|
|
], |
|
82
|
|
|
|
|
|
|
'_FLAG_NAME_STATIC' => [ |
|
83
|
|
|
|
|
|
|
'REUSE', |
|
84
|
|
|
|
|
|
|
undef, |
|
85
|
|
|
|
|
|
|
undef, |
|
86
|
|
|
|
|
|
|
undef, |
|
87
|
|
|
|
|
|
|
undef, |
|
88
|
|
|
|
|
|
|
'REFUSE_SNAPPY', |
|
89
|
|
|
|
|
|
|
'REFUSE_ZLIB', |
|
90
|
|
|
|
|
|
|
'REFUSE_OBJECTS', |
|
91
|
|
|
|
|
|
|
'VALIDATE_UTF8', |
|
92
|
|
|
|
|
|
|
'NO_BLESS_OBJECTS', |
|
93
|
|
|
|
|
|
|
'DESTRUCTIVE_INCREMENTAL', |
|
94
|
|
|
|
|
|
|
undef, |
|
95
|
|
|
|
|
|
|
'ALIAS_SMALLINT', |
|
96
|
|
|
|
|
|
|
'ALIAS_VARINT', |
|
97
|
|
|
|
|
|
|
'USE_UNDEF', |
|
98
|
|
|
|
|
|
|
'SET_READONLY', |
|
99
|
|
|
|
|
|
|
'SET_READONLY_SCALARS', |
|
100
|
|
|
|
|
|
|
undef, |
|
101
|
|
|
|
|
|
|
'REFUSE_ZSTD' |
|
102
|
|
|
|
|
|
|
], |
|
103
|
|
|
|
|
|
|
'_FLAG_NAME_VOLATILE' => [ |
|
104
|
|
|
|
|
|
|
undef, |
|
105
|
|
|
|
|
|
|
'DIRTY', |
|
106
|
|
|
|
|
|
|
'NEEDS_FINALIZE', |
|
107
|
|
|
|
|
|
|
'DECOMPRESS_SNAPPY', |
|
108
|
|
|
|
|
|
|
'DECOMPRESS_ZLIB', |
|
109
|
|
|
|
|
|
|
undef, |
|
110
|
|
|
|
|
|
|
undef, |
|
111
|
|
|
|
|
|
|
undef, |
|
112
|
|
|
|
|
|
|
undef, |
|
113
|
|
|
|
|
|
|
undef, |
|
114
|
|
|
|
|
|
|
undef, |
|
115
|
|
|
|
|
|
|
'PROTOCOL_V1', |
|
116
|
|
|
|
|
|
|
undef, |
|
117
|
|
|
|
|
|
|
undef, |
|
118
|
|
|
|
|
|
|
undef, |
|
119
|
|
|
|
|
|
|
undef, |
|
120
|
|
|
|
|
|
|
undef, |
|
121
|
|
|
|
|
|
|
'DECOMPRESS_ZSTD', |
|
122
|
|
|
|
|
|
|
undef |
|
123
|
|
|
|
|
|
|
] |
|
124
|
|
|
|
|
|
|
}; #end generated |
|
125
|
|
|
|
|
|
|
#end-no-tidy |
|
126
|
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
sub decode_from_file { |
|
128
|
0
|
|
|
0
|
1
|
|
my ( $self, $file, )= @_; # pos 3 is "target var" if one is provided |
|
129
|
0
|
0
|
|
|
|
|
$self= $self->new() unless ref $self; |
|
130
|
0
|
0
|
|
|
|
|
open my $fh, "<", $file |
|
131
|
|
|
|
|
|
|
or die "Failed to open '$file' for read: $!"; |
|
132
|
0
|
|
|
|
|
|
my $buf= do { local $/; <$fh> }; |
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
133
|
0
|
0
|
|
|
|
|
close $fh |
|
134
|
|
|
|
|
|
|
or die "Failed to close '$file': $!"; |
|
135
|
0
|
0
|
0
|
|
|
|
if ( wantarray && ( $self->flags & SRL_F_DECODER_DESTRUCTIVE_INCREMENTAL ) ) { |
|
136
|
0
|
|
|
|
|
|
my @ret; |
|
137
|
0
|
|
|
|
|
|
while ( length $buf ) { |
|
138
|
0
|
|
|
|
|
|
push @ret, $self->decode($buf); |
|
139
|
|
|
|
|
|
|
} |
|
140
|
0
|
|
|
|
|
|
return @ret; |
|
141
|
|
|
|
|
|
|
} |
|
142
|
0
|
0
|
|
|
|
|
return $self->decode( $buf, @_ > 2 ? $_[2] : () ); |
|
143
|
|
|
|
|
|
|
} |
|
144
|
|
|
|
|
|
|
|
|
145
|
|
|
|
|
|
|
my $flags= sub { |
|
146
|
|
|
|
|
|
|
my ( $int, $ary )= @_; |
|
147
|
|
|
|
|
|
|
return map { ( $ary->[$_] and $int & ( 1 << $_ ) ) ? $ary->[$_] : () } ( 0 .. $#$ary ); |
|
148
|
|
|
|
|
|
|
}; |
|
149
|
|
|
|
|
|
|
|
|
150
|
|
|
|
|
|
|
sub flag_names { |
|
151
|
0
|
|
|
0
|
0
|
|
my ( $self, $val )= @_; |
|
152
|
0
|
0
|
|
|
|
|
return $flags->( defined $val ? $val : $self->flags, _FLAG_NAME ); |
|
153
|
|
|
|
|
|
|
} |
|
154
|
|
|
|
|
|
|
|
|
155
|
|
|
|
|
|
|
sub flag_names_volatile { |
|
156
|
0
|
|
|
0
|
0
|
|
my ( $self, $val )= @_; |
|
157
|
0
|
|
0
|
|
|
|
return $flags->( $val // $self->flags, _FLAG_NAME_VOLATILE ); |
|
158
|
|
|
|
|
|
|
} |
|
159
|
|
|
|
|
|
|
|
|
160
|
|
|
|
|
|
|
sub flag_names_static { |
|
161
|
0
|
|
|
0
|
0
|
|
my ( $self, $val )= @_; |
|
162
|
0
|
|
0
|
|
|
|
return $flags->( $val // $self->flags, _FLAG_NAME_STATIC ); |
|
163
|
|
|
|
|
|
|
} |
|
164
|
|
|
|
|
|
|
|
|
165
|
|
|
|
|
|
|
1; |
|
166
|
|
|
|
|
|
|
|
|
167
|
|
|
|
|
|
|
__END__ |