Christopher Piro | 094823a | 2007-07-18 00:26:12 +0000 | [diff] [blame] | 1 | %%% Copyright (c) 2007- Facebook |
| 2 | %%% Distributed under the Thrift Software License |
Christopher Piro | de11d85 | 2007-11-18 02:10:20 +0000 | [diff] [blame] | 3 | %%% |
Christopher Piro | 094823a | 2007-07-18 00:26:12 +0000 | [diff] [blame] | 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 | |
Christopher Piro | de11d85 | 2007-11-18 02:10:20 +0000 | [diff] [blame] | 25 | ?DEFINE_ATTR(super). |
| 26 | |
Christopher Piro | 094823a | 2007-07-18 00:26:12 +0000 | [diff] [blame] | 27 | %%% |
| 28 | %%% behavior callbacks |
| 29 | %%% |
| 30 | |
| 31 | %%% super() -> SuperModule = atom() |
| 32 | %%% | none |
| 33 | |
| 34 | super() -> |
| 35 | tException. |
| 36 | |
| 37 | %%% inspect(This) -> string() |
| 38 | |
| 39 | inspect(This) -> |
Christopher Piro | de11d85 | 2007-11-18 02:10:20 +0000 | [diff] [blame] | 40 | "". |
Christopher Piro | 094823a | 2007-07-18 00:26:12 +0000 | [diff] [blame] | 41 | |
| 42 | %%% |
| 43 | %%% class methods |
| 44 | %%% |
| 45 | |
| 46 | new(Type, Message) -> |
Christopher Piro | de11d85 | 2007-11-18 02:10:20 +0000 | [diff] [blame] | 47 | Super = (super()):new(Type, Message), |
| 48 | #?MODULE{super=Super}. |
Christopher Piro | 094823a | 2007-07-18 00:26:12 +0000 | [diff] [blame] | 49 | |
| 50 | new() -> new(?tApplicationException_UNKNOWN, undefined). |
| 51 | new(Type) -> new(Type, undefined). |
| 52 | |
| 53 | %%% |
| 54 | %%% instance methods |
| 55 | %%% |
| 56 | |
| 57 | read(This, Iprot) -> |
| 58 | ?R0(Iprot, readStructBegin), |
| 59 | read_while_loop(This, Iprot), |
| 60 | ?R0(Iprot, readStructEnd), |
| 61 | ok. |
| 62 | |
| 63 | read_while_loop(This, Iprot) -> |
| 64 | {_Fname, Ftype, Fid} = ?R0(Iprot, readFieldBegin), |
| 65 | |
Christopher Piro | de11d85 | 2007-11-18 02:10:20 +0000 | [diff] [blame] | 66 | if |
| 67 | Ftype == ?tType_STOP -> |
| 68 | ok; |
Christopher Piro | 094823a | 2007-07-18 00:26:12 +0000 | [diff] [blame] | 69 | |
Christopher Piro | de11d85 | 2007-11-18 02:10:20 +0000 | [diff] [blame] | 70 | (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 Piro | 094823a | 2007-07-18 00:26:12 +0000 | [diff] [blame] | 75 | |
Christopher Piro | de11d85 | 2007-11-18 02:10:20 +0000 | [diff] [blame] | 76 | Fid == 1 -> |
| 77 | ?R0(Iprot, skip), |
| 78 | ?R0(Iprot, readFieldEnd), |
| 79 | read_while_loop(This, Iprot); |
Christopher Piro | 094823a | 2007-07-18 00:26:12 +0000 | [diff] [blame] | 80 | |
Christopher Piro | de11d85 | 2007-11-18 02:10:20 +0000 | [diff] [blame] | 81 | (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 Piro | 094823a | 2007-07-18 00:26:12 +0000 | [diff] [blame] | 86 | |
Christopher Piro | de11d85 | 2007-11-18 02:10:20 +0000 | [diff] [blame] | 87 | true -> |
| 88 | ?R0(Iprot, skip), |
| 89 | ?R0(Iprot, readFieldEnd), |
| 90 | read_while_loop(This, Iprot) |
Christopher Piro | 094823a | 2007-07-18 00:26:12 +0000 | [diff] [blame] | 91 | end. |
| 92 | |
Christopher Piro | de11d85 | 2007-11-18 02:10:20 +0000 | [diff] [blame] | 93 | write(This, Oprot) -> |
Christopher Piro | 094823a | 2007-07-18 00:26:12 +0000 | [diff] [blame] | 94 | ?R1(Oprot, writeStructBegin, "tApplicationException"), |
| 95 | Message = oop:get(This, message), |
| 96 | Type = oop:get(This, type), |
| 97 | |
Christopher Piro | de11d85 | 2007-11-18 02:10:20 +0000 | [diff] [blame] | 98 | if Message /= undefined -> |
| 99 | ?R3(Oprot, writeFieldBegin, "message", ?tType_STRING, 1), |
| 100 | ?R1(Oprot, writeString, Message), |
| 101 | ?R0(Oprot, writeFieldEnd); |
Christopher Piro | 094823a | 2007-07-18 00:26:12 +0000 | [diff] [blame] | 102 | true -> ok |
| 103 | end, |
| 104 | |
Christopher Piro | de11d85 | 2007-11-18 02:10:20 +0000 | [diff] [blame] | 105 | if Type /= undefined -> |
| 106 | ?R3(Oprot, writeFieldBegin, "type", ?tType_I32, 2), |
| 107 | ?R1(Oprot, writeI32, Type), |
| 108 | ?R0(Oprot, writeFieldEnd); |
Christopher Piro | 094823a | 2007-07-18 00:26:12 +0000 | [diff] [blame] | 109 | true -> ok |
| 110 | end, |
| 111 | |
| 112 | ?R0(Oprot, writeFieldStop), |
| 113 | ?R0(Oprot, writeStructEnd), |
| 114 | ok. |