| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
#!/usr/local/bin/perl -w |
|
2
|
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
# |
|
4
|
|
|
|
|
|
|
# Copyright (C) 1995, 1996 Systemics Ltd (http://www.systemics.com/) |
|
5
|
|
|
|
|
|
|
# All rights reserved. |
|
6
|
|
|
|
|
|
|
# |
|
7
|
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
package Stream::DataEncoding; |
|
9
|
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
require 5.000; |
|
11
|
|
|
|
|
|
|
require Exporter; |
|
12
|
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
@ISA = qw(Exporter); |
|
14
|
|
|
|
|
|
|
@EXPORT_OK = qw( |
|
15
|
|
|
|
|
|
|
encodeByte |
|
16
|
|
|
|
|
|
|
encodeInt16 |
|
17
|
|
|
|
|
|
|
encodeInt32 |
|
18
|
|
|
|
|
|
|
encodeFloat |
|
19
|
|
|
|
|
|
|
encodeDouble |
|
20
|
|
|
|
|
|
|
encodeLength |
|
21
|
|
|
|
|
|
|
encodeTime |
|
22
|
|
|
|
|
|
|
encodeString |
|
23
|
|
|
|
|
|
|
decodeByte |
|
24
|
|
|
|
|
|
|
decodeInt16 |
|
25
|
|
|
|
|
|
|
decodeInt32 |
|
26
|
|
|
|
|
|
|
decodeFloat |
|
27
|
|
|
|
|
|
|
decodeDouble |
|
28
|
|
|
|
|
|
|
decodeLength |
|
29
|
|
|
|
|
|
|
decodeTime |
|
30
|
|
|
|
|
|
|
decodeString |
|
31
|
|
|
|
|
|
|
); |
|
32
|
|
|
|
|
|
|
|
|
33
|
1
|
|
|
1
|
|
5
|
use strict; |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
31
|
|
|
34
|
1
|
|
|
1
|
|
6
|
use Carp; |
|
|
1
|
|
|
|
|
1
|
|
|
|
1
|
|
|
|
|
599
|
|
|
35
|
|
|
|
|
|
|
|
|
36
|
9
|
|
|
9
|
0
|
42
|
sub encodeByte { pack("C", shift); } |
|
37
|
9
|
|
|
9
|
0
|
35
|
sub encodeInt16 { pack("n", shift); } |
|
38
|
9
|
|
|
9
|
0
|
33
|
sub encodeInt32 { pack("N", shift); } |
|
39
|
9
|
|
|
9
|
0
|
62
|
sub encodeFloat { pack("N", unpack("l", pack("f", shift))); } |
|
40
|
|
|
|
|
|
|
sub encodeDouble |
|
41
|
|
|
|
|
|
|
{ |
|
42
|
9
|
|
|
9
|
0
|
24
|
my ($l1, $l2) = unpack("l l", pack("d", shift)); |
|
43
|
9
|
|
|
|
|
34
|
pack("N N", $l2, $l1); # Machine dependant! |
|
44
|
|
|
|
|
|
|
} |
|
45
|
|
|
|
|
|
|
sub encodeLength |
|
46
|
|
|
|
|
|
|
{ |
|
47
|
45
|
|
|
45
|
0
|
54
|
my $l = shift; |
|
48
|
|
|
|
|
|
|
|
|
49
|
45
|
50
|
|
|
|
90
|
croak("Negative length") if ($l < 0); |
|
50
|
|
|
|
|
|
|
|
|
51
|
45
|
|
|
|
|
68
|
my $retval = pack("C", ($l & 0x7F)); |
|
52
|
45
|
|
|
|
|
42
|
$l = $l >> 7; |
|
53
|
|
|
|
|
|
|
|
|
54
|
45
|
|
|
|
|
92
|
while ($l != 0) |
|
55
|
|
|
|
|
|
|
{ |
|
56
|
27
|
|
|
|
|
51
|
$retval = pack("C", (0x80 | ($l & 0x7F))) . $retval; |
|
57
|
27
|
|
|
|
|
64
|
$l = $l >> 7; |
|
58
|
|
|
|
|
|
|
} |
|
59
|
|
|
|
|
|
|
|
|
60
|
45
|
|
|
|
|
168
|
$retval; |
|
61
|
|
|
|
|
|
|
} |
|
62
|
|
|
|
|
|
|
|
|
63
|
9
|
|
|
9
|
0
|
34
|
sub encodeTime { pack("N", shift); } |
|
64
|
|
|
|
|
|
|
sub encodeString |
|
65
|
|
|
|
|
|
|
{ |
|
66
|
9
|
|
|
9
|
0
|
11
|
my $str = shift; |
|
67
|
9
|
|
|
|
|
26
|
encodeLength(length($str)) . $str; |
|
68
|
|
|
|
|
|
|
} |
|
69
|
|
|
|
|
|
|
|
|
70
|
0
|
|
|
0
|
0
|
|
sub decodeByte { unpack("C", shift); } |
|
71
|
0
|
|
|
0
|
0
|
|
sub decodeInt16 { unpack("n", shift); } |
|
72
|
0
|
|
|
0
|
0
|
|
sub decodeInt32 { unpack("N", shift); } |
|
73
|
0
|
|
|
0
|
0
|
|
sub decodeFloat { unpack("f", pack("l", unpack("N", shift))); } |
|
74
|
|
|
|
|
|
|
sub decodeDouble |
|
75
|
|
|
|
|
|
|
{ |
|
76
|
0
|
|
|
0
|
0
|
|
my ($l1, $l2) = unpack("N N", shift); # Machine dependant! |
|
77
|
0
|
|
|
|
|
|
unpack("d", pack("l l", $l2, $l1)); |
|
78
|
|
|
|
|
|
|
} |
|
79
|
|
|
|
|
|
|
sub decodeLength |
|
80
|
|
|
|
|
|
|
{ |
|
81
|
0
|
|
|
0
|
0
|
|
my $data = shift; |
|
82
|
|
|
|
|
|
|
|
|
83
|
0
|
|
|
|
|
|
my $s = 0; |
|
84
|
0
|
|
|
|
|
|
my $i = 0; |
|
85
|
0
|
|
|
|
|
|
for(;;) |
|
86
|
|
|
|
|
|
|
{ |
|
87
|
0
|
0
|
|
|
|
|
return if (length($data) < $i); |
|
88
|
|
|
|
|
|
|
|
|
89
|
0
|
|
|
|
|
|
my $n = ord(substr($data, $i++, 1)); |
|
90
|
0
|
|
|
|
|
|
$s = ($s << 7) + (0x7F & $n); |
|
91
|
0
|
0
|
|
|
|
|
last if ($n < 128); # Last octet |
|
92
|
|
|
|
|
|
|
} |
|
93
|
0
|
|
|
|
|
|
$s; |
|
94
|
|
|
|
|
|
|
} |
|
95
|
0
|
|
|
0
|
0
|
|
sub decodeTime { unpack("N", shift); } |
|
96
|
0
|
|
|
0
|
0
|
|
sub decodeString { substr(shift, 2); } |
|
97
|
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
1; |