blob: d99b0037bbf2aad02bdb66d065be351c3986fce1 [file] [log] [blame]
Christopher Piro094823a2007-07-18 00:26:12 +00001%%% Copyright (c) 2007- Facebook
2%%% Distributed under the Thrift Software License
Christopher Pirode11d852007-11-18 02:10:20 +00003%%%
Christopher Piro094823a2007-07-18 00:26:12 +00004%%% 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
Christopher Pirode11d852007-11-18 02:10:20 +000025?DEFINE_ATTR(super).
26
Christopher Piro094823a2007-07-18 00:26:12 +000027%%%
28%%% behavior callbacks
29%%%
30
31%%% super() -> SuperModule = atom()
32%%% | none
33
34super() ->
35 tException.
36
37%%% inspect(This) -> string()
38
39inspect(This) ->
Christopher Pirode11d852007-11-18 02:10:20 +000040 "".
Christopher Piro094823a2007-07-18 00:26:12 +000041
42%%%
43%%% class methods
44%%%
45
46new(Type, Message) ->
Christopher Pirode11d852007-11-18 02:10:20 +000047 Super = (super()):new(Type, Message),
48 #?MODULE{super=Super}.
Christopher Piro094823a2007-07-18 00:26:12 +000049
50new() -> new(?tApplicationException_UNKNOWN, undefined).
51new(Type) -> new(Type, undefined).
52
53%%%
54%%% instance methods
55%%%
56
57read(This, Iprot) ->
58 ?R0(Iprot, readStructBegin),
59 read_while_loop(This, Iprot),
60 ?R0(Iprot, readStructEnd),
61 ok.
62
63read_while_loop(This, Iprot) ->
64 {_Fname, Ftype, Fid} = ?R0(Iprot, readFieldBegin),
65
Christopher Pirode11d852007-11-18 02:10:20 +000066 if
67 Ftype == ?tType_STOP ->
68 ok;
Christopher Piro094823a2007-07-18 00:26:12 +000069
Christopher Pirode11d852007-11-18 02:10:20 +000070 (Fid == 1) and (Ftype == ?tType_STRING) ->
71 Message1 = ?R0(Iprot, readString),
72 This1 = oop:set(This, message, Message1),
73 ?R0(Iprot, readFieldEnd),
74 read_while_loop(This1, Iprot);
Christopher Piro094823a2007-07-18 00:26:12 +000075
Christopher Pirode11d852007-11-18 02:10:20 +000076 Fid == 1 ->
77 ?R0(Iprot, skip),
78 ?R0(Iprot, readFieldEnd),
79 read_while_loop(This, Iprot);
Christopher Piro094823a2007-07-18 00:26:12 +000080
Christopher Pirode11d852007-11-18 02:10:20 +000081 (Fid == 2) and (Ftype == ?tType_I32) ->
82 Type1 = ?R0(Iprot, readI32),
83 This1 = oop:set(This, type, Type1),
84 ?R0(Iprot, readFieldEnd),
85 read_while_loop(This1, Iprot);
Christopher Piro094823a2007-07-18 00:26:12 +000086
Christopher Pirode11d852007-11-18 02:10:20 +000087 true ->
88 ?R0(Iprot, skip),
89 ?R0(Iprot, readFieldEnd),
90 read_while_loop(This, Iprot)
Christopher Piro094823a2007-07-18 00:26:12 +000091 end.
92
Christopher Pirode11d852007-11-18 02:10:20 +000093write(This, Oprot) ->
Christopher Piro094823a2007-07-18 00:26:12 +000094 ?R1(Oprot, writeStructBegin, "tApplicationException"),
95 Message = oop:get(This, message),
96 Type = oop:get(This, type),
97
Christopher Pirode11d852007-11-18 02:10:20 +000098 if Message /= undefined ->
99 ?R3(Oprot, writeFieldBegin, "message", ?tType_STRING, 1),
100 ?R1(Oprot, writeString, Message),
101 ?R0(Oprot, writeFieldEnd);
Christopher Piro094823a2007-07-18 00:26:12 +0000102 true -> ok
103 end,
104
Christopher Pirode11d852007-11-18 02:10:20 +0000105 if Type /= undefined ->
106 ?R3(Oprot, writeFieldBegin, "type", ?tType_I32, 2),
107 ?R1(Oprot, writeI32, Type),
108 ?R0(Oprot, writeFieldEnd);
Christopher Piro094823a2007-07-18 00:26:12 +0000109 true -> ok
110 end,
111
112 ?R0(Oprot, writeFieldStop),
113 ?R0(Oprot, writeStructEnd),
114 ok.