Subversion Repositories SmartDukaan

Rev

Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
30 ashish 1
#
2
# Licensed to the Apache Software Foundation (ASF) under one
3
# or more contributor license agreements. See the NOTICE file
4
# distributed with this work for additional information
5
# regarding copyright ownership. The ASF licenses this file
6
# to you under the Apache License, Version 2.0 (the
7
# "License"); you may not use this file except in compliance
8
# with the License. You may obtain a copy of the License at
9
#
10
#   http://www.apache.org/licenses/LICENSE-2.0
11
#
12
# Unless required by applicable law or agreed to in writing,
13
# software distributed under the License is distributed on an
14
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15
# KIND, either express or implied. See the License for the
16
# specific language governing permissions and limitations
17
# under the License.
18
#
19
 
20
our $VERSION = '0.1';
21
 
22
require 5.6.0;
23
use strict;
24
use warnings;
25
 
26
#
27
# Data types that can be sent via Thrift
28
#
29
package TType;
30
use constant STOP   => 0;
31
use constant VOID   => 1;
32
use constant BOOL   => 2;
33
use constant BYTE   => 3;
34
use constant I08    => 3;
35
use constant DOUBLE => 4;
36
use constant I16    => 6;
37
use constant I32    => 8;
38
use constant I64    => 10;
39
use constant STRING => 11;
40
use constant UTF7   => 11;
41
use constant STRUCT => 12;
42
use constant MAP    => 13;
43
use constant SET    => 14;
44
use constant LIST   => 15;
45
use constant UTF8   => 16;
46
use constant UTF16  => 17;
47
1;
48
 
49
#
50
# Message types for RPC
51
#
52
package TMessageType;
53
use constant CALL      => 1;
54
use constant REPLY     => 2;
55
use constant EXCEPTION => 3;
56
use constant ONEWAY    => 4;
57
1;
58
 
59
package Thrift::TException;
60
 
61
sub new {
62
    my $classname = shift;
63
    my $self = {message => shift, code => shift || 0};
64
 
65
    return bless($self,$classname);
66
}
67
1;
68
 
69
package TApplicationException;
70
use base('Thrift::TException');
71
 
72
use constant UNKNOWN              => 0;
73
use constant UNKNOWN_METHOD       => 1;
74
use constant INVALID_MESSAGE_TYPE => 2;
75
use constant WRONG_METHOD_NAME    => 3;
76
use constant BAD_SEQUENCE_ID      => 4;
77
use constant MISSING_RESULT       => 5;
78
 
79
sub new {
80
    my $classname = shift;
81
 
82
    my $self = $classname->SUPER::new();
83
 
84
    return bless($self,$classname);
85
}
86
 
87
sub read {
88
    my $self  = shift;
89
    my $input = shift;
90
 
91
    my $xfer  = 0;
92
    my $fname = undef;
93
    my $ftype = 0;
94
    my $fid   = 0;
95
 
96
    $xfer += $input->readStructBegin($fname);
97
 
98
    while (1)
99
    {
100
        $xfer += $input->readFieldBegin($fname, $ftype, $fid);
101
        if ($ftype == TType::STOP) {
102
            last; next;
103
        }
104
 
105
      SWITCH: for($fid)
106
      {
107
          /1/ && do{
108
 
109
              if ($ftype == TType::STRING) {
110
                  $xfer += $input->readString($self->{message});
111
              } else {
112
                  $xfer += $input->skip($ftype);
113
              }
114
 
115
              last;
116
          };
117
 
118
          /2/ && do{
119
              if ($ftype == TType::I32) {
120
                  $xfer += $input->readI32($self->{code});
121
              } else {
122
                  $xfer += $input->skip($ftype);
123
              }
124
              last;
125
          };
126
 
127
          $xfer += $input->skip($ftype);
128
      }
129
 
130
      $xfer += $input->readFieldEnd();
131
    }
132
    $xfer += $input->readStructEnd();
133
 
134
    return $xfer;
135
}
136
 
137
sub write {
138
    my $self   = shift;
139
    my $output = shift;
140
 
141
    my $xfer   = 0;
142
 
143
    $xfer += $output->writeStructBegin('TApplicationException');
144
 
145
    if ($self->getMessage()) {
146
        $xfer += $output->writeFieldBegin('message', TType::STRING, 1);
147
        $xfer += $output->writeString($self->getMessage());
148
        $xfer += $output->writeFieldEnd();
149
    }
150
 
151
    if ($self->getCode()) {
152
        $xfer += $output->writeFieldBegin('type', TType::I32, 2);
153
        $xfer += $output->writeI32($self->getCode());
154
        $xfer += $output->writeFieldEnd();
155
    }
156
 
157
    $xfer += $output->writeFieldStop();
158
    $xfer += $output->writeStructEnd();
159
 
160
    return $xfer;
161
}
162
 
163
sub getMessage
164
{
165
    my $self = shift;
166
 
167
    return $self->{message};
168
}
169
 
170
sub getCode
171
{
172
    my $self = shift;
173
 
174
    return $self->{code};
175
}
176
 
177
1;