blob: 6b7a75d59b0ebbd6cbaa8ee64d6bb6e5e586d879 [file] [log] [blame]
Christian Lavoieafc6d8f2011-02-20 02:39:19 +00001/*
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
20package thrift
21
22import (
23 "os"
24)
25
26const (
27 UNKNOWN_APPLICATION_EXCEPTION = 0
28 UNKNOWN_METHOD = 1
29 INVALID_MESSAGE_TYPE_EXCEPTION = 2
30 WRONG_METHOD_NAME = 3
31 BAD_SEQUENCE_ID = 4
32 MISSING_RESULT = 5
33 INTERNAL_ERROR = 6
34 PROTOCOL_ERROR = 7
Roger Meier01931492012-12-22 21:31:03 +010035 INVALID_TRANSFORM = 8
36 INVALID_PROTOCOL = 9
37 UNSUPPORTED_CLIENT_TYPE = 10
Christian Lavoieafc6d8f2011-02-20 02:39:19 +000038)
39
40
41/**
42 * Application level exception
43 *
44 */
45type TApplicationException interface {
46 TException
47 TypeId() int32
48 Read(iprot TProtocol) (TApplicationException, os.Error)
49 Write(oprot TProtocol) os.Error
50}
51
52type tApplicationException struct {
53 TException
54 type_ int32
55}
56
57func NewTApplicationExceptionDefault() TApplicationException {
58 return NewTApplicationException(UNKNOWN_APPLICATION_EXCEPTION, "UNKNOWN")
59}
60
61func NewTApplicationExceptionType(type_ int32) TApplicationException {
62 return NewTApplicationException(type_, "UNKNOWN")
63}
64
65func NewTApplicationException(type_ int32, message string) TApplicationException {
66 return &tApplicationException{TException: NewTException(message), type_: type_}
67}
68
69func NewTApplicationExceptionMessage(message string) TApplicationException {
70 return NewTApplicationException(UNKNOWN_APPLICATION_EXCEPTION, message)
71}
72
73func (p *tApplicationException) TypeId() int32 {
74 return p.type_
75}
76
77func (p *tApplicationException) Read(iprot TProtocol) (error TApplicationException, err os.Error) {
78 _, err = iprot.ReadStructBegin()
79 if err != nil {
80 return
81 }
82
83 message := ""
84 type_ := int32(UNKNOWN_APPLICATION_EXCEPTION)
85
86 for {
87 _, ttype, id, err := iprot.ReadFieldBegin()
88 if err != nil {
89 return
90 }
91 if ttype == STOP {
92 break
93 }
94 switch id {
95 case 1:
96 if ttype == STRING {
97 message, err = iprot.ReadString()
98 if err != nil {
99 return
100 }
101 } else {
102 err = SkipDefaultDepth(iprot, ttype)
103 if err != nil {
104 return
105 }
106 }
107 break
108 case 2:
109 if ttype == I32 {
110 type_, err = iprot.ReadI32()
111 if err != nil {
112 return
113 }
114 } else {
115 err = SkipDefaultDepth(iprot, ttype)
116 if err != nil {
117 return
118 }
119 }
120 break
121 default:
122 err = SkipDefaultDepth(iprot, ttype)
123 if err != nil {
124 return
125 }
126 break
127 }
128 err = iprot.ReadFieldEnd()
129 if err != nil {
130 return
131 }
132 }
133 err = iprot.ReadStructEnd()
134 error = NewTApplicationException(type_, message)
135 return
136}
137
138func (p *tApplicationException) Write(oprot TProtocol) (err os.Error) {
139 err = oprot.WriteStructBegin("TApplicationException")
140 if len(p.String()) > 0 {
141 err = oprot.WriteFieldBegin("message", STRING, 1)
142 if err != nil {
143 return
144 }
145 err = oprot.WriteString(p.String())
146 if err != nil {
147 return
148 }
149 err = oprot.WriteFieldEnd()
150 if err != nil {
151 return
152 }
153 }
154 err = oprot.WriteFieldBegin("type", I32, 2)
155 if err != nil {
156 return
157 }
158 err = oprot.WriteI32(p.type_)
159 if err != nil {
160 return
161 }
162 err = oprot.WriteFieldEnd()
163 if err != nil {
164 return
165 }
166 err = oprot.WriteFieldStop()
167 if err != nil {
168 return
169 }
170 err = oprot.WriteStructEnd()
171 return
172}