summaryrefslogtreecommitdiff
path: root/lib/Net/Riak/Transport/PBC/Code.pm
blob: 9231540fb11569b7860b9e58576bebd465d821be (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
package Net::Riak::Transport::PBC::Code;
use strict;
use warnings;
use base 'Exporter';

our @EXPORT_OK = qw/
    REQ_CODE
    RESP_CLASS
    EXPECTED_RESP
    RESP_DECODER
/;

sub EXPECTED_RESP {
    my $code = shift;
    return {
        1 => 2,
        3 => 4,
        5 => 6,
        7 => 8,
        9 => 10,
        11 => 12,
        13 => 14,
        15 => 16,
        17 => 18,
        19 => 20,
        21 => 22,
        23 => 24,
    }->{$code};
}
sub RESP_CLASS {
    my $code = shift;

    return {
        0 => 'RpbErrorResp',
        2 => 'RpbPingResp',
        4 => 'RpbGetClientIdResp',
        6 => 'RpbSetClientIdResp',
        8 => 'RpbGetServerInfoResp',
        10 => 'RpbGetResp',
        12 => 'RpbPutResp',
        14 => 'RpbDelResp',
        16 => 'RpbListBucketsResp',
        18 => 'RpbListKeysResp',
        20 => 'RpbGetBucketResp',
        22 => 'RpbSetBucketResp',
        24 => 'RpbMapRedResp',
    }->{$code};
}

sub RESP_DECODER {
    my $code = shift;

    return {
        0 => 'RpbErrorResp',
        2 => undef,
        4 => 'RpbGetClientIdResp',
        6 => undef,
        8 => 'RpbGetServerInfoResp',
        10 =>  'RpbGetResp',
        12 =>  'RpbPutResp',
        14 =>  undef,
        16 =>  'RpbListBucketsResp',
        18 =>  'RpbListKeysResp',
        20 =>  'RpbGetBucketResp',
        22 =>  undef,
        24 =>  'RpbMapRedResp'
    }->{$code};
};


sub REQ_CODE {
    my $class = shift;

    return {
        RpbPingReq => 1,
        RpbGetClientIdReq => 3,
        RpbSetClientIdReq => 5,
        RpbGetServerInfoReq => 7,
        RpbGetReq => 9,
        RpbPutReq => 11,
        RpbDelReq => 13,
        RpbListBucketsReq => 15,
        RpbListKeysReq => 17,
        RpbGetBucketReq => 19,
        RpbSetBucketReq => 21,
        RpbMapRedReq => 23,
    }->{$class};
}

1;