blob: 67186f23cf9d8edf3233c3951b18c1dc85a52d57 [file] [log] [blame]
Mark Slee254ce202007-05-16 02:21:06 +00001#
David Reissea2cba82009-03-30 21:35:00 +00002# 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
Mark Slee254ce202007-05-16 02:21:06 +00009#
David Reissea2cba82009-03-30 21:35:00 +000010# http://www.apache.org/licenses/LICENSE-2.0
Mark Slee254ce202007-05-16 02:21:06 +000011#
David Reissea2cba82009-03-30 21:35:00 +000012# 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.
Mark Slee254ce202007-05-16 02:21:06 +000018#
19
Jake Farrell6fcecd42012-10-11 20:34:25 +000020our $VERSION = '1.0.0-dev';
Mark Slee254ce202007-05-16 02:21:06 +000021
22require 5.6.0;
23use strict;
24use warnings;
25
26#
27# Data types that can be sent via Thrift
28#
29package TType;
30use constant STOP => 0;
31use constant VOID => 1;
32use constant BOOL => 2;
33use constant BYTE => 3;
34use constant I08 => 3;
35use constant DOUBLE => 4;
36use constant I16 => 6;
37use constant I32 => 8;
38use constant I64 => 10;
39use constant STRING => 11;
40use constant UTF7 => 11;
41use constant STRUCT => 12;
42use constant MAP => 13;
43use constant SET => 14;
44use constant LIST => 15;
45use constant UTF8 => 16;
46use constant UTF16 => 17;
471;
48
49#
50# Message types for RPC
51#
52package TMessageType;
53use constant CALL => 1;
54use constant REPLY => 2;
55use constant EXCEPTION => 3;
David Reissdeda1412009-04-02 19:22:31 +000056use constant ONEWAY => 4;
Mark Slee254ce202007-05-16 02:21:06 +0000571;
58
59package Thrift::TException;
60
61sub new {
62 my $classname = shift;
63 my $self = {message => shift, code => shift || 0};
64
65 return bless($self,$classname);
66}
671;
68
69package TApplicationException;
70use base('Thrift::TException');
71
Roger Meier01931492012-12-22 21:31:03 +010072use constant UNKNOWN => 0;
73use constant UNKNOWN_METHOD => 1;
74use constant INVALID_MESSAGE_TYPE => 2;
75use constant WRONG_METHOD_NAME => 3;
76use constant BAD_SEQUENCE_ID => 4;
77use constant MISSING_RESULT => 5;
78use constant INTERNAL_ERROR => 6;
79use constant PROTOCOL_ERROR => 7;
80use constant INVALID_TRANSFORM => 8;
81use constant INVALID_PROTOCOL => 9;
82use constant UNSUPPORTED_CLIENT_TYPE => 10;
Mark Slee254ce202007-05-16 02:21:06 +000083
84sub new {
85 my $classname = shift;
86
87 my $self = $classname->SUPER::new();
88
89 return bless($self,$classname);
90}
91
92sub read {
93 my $self = shift;
94 my $input = shift;
95
96 my $xfer = 0;
97 my $fname = undef;
98 my $ftype = 0;
99 my $fid = 0;
100
Bryan Duxburyee8255d2010-09-02 00:52:46 +0000101 $xfer += $input->readStructBegin(\$fname);
Mark Slee254ce202007-05-16 02:21:06 +0000102
103 while (1)
104 {
Bryan Duxburyee8255d2010-09-02 00:52:46 +0000105 $xfer += $input->readFieldBegin(\$fname, \$ftype, \$fid);
Mark Slee254ce202007-05-16 02:21:06 +0000106 if ($ftype == TType::STOP) {
107 last; next;
108 }
109
110 SWITCH: for($fid)
111 {
112 /1/ && do{
113
114 if ($ftype == TType::STRING) {
Bryan Duxburyee8255d2010-09-02 00:52:46 +0000115 $xfer += $input->readString(\$self->{message});
Mark Slee254ce202007-05-16 02:21:06 +0000116 } else {
117 $xfer += $input->skip($ftype);
118 }
119
120 last;
121 };
122
123 /2/ && do{
124 if ($ftype == TType::I32) {
Bryan Duxburyee8255d2010-09-02 00:52:46 +0000125 $xfer += $input->readI32(\$self->{code});
Mark Slee254ce202007-05-16 02:21:06 +0000126 } else {
127 $xfer += $input->skip($ftype);
128 }
129 last;
130 };
131
132 $xfer += $input->skip($ftype);
133 }
134
135 $xfer += $input->readFieldEnd();
136 }
137 $xfer += $input->readStructEnd();
138
139 return $xfer;
140}
141
142sub write {
143 my $self = shift;
144 my $output = shift;
145
146 my $xfer = 0;
147
148 $xfer += $output->writeStructBegin('TApplicationException');
149
150 if ($self->getMessage()) {
151 $xfer += $output->writeFieldBegin('message', TType::STRING, 1);
152 $xfer += $output->writeString($self->getMessage());
153 $xfer += $output->writeFieldEnd();
154 }
155
156 if ($self->getCode()) {
157 $xfer += $output->writeFieldBegin('type', TType::I32, 2);
158 $xfer += $output->writeI32($self->getCode());
159 $xfer += $output->writeFieldEnd();
160 }
161
162 $xfer += $output->writeFieldStop();
163 $xfer += $output->writeStructEnd();
164
165 return $xfer;
166}
167
168sub getMessage
169{
170 my $self = shift;
171
172 return $self->{message};
173}
174
175sub getCode
176{
177 my $self = shift;
178
179 return $self->{code};
180}
181
1821;