blob: 6655cc5a97204de66ee74530d08f3a857d905343 [file] [log] [blame]
Girish Gowdra631ef3d2020-06-15 10:45:52 -07001/*
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
22const (
23 UNKNOWN_APPLICATION_EXCEPTION = 0
24 UNKNOWN_METHOD = 1
25 INVALID_MESSAGE_TYPE_EXCEPTION = 2
26 WRONG_METHOD_NAME = 3
27 BAD_SEQUENCE_ID = 4
28 MISSING_RESULT = 5
29 INTERNAL_ERROR = 6
30 PROTOCOL_ERROR = 7
31)
32
33// Application level Thrift exception
34type TApplicationException interface {
35 TException
36 TypeId() int32
37 Read(iprot TProtocol) (TApplicationException, error)
38 Write(oprot TProtocol) error
39}
40
41type tApplicationException struct {
42 message string
43 type_ int32
44}
45
46func (e tApplicationException) Error() string {
47 return e.message
48}
49
50func NewTApplicationException(type_ int32, message string) TApplicationException {
51 return &tApplicationException{message, type_}
52}
53
54func (p *tApplicationException) TypeId() int32 {
55 return p.type_
56}
57
58func (p *tApplicationException) Read(iprot TProtocol) (TApplicationException, error) {
59 _, err := iprot.ReadStructBegin()
60 if err != nil {
61 return nil, err
62 }
63
64 message := ""
65 type_ := int32(UNKNOWN_APPLICATION_EXCEPTION)
66
67 for {
68 _, ttype, id, err := iprot.ReadFieldBegin()
69 if err != nil {
70 return nil, err
71 }
72 if ttype == STOP {
73 break
74 }
75 switch id {
76 case 1:
77 if ttype == STRING {
78 if message, err = iprot.ReadString(); err != nil {
79 return nil, err
80 }
81 } else {
82 if err = SkipDefaultDepth(iprot, ttype); err != nil {
83 return nil, err
84 }
85 }
86 case 2:
87 if ttype == I32 {
88 if type_, err = iprot.ReadI32(); err != nil {
89 return nil, err
90 }
91 } else {
92 if err = SkipDefaultDepth(iprot, ttype); err != nil {
93 return nil, err
94 }
95 }
96 default:
97 if err = SkipDefaultDepth(iprot, ttype); err != nil {
98 return nil, err
99 }
100 }
101 if err = iprot.ReadFieldEnd(); err != nil {
102 return nil, err
103 }
104 }
105 return NewTApplicationException(type_, message), iprot.ReadStructEnd()
106}
107
108func (p *tApplicationException) Write(oprot TProtocol) (err error) {
109 err = oprot.WriteStructBegin("TApplicationException")
110 if len(p.Error()) > 0 {
111 err = oprot.WriteFieldBegin("message", STRING, 1)
112 if err != nil {
113 return
114 }
115 err = oprot.WriteString(p.Error())
116 if err != nil {
117 return
118 }
119 err = oprot.WriteFieldEnd()
120 if err != nil {
121 return
122 }
123 }
124 err = oprot.WriteFieldBegin("type", I32, 2)
125 if err != nil {
126 return
127 }
128 err = oprot.WriteI32(p.type_)
129 if err != nil {
130 return
131 }
132 err = oprot.WriteFieldEnd()
133 if err != nil {
134 return
135 }
136 err = oprot.WriteFieldStop()
137 if err != nil {
138 return
139 }
140 err = oprot.WriteStructEnd()
141 return
142}