blob: 8900c5dca477428bdef3ccff8e35b3c1f494510d [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(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
18%% -export([interface/1]). %%
19
20-export([
21 new/1,
22 skip/2,
23
24 writeMessageBegin/4, writeMessageEnd/1,
25 writeStructBegin/2, writeStructEnd/1,
26 writeFieldBegin/4, writeFieldEnd/1, writeFieldStop/1,
27 writeMapBegin/4, writeMapEnd/1,
28 writeListBegin/3, writeListEnd/1,
29 writeSetBegin/3, writeSetEnd/1,
30
31 writeBool/2, writeByte/2, writeI16/2, writeI32/2,
32 writeI64/2, writeDouble/2, writeString/2,
33
34 readMessageBegin/1, readMessageEnd/1,
35 readStructBegin/1, readStructEnd/1,
36 readFieldBegin/1, readFieldEnd/1,
37 readMapBegin/1, readMapEnd/1,
38 readListBegin/1, readListEnd/1,
39 readSetBegin/1, readSetEnd/1,
40
41 readBool/1, readByte/1, readI16/1, readI32/1,
42 readI64/1, readDouble/1, readString/1
43]).
44
45%%%
46%%% server interface
47%%%
48
49%% %%% modules we can instantiate from the server %%
50%% interface(subclasses) -> %%
51%% [ %%
52%% tBinaryProtocol %%
53%% ]; %%
54%% %%
55%% %%% synchronous calls to pass %%
56%% interface(call) -> %%
57%% [ %%
58%% skip, %%
59%% %%
60%% writeMessageBegin, writeMessageEnd, %%
61%% writeStructBegin, writeStructEnd, %%
62%% writeFieldBegin, writeFieldEnd, writeFieldStop, %%
63%% writeMapBegin, writeMapEnd, %%
64%% writeListBegin, writeListEnd, %%
65%% writeSetBegin, writeSetEnd, %%
66%% %%
67%% writeBool, writeByte, writeI16, writeI32, %%
68%% writeI64, writeDouble, writeString, %%
69%% %%
70%% readMessageBegin, readMessageEnd, %%
71%% readStructBegin, readStructEnd, %%
72%% readFieldBegin, readFieldEnd, %%
73%% readMapBegin, readMapEnd, %%
74%% readListBegin, readListEnd, %%
75%% readSetBegin, readSetEnd, %%
76%% %%
77%% readBool, readByte, readI16, readI32, %%
78%% readI64, readDouble, readString %%
79%% ]; %%
80%% %%
81%% %%% asynchronous casts to pass %%
82%% interface(cast) -> %%
83%% []. %%
84
85%%%
86%%% define attributes
87%%% 'super' is required unless ?MODULE is a base class
88%%%
89
90?DEFINE_ATTR(trans).
91
92%%%
93%%% behavior callbacks
94%%%
95
96%%% super() -> SuperModule = atom()
97%%% | none
98
99super() ->
100 none.
101
102%%% inspect(This) -> string()
103
104inspect(This) ->
105 ?FORMAT_ATTR(trans).
106
107%%%
108%%% class methods
109%%%
110
111new(Trans) ->
112 #?MODULE{trans=Trans}.
113
114%%%
115%%% instance methods
116%%%
117
118writeMessageBegin(_This, _Name, _Type, _Seqid) -> ok.
119writeMessageEnd(_This) -> ok.
120writeStructBegin(_This, _Name) -> ok.
121writeStructEnd(_This) -> ok.
122writeFieldBegin(_This, _Name, _Type, _Id) -> ok.
123writeFieldEnd(_This) -> ok.
124writeFieldStop(_This) -> ok.
125writeMapBegin(_This, _Ktype, _Vtype, _Size) -> ok.
126writeMapEnd(_This) -> ok.
127writeListBegin(_This, _Etype, _Size) -> ok.
128writeListEnd(_This) -> ok.
129writeSetBegin(_This, _Etype, _Size) -> ok.
130writeSetEnd(_This) -> ok.
131
132writeBool(_This, _Value) -> ok.
133writeByte(_This, _Value) -> ok.
134writeI16(_This, _Value) -> ok.
135writeI32(_This, _Value) -> ok.
136writeI64(_This, _Value) -> ok.
137writeDouble(_This, _Value) -> ok.
138writeString(_This, _Value) -> ok.
139
140readMessageBegin(_This) -> ok.
141readMessageEnd(_This) -> ok.
142readStructBegin(_This) -> ok.
143readStructEnd(_This) -> ok.
144readFieldBegin(_This) -> ok.
145readFieldEnd(_This) -> ok.
146readMapBegin(_This) -> ok.
147readMapEnd(_This) -> ok.
148readListBegin(_This) -> ok.
149readListEnd(_This) -> ok.
150readSetBegin(_This) -> ok.
151readSetEnd(_This) -> ok.
152
153readBool(_This) -> ok.
154readByte(_This) -> ok.
155readI16(_This) -> ok.
156readI32(_This) -> ok.
157readI64(_This) -> ok.
158readDouble(_This) -> ok.
159readString(_This) -> ok.
160
161skip(This, Type) ->
162 case Type of
163 ?tType_STOP -> nil; % WATCH
164 ?tType_BOOL -> ?L0(readBool);
165 ?tType_BYTE -> ?L0(readByte);
166 ?tType_I16 -> ?L0(readI16);
167 ?tType_I32 -> ?L0(readI32);
168 ?tType_I64 -> ?L0(readI64);
169 ?tType_DOUBLE -> ?L0(readDouble);
170 ?tType_STRING -> ?L0(readString);
171
172 ?tType_STRUCT ->
173 ?L0(readStructBegin),
174 skip_struct_loop(This),
175
176 %% cpiro: this isn't here in the original tprotocol.rb, but i think it's a bug
177 ?L0(readStructEnd);
178
179 ?tType_MAP ->
180 {Ktype, Vtype, Size} = ?L0(readMapBegin),
181 skip_map_repeat(This, Ktype, Vtype, Size),
182 ?L0(readMapEnd);
183
184 ?tType_SET ->
185 {Etype, Size} = ?L0(readSetBegin),
186 skip_set_repeat(This, Etype, Size),
187 ?L0(readSetEnd);
188
189 ?tType_LIST ->
190 {Etype, Size} = ?L0(readListBegin),
191 skip_set_repeat(This, Etype, Size), % [sic] skipping same as for SET
192 ?L0(readListEnd)
193 end.
194
195skip_struct_loop(This) ->
196 { _Name, Type, _Id } = ?L0(readFieldBegin),
197 if
198 Type == ?tType_STOP ->
199 ok;
200
201 true ->
202 ?L1(skip, Type),
203 ?L0(readFieldEnd),
204
205 %% cpiro: this is here in original tprotocol.rb, but i think it's a bug
206 % ?L0(readStructEnd),
207 skip_struct_loop(This)
208 end.
209
210skip_map_repeat(This, Ktype, Vtype, Times) ->
211 ?L1(skip, Ktype),
212 ?L1(skip, Vtype),
213 skip_map_repeat(This, Ktype, Vtype, Times-1).
214
215skip_set_repeat(This, Etype, Times) ->
216 ?L1(skip, Etype),
217 skip_set_repeat(This, Etype, Times-1).