| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
# $Id: Message.pm,v 1.9 2014-01-28 15:40:10 joern Exp $ |
|
2
|
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
#----------------------------------------------------------------------- |
|
4
|
|
|
|
|
|
|
# Copyright (C) 2005-2015 by Jörn Reder . |
|
5
|
|
|
|
|
|
|
# All Rights Reserved. See file COPYRIGHT for details. |
|
6
|
|
|
|
|
|
|
# |
|
7
|
|
|
|
|
|
|
# This module is part of Event::RPC, which is free software; you can |
|
8
|
|
|
|
|
|
|
# redistribute it and/or modify it under the same terms as Perl itself. |
|
9
|
|
|
|
|
|
|
#----------------------------------------------------------------------- |
|
10
|
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
package Event::RPC::Message::Negotiate; |
|
12
|
|
|
|
|
|
|
|
|
13
|
31
|
|
|
31
|
|
145
|
use base Event::RPC::Message; |
|
|
31
|
|
|
|
|
54
|
|
|
|
31
|
|
|
|
|
11378
|
|
|
14
|
|
|
|
|
|
|
|
|
15
|
31
|
|
|
31
|
|
170
|
use Carp; |
|
|
31
|
|
|
|
|
106
|
|
|
|
31
|
|
|
|
|
1511
|
|
|
16
|
31
|
|
|
31
|
|
142
|
use strict; |
|
|
31
|
|
|
|
|
55
|
|
|
|
31
|
|
|
|
|
451
|
|
|
17
|
31
|
|
|
31
|
|
122
|
use utf8; |
|
|
31
|
|
|
|
|
37
|
|
|
|
31
|
|
|
|
|
94
|
|
|
18
|
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
my %MESSAGE_FORMATS = ( |
|
20
|
|
|
|
|
|
|
"SERL" => "Event::RPC::Message::Sereal", |
|
21
|
|
|
|
|
|
|
"CBOR" => "Event::RPC::Message::CBOR", |
|
22
|
|
|
|
|
|
|
"JSON" => "Event::RPC::Message::JSON", |
|
23
|
|
|
|
|
|
|
"STOR" => "Event::RPC::Message::Storable", |
|
24
|
|
|
|
|
|
|
); |
|
25
|
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
my @MESSAGE_FORMAT_ORDER = qw( SERL CBOR JSON STOR ); |
|
27
|
|
|
|
|
|
|
|
|
28
|
120
|
|
|
120
|
0
|
786
|
sub known_message_formats { \%MESSAGE_FORMATS } |
|
29
|
46
|
|
|
46
|
0
|
118086
|
sub message_format_order { \@MESSAGE_FORMAT_ORDER } |
|
30
|
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
my $STORABLE_FALLBACK_OK = 0; |
|
32
|
11
|
|
|
11
|
0
|
112
|
sub get_storable_fallback_ok { $STORABLE_FALLBACK_OK } |
|
33
|
94
|
|
|
94
|
0
|
389
|
sub set_storable_fallback_ok { $STORABLE_FALLBACK_OK = $_[1] } |
|
34
|
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
sub encode_message { |
|
36
|
158
|
|
|
158
|
0
|
354
|
my $self = shift; |
|
37
|
158
|
|
|
|
|
301
|
my ($decoded) = @_; |
|
38
|
|
|
|
|
|
|
|
|
39
|
158
|
|
100
|
|
|
1262
|
my $ok = $decoded->{ok} || ""; |
|
40
|
158
|
|
100
|
|
|
969
|
my $msg = $decoded->{msg} || ""; |
|
41
|
158
|
|
100
|
|
|
537
|
my $cmd = $decoded->{cmd} || ""; |
|
42
|
|
|
|
|
|
|
|
|
43
|
158
|
|
|
|
|
1407
|
s,/\d/,,g for ( $ok, $msg, $cmd ); |
|
44
|
|
|
|
|
|
|
|
|
45
|
158
|
|
|
|
|
944
|
return "/0/E:R:M:N/1/$ok/2/$msg/3/$cmd/0/"; |
|
46
|
|
|
|
|
|
|
} |
|
47
|
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
sub decode_message { |
|
49
|
159
|
|
|
159
|
0
|
400
|
my $self = shift; |
|
50
|
159
|
|
|
|
|
414
|
my ($encoded) = @_; |
|
51
|
|
|
|
|
|
|
|
|
52
|
159
|
100
|
|
|
|
2939
|
return { ok => $1, msg => $2, cmd => $3 } |
|
53
|
|
|
|
|
|
|
if $encoded =~ m,^/0/E:R:M:N/1/(.*?)/2/(.*?)/3/(.*?)/0/$,; |
|
54
|
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
#-- An old client or server may not know our message |
|
56
|
|
|
|
|
|
|
#-- format negotiation protocol, so we provide a Storable |
|
57
|
|
|
|
|
|
|
#-- fallback mechanism, if we're allowed to do so. |
|
58
|
11
|
100
|
|
|
|
118
|
if ( $self->get_storable_fallback_ok ) { |
|
59
|
10
|
|
|
|
|
186
|
require Event::RPC::Message::Storable; |
|
60
|
10
|
|
|
|
|
138
|
bless $self, "Event::RPC::Message::Storable"; |
|
61
|
10
|
|
|
|
|
103
|
return $self->decode_message($encoded); |
|
62
|
|
|
|
|
|
|
} |
|
63
|
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
#-- No Storable fallback allowed. We bail out! |
|
65
|
1
|
|
|
|
|
37
|
die "Error on message format negotitation and no fallback to Storable allowed\n"; |
|
66
|
|
|
|
|
|
|
} |
|
67
|
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
1; |
|
69
|
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
__END__ |