Last active
December 31, 2015 03:19
-
-
Save wesyoung/7927182 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use strict; | |
use warnings; | |
use 5.011; | |
use Test::More; | |
use Data::Dumper; | |
BEGIN { | |
use_ok('CIF'); | |
use_ok('CIF::Protocol::Message'); | |
}; | |
my $m = CIF::Protocol::Message->new({ | |
version => '0.00000001', | |
Token => 1234, | |
mtype => 'reply', | |
stype => Ox::OxType::StypeType::stype_type_ext_value(), | |
ext_stype => 'test s', | |
ctype => 'ping', | |
Response => Ox::ResponseType->new({ | |
rtype => Ox::ResponseType::RtypeType::rtype_type_ping(), | |
Data => ['1234','12345'], | |
}), | |
}); | |
$m = $m->encode(); | |
warn Dumper($m); | |
$m = CIF::Protocol::Message->decode($m); | |
warn Dumper($m); | |
ok(ref($m) eq 'CIF::Protocol::Message'); | |
ok($m->get_stype() == Ox::OxType::StypeType::stype_type_ext_value()); | |
done_testing(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package CIF::Protocol::Message; | |
use strict; | |
use warnings; | |
use namespace::autoclean; | |
# moose | |
use Moose; | |
use MooseX::FollowPBP; | |
use MooseX::SlurpyConstructor; | |
use MooseX::NonMoose; | |
# local stuff | |
use CIF::Protocol::Type; | |
extends | |
'CIF::Protocol::Message::Token', | |
'CIF::Protocol::Message::Query', | |
'CIF::Protocol::Message::Ox'; | |
has 'version' => ( | |
is => 'ro', | |
default => '0.00000001', | |
); | |
has 'Token' => ( | |
is => 'rw', | |
isa => 'Str', | |
); | |
has 'mtype' => ( | |
is => 'rw', | |
isa => 'CIF::Protocol::Type::Mtype', | |
coerce => 1, | |
); | |
has 'stype' => ( | |
is => 'rw', | |
isa => 'CIF::Protocol::Type::Stype', | |
coerce => 1, | |
); | |
has 'ctype' => ( | |
is => 'rw', | |
isa => 'CIF::Protocol::Type::Ctype', | |
coerce => 1, | |
); | |
has [qw/ext_mtype ext_stype ext_ctype/] => ( | |
is => 'rw', | |
isa => 'Str', | |
); | |
has 'Response' => ( | |
is => 'ro', | |
isa => 'CIF::Protocol::Type::Response', | |
); | |
sub encode { | |
my $self = shift; | |
return Ox::OxType->encode($self); | |
} | |
sub decode { | |
my $class = shift; | |
my $str = shift; | |
return bless(Ox::OxType->decode($str),$class); | |
} | |
sub BUILD { | |
my $self = shift; | |
#warn ::Dumper($self); | |
} | |
1; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package Ox; | |
message ListClientsResponseType { | |
repeated string client = 1; | |
repeated int32 connectTimestamp = 2; | |
} | |
message PingResponseType { | |
optional double ts = 1; | |
optional int32 pingseq = 2; | |
} | |
message ListThreadsResponseType { | |
repeated string id = 1; | |
repeated string user = 2; | |
repeated string host = 3; | |
repeated string command = 4; | |
repeated int32 runtime = 5; | |
repeated string state = 6; | |
repeated string info = 7; | |
} | |
message StatsResponseType { | |
enum stype_type { | |
stype_type_router = 1; | |
stype_type_db = 2; | |
stype_type_ext_value = 3; | |
} | |
optional stype_type stype = 1; | |
optional string ext_stype = 2; | |
optional string stats = 3; | |
} | |
message ResponseType { | |
enum rtype_type { | |
rtype_type_ping = 1; | |
rtype_type_listclients = 2; | |
rtype_type_stats = 3; | |
rtype_type_query = 4; | |
rtype_type_token = 5; | |
rtype_type_ext_value = 99; | |
} | |
optional rtype_type rtype = 1; | |
optional string ext_rtype = 2; | |
repeated bytes Data = 99; | |
} | |
message OxType { | |
enum stype_type { | |
stype_type_success = 1; | |
stype_type_failed = 2; | |
stype_type_unauthorized = 3; | |
stype_type_duplicate = 4; | |
stype_type_ext_value = 99; | |
} | |
enum mtype_type { | |
mtype_type_command = 1; | |
mtype_type_reply = 2; | |
mtype_type_ext_value = 99; | |
} | |
enum ctype_type { | |
ctype_type_register = 1; | |
ctype_type_unregister = 2; | |
ctype_type_ipublish = 3; | |
ctype_type_listclients = 4; | |
ctype_type_shutdown = 5; | |
ctype_type_stats = 6; | |
ctype_type_ping = 7; | |
ctype_type_pause = 8; | |
ctype_type_resume = 9; | |
ctype_type_restart = 10; | |
ctype_type_thread_list = 300; | |
ctype_type_ext_value = 900; | |
} | |
optional double version = 1 [ default = 0.000001 ]; // 0.00.00-alpha.1 | |
optional mtype_type mtype = 2; | |
optional string ext_mtype = 3; | |
optional stype_type stype = 4; | |
optional string ext_stype = 5; | |
optional ctype_type ctype = 6; | |
optional string ext_ctype = 7; | |
optional string Token = 8; | |
repeated ResponseType Response = 9; | |
extensions 100 to 199; | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment