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 | c2e37c7 | 2007-11-15 06:26:30 +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(tProtocol). |
| 8 | |
| 9 | -include("oop.hrl"). |
| 10 | |
| 11 | -include("thrift.hrl"). |
| 12 | -include("protocol/tProtocol.hrl"). |
| 13 | |
| 14 | -behavior(oop). |
| 15 | |
| 16 | -export([attr/4, super/0, inspect/1]). |
| 17 | |
Christopher Piro | 094823a | 2007-07-18 00:26:12 +0000 | [diff] [blame] | 18 | -export([ |
Christopher Piro | c2e37c7 | 2007-11-15 06:26:30 +0000 | [diff] [blame] | 19 | new/1, |
| 20 | skip/2, |
Christopher Piro | 094823a | 2007-07-18 00:26:12 +0000 | [diff] [blame] | 21 | |
Christopher Piro | c2e37c7 | 2007-11-15 06:26:30 +0000 | [diff] [blame] | 22 | writeMessageBegin/4, writeMessageEnd/1, |
| 23 | writeStructBegin/2, writeStructEnd/1, |
| 24 | writeFieldBegin/4, writeFieldEnd/1, writeFieldStop/1, |
| 25 | writeMapBegin/4, writeMapEnd/1, |
| 26 | writeListBegin/3, writeListEnd/1, |
| 27 | writeSetBegin/3, writeSetEnd/1, |
Christopher Piro | 094823a | 2007-07-18 00:26:12 +0000 | [diff] [blame] | 28 | |
Christopher Piro | c2e37c7 | 2007-11-15 06:26:30 +0000 | [diff] [blame] | 29 | writeBool/2, writeByte/2, writeI16/2, writeI32/2, |
| 30 | writeI64/2, writeDouble/2, writeString/2, |
Christopher Piro | 094823a | 2007-07-18 00:26:12 +0000 | [diff] [blame] | 31 | |
Christopher Piro | c2e37c7 | 2007-11-15 06:26:30 +0000 | [diff] [blame] | 32 | readMessageBegin/1, readMessageEnd/1, |
| 33 | readStructBegin/1, readStructEnd/1, |
| 34 | readFieldBegin/1, readFieldEnd/1, |
| 35 | readMapBegin/1, readMapEnd/1, |
| 36 | readListBegin/1, readListEnd/1, |
| 37 | readSetBegin/1, readSetEnd/1, |
Christopher Piro | 094823a | 2007-07-18 00:26:12 +0000 | [diff] [blame] | 38 | |
Christopher Piro | c2e37c7 | 2007-11-15 06:26:30 +0000 | [diff] [blame] | 39 | readBool/1, readByte/1, readI16/1, readI32/1, |
| 40 | readI64/1, readDouble/1, readString/1 |
| 41 | ]). |
Christopher Piro | 094823a | 2007-07-18 00:26:12 +0000 | [diff] [blame] | 42 | |
| 43 | %%% |
| 44 | %%% define attributes |
| 45 | %%% 'super' is required unless ?MODULE is a base class |
| 46 | %%% |
| 47 | |
| 48 | ?DEFINE_ATTR(trans). |
Christopher Piro | c2e37c7 | 2007-11-15 06:26:30 +0000 | [diff] [blame] | 49 | |
Christopher Piro | 094823a | 2007-07-18 00:26:12 +0000 | [diff] [blame] | 50 | %%% |
| 51 | %%% behavior callbacks |
| 52 | %%% |
Christopher Piro | c2e37c7 | 2007-11-15 06:26:30 +0000 | [diff] [blame] | 53 | |
Christopher Piro | 094823a | 2007-07-18 00:26:12 +0000 | [diff] [blame] | 54 | %%% super() -> SuperModule = atom() |
| 55 | %%% | none |
| 56 | |
| 57 | super() -> |
| 58 | none. |
| 59 | |
| 60 | %%% inspect(This) -> string() |
| 61 | |
| 62 | inspect(This) -> |
| 63 | ?FORMAT_ATTR(trans). |
| 64 | |
| 65 | %%% |
| 66 | %%% class methods |
| 67 | %%% |
| 68 | |
| 69 | new(Trans) -> |
| 70 | #?MODULE{trans=Trans}. |
| 71 | |
| 72 | %%% |
| 73 | %%% instance methods |
| 74 | %%% |
| 75 | |
| 76 | writeMessageBegin(_This, _Name, _Type, _Seqid) -> ok. |
| 77 | writeMessageEnd(_This) -> ok. |
| 78 | writeStructBegin(_This, _Name) -> ok. |
| 79 | writeStructEnd(_This) -> ok. |
| 80 | writeFieldBegin(_This, _Name, _Type, _Id) -> ok. |
| 81 | writeFieldEnd(_This) -> ok. |
| 82 | writeFieldStop(_This) -> ok. |
| 83 | writeMapBegin(_This, _Ktype, _Vtype, _Size) -> ok. |
| 84 | writeMapEnd(_This) -> ok. |
| 85 | writeListBegin(_This, _Etype, _Size) -> ok. |
| 86 | writeListEnd(_This) -> ok. |
| 87 | writeSetBegin(_This, _Etype, _Size) -> ok. |
| 88 | writeSetEnd(_This) -> ok. |
| 89 | |
| 90 | writeBool(_This, _Value) -> ok. |
| 91 | writeByte(_This, _Value) -> ok. |
| 92 | writeI16(_This, _Value) -> ok. |
| 93 | writeI32(_This, _Value) -> ok. |
| 94 | writeI64(_This, _Value) -> ok. |
| 95 | writeDouble(_This, _Value) -> ok. |
| 96 | writeString(_This, _Value) -> ok. |
| 97 | |
| 98 | readMessageBegin(_This) -> ok. |
| 99 | readMessageEnd(_This) -> ok. |
| 100 | readStructBegin(_This) -> ok. |
| 101 | readStructEnd(_This) -> ok. |
| 102 | readFieldBegin(_This) -> ok. |
| 103 | readFieldEnd(_This) -> ok. |
| 104 | readMapBegin(_This) -> ok. |
| 105 | readMapEnd(_This) -> ok. |
| 106 | readListBegin(_This) -> ok. |
| 107 | readListEnd(_This) -> ok. |
| 108 | readSetBegin(_This) -> ok. |
| 109 | readSetEnd(_This) -> ok. |
| 110 | |
| 111 | readBool(_This) -> ok. |
| 112 | readByte(_This) -> ok. |
| 113 | readI16(_This) -> ok. |
| 114 | readI32(_This) -> ok. |
| 115 | readI64(_This) -> ok. |
| 116 | readDouble(_This) -> ok. |
| 117 | readString(_This) -> ok. |
| 118 | |
| 119 | skip(This, Type) -> |
Christopher Piro | c2e37c7 | 2007-11-15 06:26:30 +0000 | [diff] [blame] | 120 | case Type of |
| 121 | ?tType_STOP -> nil; % WATCH |
| 122 | ?tType_BOOL -> ?L0(readBool); |
| 123 | ?tType_BYTE -> ?L0(readByte); |
| 124 | ?tType_I16 -> ?L0(readI16); |
| 125 | ?tType_I32 -> ?L0(readI32); |
| 126 | ?tType_I64 -> ?L0(readI64); |
| 127 | ?tType_DOUBLE -> ?L0(readDouble); |
| 128 | ?tType_STRING -> ?L0(readString); |
Christopher Piro | 094823a | 2007-07-18 00:26:12 +0000 | [diff] [blame] | 129 | |
Christopher Piro | c2e37c7 | 2007-11-15 06:26:30 +0000 | [diff] [blame] | 130 | ?tType_STRUCT -> |
| 131 | ?L0(readStructBegin), |
| 132 | skip_struct_loop(This), |
Christopher Piro | 094823a | 2007-07-18 00:26:12 +0000 | [diff] [blame] | 133 | |
Christopher Piro | c2e37c7 | 2007-11-15 06:26:30 +0000 | [diff] [blame] | 134 | %% cpiro: this isn't here in the original tprotocol.rb, but i think it's a bug |
| 135 | ?L0(readStructEnd); |
Christopher Piro | 094823a | 2007-07-18 00:26:12 +0000 | [diff] [blame] | 136 | |
Christopher Piro | c2e37c7 | 2007-11-15 06:26:30 +0000 | [diff] [blame] | 137 | ?tType_MAP -> |
| 138 | {Ktype, Vtype, Size} = ?L0(readMapBegin), |
| 139 | skip_map_repeat(This, Ktype, Vtype, Size), |
| 140 | ?L0(readMapEnd); |
Christopher Piro | 094823a | 2007-07-18 00:26:12 +0000 | [diff] [blame] | 141 | |
Christopher Piro | c2e37c7 | 2007-11-15 06:26:30 +0000 | [diff] [blame] | 142 | ?tType_SET -> |
| 143 | {Etype, Size} = ?L0(readSetBegin), |
| 144 | skip_set_repeat(This, Etype, Size), |
| 145 | ?L0(readSetEnd); |
Christopher Piro | 094823a | 2007-07-18 00:26:12 +0000 | [diff] [blame] | 146 | |
Christopher Piro | c2e37c7 | 2007-11-15 06:26:30 +0000 | [diff] [blame] | 147 | ?tType_LIST -> |
| 148 | {Etype, Size} = ?L0(readListBegin), |
| 149 | skip_set_repeat(This, Etype, Size), % [sic] skipping same as for SET |
| 150 | ?L0(readListEnd) |
Christopher Piro | 094823a | 2007-07-18 00:26:12 +0000 | [diff] [blame] | 151 | end. |
| 152 | |
| 153 | skip_struct_loop(This) -> |
| 154 | { _Name, Type, _Id } = ?L0(readFieldBegin), |
| 155 | if |
Christopher Piro | c2e37c7 | 2007-11-15 06:26:30 +0000 | [diff] [blame] | 156 | Type == ?tType_STOP -> |
| 157 | ok; |
Christopher Piro | 094823a | 2007-07-18 00:26:12 +0000 | [diff] [blame] | 158 | |
Christopher Piro | c2e37c7 | 2007-11-15 06:26:30 +0000 | [diff] [blame] | 159 | true -> |
| 160 | ?L1(skip, Type), |
| 161 | ?L0(readFieldEnd), |
| 162 | |
| 163 | %% cpiro: this is here in original tprotocol.rb, but i think it's a bug |
| 164 | %% ?L0(readStructEnd), |
| 165 | skip_struct_loop(This) |
Christopher Piro | 094823a | 2007-07-18 00:26:12 +0000 | [diff] [blame] | 166 | end. |
Christopher Piro | c2e37c7 | 2007-11-15 06:26:30 +0000 | [diff] [blame] | 167 | |
Christopher Piro | 094823a | 2007-07-18 00:26:12 +0000 | [diff] [blame] | 168 | skip_map_repeat(This, Ktype, Vtype, Times) -> |
| 169 | ?L1(skip, Ktype), |
| 170 | ?L1(skip, Vtype), |
| 171 | skip_map_repeat(This, Ktype, Vtype, Times-1). |
| 172 | |
| 173 | skip_set_repeat(This, Etype, Times) -> |
| 174 | ?L1(skip, Etype), |
| 175 | skip_set_repeat(This, Etype, Times-1). |