blob: f3ff287f8626ce17c9024e6ae4b388fd9fdd484a [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 Farrell99010692011-11-30 02:09:46 +000020our $VERSION = '0.9.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;
Roger Meier345ecc72011-08-03 09:49:27 +000078use constant INTERNAL_ERROR => 6;
79use constant PROTOCOL_ERROR => 7;
Mark Slee254ce202007-05-16 02:21:06 +000080
81sub new {
82 my $classname = shift;
83
84 my $self = $classname->SUPER::new();
85
86 return bless($self,$classname);
87}
88
89sub read {
90 my $self = shift;
91 my $input = shift;
92
93 my $xfer = 0;
94 my $fname = undef;
95 my $ftype = 0;
96 my $fid = 0;
97
Bryan Duxburyee8255d2010-09-02 00:52:46 +000098 $xfer += $input->readStructBegin(\$fname);
Mark Slee254ce202007-05-16 02:21:06 +000099
100 while (1)
101 {
Bryan Duxburyee8255d2010-09-02 00:52:46 +0000102 $xfer += $input->readFieldBegin(\$fname, \$ftype, \$fid);
Mark Slee254ce202007-05-16 02:21:06 +0000103 if ($ftype == TType::STOP) {
104 last; next;
105 }
106
107 SWITCH: for($fid)
108 {
109 /1/ && do{
110
111 if ($ftype == TType::STRING) {
Bryan Duxburyee8255d2010-09-02 00:52:46 +0000112 $xfer += $input->readString(\$self->{message});
Mark Slee254ce202007-05-16 02:21:06 +0000113 } else {
114 $xfer += $input->skip($ftype);
115 }
116
117 last;
118 };
119
120 /2/ && do{
121 if ($ftype == TType::I32) {
Bryan Duxburyee8255d2010-09-02 00:52:46 +0000122 $xfer += $input->readI32(\$self->{code});
Mark Slee254ce202007-05-16 02:21:06 +0000123 } else {
124 $xfer += $input->skip($ftype);
125 }
126 last;
127 };
128
129 $xfer += $input->skip($ftype);
130 }
131
132 $xfer += $input->readFieldEnd();
133 }
134 $xfer += $input->readStructEnd();
135
136 return $xfer;
137}
138
139sub write {
140 my $self = shift;
141 my $output = shift;
142
143 my $xfer = 0;
144
145 $xfer += $output->writeStructBegin('TApplicationException');
146
147 if ($self->getMessage()) {
148 $xfer += $output->writeFieldBegin('message', TType::STRING, 1);
149 $xfer += $output->writeString($self->getMessage());
150 $xfer += $output->writeFieldEnd();
151 }
152
153 if ($self->getCode()) {
154 $xfer += $output->writeFieldBegin('type', TType::I32, 2);
155 $xfer += $output->writeI32($self->getCode());
156 $xfer += $output->writeFieldEnd();
157 }
158
159 $xfer += $output->writeFieldStop();
160 $xfer += $output->writeStructEnd();
161
162 return $xfer;
163}
164
165sub getMessage
166{
167 my $self = shift;
168
169 return $self->{message};
170}
171
172sub getCode
173{
174 my $self = shift;
175
176 return $self->{code};
177}
178
1791;