blob: 568b9c943874eda7c54f6c932e4bc023aa50c12b [file] [log] [blame]
Christopher Piro094823a2007-07-18 00:26:12 +00001%%% Copyright (c) 2007- Facebook
2%%% Distributed under the Thrift Software License
3%%%
4%%% See accompanying file LICENSE or visit the Thrift site at:
5%%% http://developers.facebook.com/thrift/
6
7-module(tApplicationException).
8
9-include("thrift.hrl").
10-include("tApplicationException.hrl").
11
12-include("oop.hrl").
13
14-behavior(oop).
15
16-export([attr/4, super/0, inspect/1]).
17
18-export([new/0, new/1, new/2, read/2, write/2]).
19
20%%%
21%%% define attributes
22%%% 'super' is required unless ?MODULE is a base class
23%%%
24
25?DEFINE_ATTR(super);
26?DEFINE_ATTR(type).
27
28%%%
29%%% behavior callbacks
30%%%
31
32%%% super() -> SuperModule = atom()
33%%% | none
34
35super() ->
36 tException.
37
38%%% inspect(This) -> string()
39
40inspect(This) ->
41 ?FORMAT_ATTR(type).
42
43%%%
44%%% class methods
45%%%
46
47new(Type, Message) ->
48 Super = (super()):new(Message),
49 #?MODULE{super=Super, type=Type}.
50
51new() -> new(?tApplicationException_UNKNOWN, undefined).
52new(Type) -> new(Type, undefined).
53
54%%%
55%%% instance methods
56%%%
57
58read(This, Iprot) ->
59 ?R0(Iprot, readStructBegin),
60 read_while_loop(This, Iprot),
61 ?R0(Iprot, readStructEnd),
62 ok.
63
64read_while_loop(This, Iprot) ->
65 {_Fname, Ftype, Fid} = ?R0(Iprot, readFieldBegin),
66
67 if
68 Ftype == ?tType_STOP ->
69 ok;
70
71 (Fid == 1) and (Ftype == ?tType_STRING) ->
72 Message1 = ?R0(Iprot, readString),
73 This1 = oop:set(This, message, Message1),
74 ?R0(Iprot, readFieldEnd),
75 read_while_loop(This1, Iprot);
76
77 Fid == 1 ->
78 ?R0(Iprot, skip),
79 ?R0(Iprot, readFieldEnd),
80 read_while_loop(This, Iprot);
81
82 (Fid == 2) and (Ftype == ?tType_I32) ->
83 Type1 = ?R0(Iprot, readI32),
84 This1 = oop:set(This, type, Type1),
85 ?R0(Iprot, readFieldEnd),
86 read_while_loop(This1, Iprot);
87
88 true ->
89 ?R0(Iprot, skip),
90 ?R0(Iprot, readFieldEnd),
91 read_while_loop(This, Iprot)
92 end.
93
94write(This, Oprot) ->
95 ?R1(Oprot, writeStructBegin, "tApplicationException"),
96 Message = oop:get(This, message),
97 Type = oop:get(This, type),
98
99 if Message /= undefined ->
100 ?R3(Oprot, writeFieldBegin, "message", ?tType_STRING, 1),
101 ?R1(Oprot, writeString, Message),
102 ?R0(Oprot, writeFieldEnd);
103 true -> ok
104 end,
105
106 if Type /= undefined ->
107 ?R3(Oprot, writeFieldBegin, "type", ?tType_I32, 2),
108 ?R1(Oprot, writeI32, Type),
109 ?R0(Oprot, writeFieldEnd);
110 true -> ok
111 end,
112
113 ?R0(Oprot, writeFieldStop),
114 ?R0(Oprot, writeStructEnd),
115 ok.