| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
=head1 NAME |
|
2
|
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
Data::FastPack::Meta - Encode/decode rourines for fastpack meta data message payloads |
|
4
|
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
=cut |
|
6
|
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
package Data::FastPack::Meta; |
|
8
|
1
|
|
|
1
|
|
770
|
use strict; |
|
|
1
|
|
|
|
|
1
|
|
|
|
1
|
|
|
|
|
30
|
|
|
9
|
1
|
|
|
1
|
|
3
|
use warnings; |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
37
|
|
|
10
|
|
|
|
|
|
|
|
|
11
|
1
|
|
|
1
|
|
3
|
use Export::These qw; |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
5
|
|
|
12
|
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
# Meta / structured data encoding and decoding |
|
14
|
|
|
|
|
|
|
# ============================================ |
|
15
|
|
|
|
|
|
|
# |
|
16
|
|
|
|
|
|
|
# Structured or meta data messages are always of id 0. They |
|
17
|
|
|
|
|
|
|
# |
|
18
|
|
|
|
|
|
|
|
|
19
|
1
|
|
|
1
|
|
1588
|
use Cpanel::JSON::XS; |
|
|
1
|
|
|
|
|
5156
|
|
|
|
1
|
|
|
|
|
60
|
|
|
20
|
1
|
|
|
1
|
|
450
|
use Data::MessagePack; |
|
|
1
|
|
|
|
|
966
|
|
|
|
1
|
|
|
|
|
160
|
|
|
21
|
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
my $mp=Data::MessagePack->new(); |
|
23
|
|
|
|
|
|
|
$mp->prefer_integer(1); |
|
24
|
|
|
|
|
|
|
$mp->utf8(1); |
|
25
|
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
# Arguments: $payload, force_mp Forcing message pack decode is only needed if |
|
27
|
|
|
|
|
|
|
# the encoded data is not of map or array type. Otherise automatic decoding is |
|
28
|
|
|
|
|
|
|
# best |
|
29
|
|
|
|
|
|
|
sub decode_meta_payload { |
|
30
|
2
|
|
|
2
|
0
|
380
|
my ($payload,$force_mp)=@_; |
|
31
|
2
|
|
|
|
|
2
|
my $decodedMessage; |
|
32
|
|
|
|
|
|
|
|
|
33
|
2
|
|
|
|
|
5
|
for(unpack("C", $payload)) { |
|
34
|
2
|
100
|
66
|
|
|
12
|
if (!$force_mp and ($_== 0x5B || $_== 0x7B)) { |
|
|
|
|
66
|
|
|
|
|
|
35
|
|
|
|
|
|
|
#JSON encoded string |
|
36
|
1
|
|
|
|
|
42
|
$decodedMessage=decode_json($payload); |
|
37
|
|
|
|
|
|
|
} |
|
38
|
|
|
|
|
|
|
else { |
|
39
|
|
|
|
|
|
|
#msgpack encoded |
|
40
|
1
|
|
|
|
|
6
|
$decodedMessage=$mp->unpack($payload); |
|
41
|
|
|
|
|
|
|
} |
|
42
|
|
|
|
|
|
|
} |
|
43
|
2
|
|
|
|
|
4
|
$decodedMessage; |
|
44
|
|
|
|
|
|
|
} |
|
45
|
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
# Arguments: payload, force_mp |
|
47
|
|
|
|
|
|
|
sub encode_meta_payload { |
|
48
|
2
|
100
|
|
2
|
0
|
1608
|
$_[1]?$mp->encode($_[0]):encode_json($_[0]); |
|
49
|
|
|
|
|
|
|
} |
|
50
|
|
|
|
|
|
|
1; |