line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Hessian::Tiny::Type; |
2
|
|
|
|
|
|
|
|
3
|
2
|
|
|
2
|
|
13
|
use warnings; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
67
|
|
4
|
2
|
|
|
2
|
|
12
|
use strict; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
64
|
|
5
|
2
|
|
|
2
|
|
12
|
use Math::BigInt; |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
20
|
|
6
|
2
|
|
|
2
|
|
32640
|
use Config; |
|
2
|
|
|
|
|
5
|
|
|
2
|
|
|
|
|
94
|
|
7
|
2
|
|
|
2
|
|
1909
|
use fields qw(data type len class); |
|
2
|
|
|
|
|
3247
|
|
|
2
|
|
|
|
|
14
|
|
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
=head1 NAME |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
Hessian::Tiny::Type - Hessian Types & utility routines |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
=head1 SUBROUTINES/METHODS |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
=head2 new |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
base class for other types |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
=cut |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
sub new { |
22
|
104
|
|
|
104
|
1
|
1417
|
my($class,@params) = @_; |
23
|
104
|
100
|
|
|
|
598
|
my $self = 1 == scalar @params |
24
|
|
|
|
|
|
|
? {data=>$params[0]} |
25
|
|
|
|
|
|
|
: {@params} |
26
|
|
|
|
|
|
|
; |
27
|
104
|
|
|
|
|
1792
|
return bless $self, $class; |
28
|
|
|
|
|
|
|
} |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
# Hessian 1.0 Types |
31
|
2
|
|
|
2
|
|
302
|
{ package Hessian::Type::Null; use base 'Hessian::Tiny::Type'; } |
|
2
|
|
|
|
|
5
|
|
|
2
|
|
|
|
|
333
|
|
32
|
2
|
|
|
2
|
|
12
|
{ package Hessian::Type::True; use base 'Hessian::Tiny::Type'; } |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
208
|
|
33
|
2
|
|
|
2
|
|
10
|
{ package Hessian::Type::False; use base 'Hessian::Tiny::Type'; } |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
262
|
|
34
|
2
|
|
|
2
|
|
12
|
{ package Hessian::Type::Date; use base 'Hessian::Tiny::Type'; } |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
303
|
|
35
|
2
|
|
|
2
|
|
9
|
{ package Hessian::Type::Integer; use base 'Hessian::Tiny::Type'; } |
|
2
|
|
|
|
|
5
|
|
|
2
|
|
|
|
|
182
|
|
36
|
2
|
|
|
2
|
|
9
|
{ package Hessian::Type::Long; use base 'Hessian::Tiny::Type'; } |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
312
|
|
37
|
2
|
|
|
2
|
|
11
|
{ package Hessian::Type::Binary; use base 'Hessian::Tiny::Type'; } |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
248
|
|
38
|
2
|
|
|
2
|
|
11
|
{ package Hessian::Type::String; use base 'Hessian::Tiny::Type'; } |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
237
|
|
39
|
2
|
|
|
2
|
|
18
|
{ package Hessian::Type::XML; use base 'Hessian::Tiny::Type'; } # 1.0 only |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
214
|
|
40
|
2
|
|
|
2
|
|
11
|
{ package Hessian::Type::Double; use base 'Hessian::Tiny::Type'; } |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
220
|
|
41
|
2
|
|
|
2
|
|
12
|
{ package Hessian::Type::List; use base 'Hessian::Tiny::Type'; } |
|
2
|
|
|
|
|
2
|
|
|
2
|
|
|
|
|
239
|
|
42
|
2
|
|
|
2
|
|
11
|
{ package Hessian::Type::Map; use base 'Hessian::Tiny::Type'; } |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
253
|
|
43
|
2
|
|
|
2
|
|
12
|
{ package Hessian::Type::Header; use base 'Hessian::Tiny::Type'; } |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
223
|
|
44
|
2
|
|
|
2
|
|
64
|
{ package Hessian::Type::Remote; use base 'Hessian::Tiny::Type'; } |
|
2
|
|
|
|
|
11
|
|
|
2
|
|
|
|
|
209
|
|
45
|
2
|
|
|
2
|
|
9
|
{ package Hessian::Type::Fault; use base 'Hessian::Tiny::Type'; } |
|
2
|
|
|
|
|
9
|
|
|
2
|
|
|
|
|
211
|
|
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
# Hessian 2.0 Types |
48
|
2
|
|
|
2
|
|
10
|
{ package Hessian::Type::Class; use base 'Hessian::Tiny::Type'; } |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
205
|
|
49
|
2
|
|
|
2
|
|
9
|
{ package Hessian::Type::Object; use base 'Hessian::Tiny::Type'; } |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
1290
|
|
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
# helper functions for Convertor use |
52
|
|
|
|
|
|
|
sub _pack_q { # pack (64-bit) signed long |
53
|
21
|
|
|
21
|
|
55
|
my $bi = shift; |
54
|
21
|
50
|
|
|
|
95
|
$bi = Math::BigInt->new($bi) unless length(ref $bi) > 0; |
55
|
21
|
100
|
|
|
|
143
|
$bi = Math::BigInt->new('0x8000000000000000')->bmul(2)->badd($bi) if $bi->is_neg; |
56
|
21
|
|
|
|
|
5508
|
return pack 'H16', sprintf '%016s',substr($bi->as_hex, 2); |
57
|
|
|
|
|
|
|
} |
58
|
|
|
|
|
|
|
sub _unpack_q { # unpack (64-bit) signed long |
59
|
42
|
|
|
42
|
|
105
|
my $bytes = shift; |
60
|
42
|
|
|
|
|
2618
|
my $n = Math::BigInt->new('0x' . unpack('H16',$bytes)); |
61
|
42
|
|
|
|
|
12856
|
my $m = Math::BigInt->new('0x7fffffffffffffff'); |
62
|
42
|
100
|
|
|
|
15396
|
$n = Math::BigInt->new('0x8000000000000000')->bmul(-2)->badd($n) if $n->bcmp($m) > 0; |
63
|
42
|
|
|
|
|
11633
|
return $n; |
64
|
|
|
|
|
|
|
} |
65
|
|
|
|
|
|
|
#local to network order (and back) |
66
|
87
|
50
|
|
87
|
|
2705
|
sub _l2n { return $Config{'byteorder'} =~ /^1234/ ? scalar reverse $_[0] : $_[0] } |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
sub _make_reader { |
69
|
183
|
|
|
183
|
|
771
|
my $fh = shift; |
70
|
183
|
|
|
|
|
1622
|
binmode $fh, ':bytes'; |
71
|
|
|
|
|
|
|
return sub { |
72
|
585
|
|
|
585
|
|
20405
|
my($len,$utf8_flag) = @_; |
73
|
585
|
100
|
|
|
|
3936
|
binmode $fh, $utf8_flag ? ':utf8' : ':bytes'; |
74
|
585
|
100
|
|
|
|
2396
|
return seek $fh, $len, 1 if $len < 0; #rewind on negative len |
75
|
|
|
|
|
|
|
|
76
|
546
|
|
|
|
|
1020
|
my $buf = ''; |
77
|
546
|
|
|
|
|
3503
|
my $l = read $fh, $buf, $len; |
78
|
546
|
100
|
|
|
|
1799
|
die "_reader: want $len but got $l" unless $len == $l; |
79
|
544
|
|
|
|
|
3471
|
return $buf; |
80
|
|
|
|
|
|
|
} |
81
|
183
|
|
|
|
|
3295
|
} |
82
|
|
|
|
|
|
|
sub _make_writer { |
83
|
183
|
|
|
183
|
|
472
|
my $fh = shift; |
84
|
|
|
|
|
|
|
return sub { |
85
|
806
|
|
|
806
|
|
4921
|
my($buf,$utf8_flag) = @_; |
86
|
806
|
100
|
|
|
|
4596
|
binmode $fh, $utf8_flag ? ':utf8' : ':bytes'; |
87
|
806
|
|
|
|
|
32406
|
print $fh $buf; |
88
|
|
|
|
|
|
|
} |
89
|
183
|
|
|
|
|
1645
|
} |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
1; # End of Hessian::Type |