]>
Commit | Line | Data |
---|---|---|
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 | use 5.10.0; | |
21 | use strict; | |
22 | use warnings; | |
23 | ||
24 | use Thrift; | |
25 | use Thrift::Type; | |
26 | ||
27 | package Thrift::TException; | |
28 | use version 0.77; our $VERSION = version->declare("$Thrift::VERSION"); | |
29 | ||
30 | use overload '""' => sub { | |
31 | return | |
32 | sprintf '%s error: %s (code %s)', | |
33 | ref( $_[0] ), | |
34 | ( $_[0]->{message} || 'empty message' ), | |
35 | ( defined $_[0]->{code} ? $_[0]->{code} : 'undefined' ); | |
36 | }; | |
37 | ||
38 | sub new { | |
39 | my $classname = shift; | |
40 | my $self = {message => shift, code => shift || 0}; | |
41 | ||
42 | return bless($self,$classname); | |
43 | } | |
44 | ||
45 | package Thrift::TApplicationException; | |
46 | use parent -norequire, 'Thrift::TException'; | |
47 | use version 0.77; our $VERSION = version->declare("$Thrift::VERSION"); | |
48 | ||
49 | use constant UNKNOWN => 0; | |
50 | use constant UNKNOWN_METHOD => 1; | |
51 | use constant INVALID_MESSAGE_TYPE => 2; | |
52 | use constant WRONG_METHOD_NAME => 3; | |
53 | use constant BAD_SEQUENCE_ID => 4; | |
54 | use constant MISSING_RESULT => 5; | |
55 | use constant INTERNAL_ERROR => 6; | |
56 | use constant PROTOCOL_ERROR => 7; | |
57 | use constant INVALID_TRANSFORM => 8; | |
58 | use constant INVALID_PROTOCOL => 9; | |
59 | use constant UNSUPPORTED_CLIENT_TYPE => 10; | |
60 | ||
61 | sub new { | |
62 | my $classname = shift; | |
63 | ||
64 | my $self = $classname->SUPER::new(@_); | |
65 | ||
66 | return bless($self,$classname); | |
67 | } | |
68 | ||
69 | sub read { | |
70 | my $self = shift; | |
71 | my $input = shift; | |
72 | ||
73 | my $xfer = 0; | |
74 | my $fname = undef; | |
75 | my $ftype = 0; | |
76 | my $fid = 0; | |
77 | ||
78 | $xfer += $input->readStructBegin(\$fname); | |
79 | ||
80 | while (1) | |
81 | { | |
82 | $xfer += $input->readFieldBegin(\$fname, \$ftype, \$fid); | |
83 | if ($ftype == Thrift::TType::STOP) { | |
84 | last; next; | |
85 | } | |
86 | ||
87 | SWITCH: for($fid) | |
88 | { | |
89 | /1/ && do{ | |
90 | ||
91 | if ($ftype == Thrift::TType::STRING) { | |
92 | $xfer += $input->readString(\$self->{message}); | |
93 | } | |
94 | else { | |
95 | $xfer += $input->skip($ftype); | |
96 | } | |
97 | ||
98 | last; | |
99 | }; | |
100 | ||
101 | /2/ && do{ | |
102 | if ($ftype == Thrift::TType::I32) { | |
103 | $xfer += $input->readI32(\$self->{code}); | |
104 | } | |
105 | else { | |
106 | $xfer += $input->skip($ftype); | |
107 | } | |
108 | last; | |
109 | }; | |
110 | ||
111 | $xfer += $input->skip($ftype); | |
112 | } | |
113 | ||
114 | $xfer += $input->readFieldEnd(); | |
115 | } | |
116 | $xfer += $input->readStructEnd(); | |
117 | ||
118 | return $xfer; | |
119 | } | |
120 | ||
121 | sub write { | |
122 | my $self = shift; | |
123 | my $output = shift; | |
124 | ||
125 | my $xfer = 0; | |
126 | ||
127 | $xfer += $output->writeStructBegin('TApplicationException'); | |
128 | ||
129 | if ($self->getMessage()) { | |
130 | $xfer += $output->writeFieldBegin('message', Thrift::TType::STRING, 1); | |
131 | $xfer += $output->writeString($self->getMessage()); | |
132 | $xfer += $output->writeFieldEnd(); | |
133 | } | |
134 | ||
135 | if ($self->getCode()) { | |
136 | $xfer += $output->writeFieldBegin('type', Thrift::TType::I32, 2); | |
137 | $xfer += $output->writeI32($self->getCode()); | |
138 | $xfer += $output->writeFieldEnd(); | |
139 | } | |
140 | ||
141 | $xfer += $output->writeFieldStop(); | |
142 | $xfer += $output->writeStructEnd(); | |
143 | ||
144 | return $xfer; | |
145 | } | |
146 | ||
147 | sub getMessage | |
148 | { | |
149 | my $self = shift; | |
150 | ||
151 | return $self->{message}; | |
152 | } | |
153 | ||
154 | sub getCode | |
155 | { | |
156 | my $self = shift; | |
157 | ||
158 | return $self->{code}; | |
159 | } | |
160 | ||
161 | 1; |