blob: 39b051f14a945ec6d1908c5ec1c173dd3e780005 [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
Roger Meier22872782010-10-22 11:20:25 +000020our $VERSION = '0.6.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
72use 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;
78
79sub new {
80 my $classname = shift;
81
82 my $self = $classname->SUPER::new();
83
84 return bless($self,$classname);
85}
86
87sub 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
Bryan Duxburyee8255d2010-09-02 00:52:46 +000096 $xfer += $input->readStructBegin(\$fname);
Mark Slee254ce202007-05-16 02:21:06 +000097
98 while (1)
99 {
Bryan Duxburyee8255d2010-09-02 00:52:46 +0000100 $xfer += $input->readFieldBegin(\$fname, \$ftype, \$fid);
Mark Slee254ce202007-05-16 02:21:06 +0000101 if ($ftype == TType::STOP) {
102 last; next;
103 }
104
105 SWITCH: for($fid)
106 {
107 /1/ && do{
108
109 if ($ftype == TType::STRING) {
Bryan Duxburyee8255d2010-09-02 00:52:46 +0000110 $xfer += $input->readString(\$self->{message});
Mark Slee254ce202007-05-16 02:21:06 +0000111 } else {
112 $xfer += $input->skip($ftype);
113 }
114
115 last;
116 };
117
118 /2/ && do{
119 if ($ftype == TType::I32) {
Bryan Duxburyee8255d2010-09-02 00:52:46 +0000120 $xfer += $input->readI32(\$self->{code});
Mark Slee254ce202007-05-16 02:21:06 +0000121 } 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
137sub 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
163sub getMessage
164{
165 my $self = shift;
166
167 return $self->{message};
168}
169
170sub getCode
171{
172 my $self = shift;
173
174 return $self->{code};
175}
176
1771;