blob: 4ef67b801b75c1d01c9f564eea0de277a5f970b3 [file] [log] [blame]
Christopher Piro094823a2007-07-18 00:26:12 +00001%%% Copyright (c) 2007- Facebook
2%%% Distributed under the Thrift Software License
Christopher Piroc2e37c72007-11-15 06:26:30 +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(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 Piro094823a2007-07-18 00:26:12 +000018-export([
Christopher Piroc2e37c72007-11-15 06:26:30 +000019 new/1,
20 skip/2,
Christopher Piro094823a2007-07-18 00:26:12 +000021
Christopher Piroc2e37c72007-11-15 06:26:30 +000022 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 Piro094823a2007-07-18 00:26:12 +000028
Christopher Piroc2e37c72007-11-15 06:26:30 +000029 writeBool/2, writeByte/2, writeI16/2, writeI32/2,
30 writeI64/2, writeDouble/2, writeString/2,
Christopher Piro094823a2007-07-18 00:26:12 +000031
Christopher Piroc2e37c72007-11-15 06:26:30 +000032 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 Piro094823a2007-07-18 00:26:12 +000038
Christopher Piroc2e37c72007-11-15 06:26:30 +000039 readBool/1, readByte/1, readI16/1, readI32/1,
40 readI64/1, readDouble/1, readString/1
41 ]).
Christopher Piro094823a2007-07-18 00:26:12 +000042
43%%%
44%%% define attributes
45%%% 'super' is required unless ?MODULE is a base class
46%%%
47
48?DEFINE_ATTR(trans).
Christopher Piroc2e37c72007-11-15 06:26:30 +000049
Christopher Piro094823a2007-07-18 00:26:12 +000050%%%
51%%% behavior callbacks
52%%%
Christopher Piroc2e37c72007-11-15 06:26:30 +000053
Christopher Piro094823a2007-07-18 00:26:12 +000054%%% super() -> SuperModule = atom()
55%%% | none
56
57super() ->
58 none.
59
60%%% inspect(This) -> string()
61
62inspect(This) ->
63 ?FORMAT_ATTR(trans).
64
65%%%
66%%% class methods
67%%%
68
69new(Trans) ->
70 #?MODULE{trans=Trans}.
71
72%%%
73%%% instance methods
74%%%
75
76writeMessageBegin(_This, _Name, _Type, _Seqid) -> ok.
77writeMessageEnd(_This) -> ok.
78writeStructBegin(_This, _Name) -> ok.
79writeStructEnd(_This) -> ok.
80writeFieldBegin(_This, _Name, _Type, _Id) -> ok.
81writeFieldEnd(_This) -> ok.
82writeFieldStop(_This) -> ok.
83writeMapBegin(_This, _Ktype, _Vtype, _Size) -> ok.
84writeMapEnd(_This) -> ok.
85writeListBegin(_This, _Etype, _Size) -> ok.
86writeListEnd(_This) -> ok.
87writeSetBegin(_This, _Etype, _Size) -> ok.
88writeSetEnd(_This) -> ok.
89
90writeBool(_This, _Value) -> ok.
91writeByte(_This, _Value) -> ok.
92writeI16(_This, _Value) -> ok.
93writeI32(_This, _Value) -> ok.
94writeI64(_This, _Value) -> ok.
95writeDouble(_This, _Value) -> ok.
96writeString(_This, _Value) -> ok.
97
98readMessageBegin(_This) -> ok.
99readMessageEnd(_This) -> ok.
100readStructBegin(_This) -> ok.
101readStructEnd(_This) -> ok.
102readFieldBegin(_This) -> ok.
103readFieldEnd(_This) -> ok.
104readMapBegin(_This) -> ok.
105readMapEnd(_This) -> ok.
106readListBegin(_This) -> ok.
107readListEnd(_This) -> ok.
108readSetBegin(_This) -> ok.
109readSetEnd(_This) -> ok.
110
111readBool(_This) -> ok.
112readByte(_This) -> ok.
113readI16(_This) -> ok.
114readI32(_This) -> ok.
115readI64(_This) -> ok.
116readDouble(_This) -> ok.
117readString(_This) -> ok.
118
119skip(This, Type) ->
Christopher Piroc2e37c72007-11-15 06:26:30 +0000120 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 Piro094823a2007-07-18 00:26:12 +0000129
Christopher Piroc2e37c72007-11-15 06:26:30 +0000130 ?tType_STRUCT ->
131 ?L0(readStructBegin),
132 skip_struct_loop(This),
Christopher Piro094823a2007-07-18 00:26:12 +0000133
Christopher Piroc2e37c72007-11-15 06:26:30 +0000134 %% cpiro: this isn't here in the original tprotocol.rb, but i think it's a bug
135 ?L0(readStructEnd);
Christopher Piro094823a2007-07-18 00:26:12 +0000136
Christopher Piroc2e37c72007-11-15 06:26:30 +0000137 ?tType_MAP ->
138 {Ktype, Vtype, Size} = ?L0(readMapBegin),
139 skip_map_repeat(This, Ktype, Vtype, Size),
140 ?L0(readMapEnd);
Christopher Piro094823a2007-07-18 00:26:12 +0000141
Christopher Piroc2e37c72007-11-15 06:26:30 +0000142 ?tType_SET ->
143 {Etype, Size} = ?L0(readSetBegin),
144 skip_set_repeat(This, Etype, Size),
145 ?L0(readSetEnd);
Christopher Piro094823a2007-07-18 00:26:12 +0000146
Christopher Piroc2e37c72007-11-15 06:26:30 +0000147 ?tType_LIST ->
148 {Etype, Size} = ?L0(readListBegin),
149 skip_set_repeat(This, Etype, Size), % [sic] skipping same as for SET
150 ?L0(readListEnd)
Christopher Piro094823a2007-07-18 00:26:12 +0000151 end.
152
153skip_struct_loop(This) ->
154 { _Name, Type, _Id } = ?L0(readFieldBegin),
155 if
Christopher Piroc2e37c72007-11-15 06:26:30 +0000156 Type == ?tType_STOP ->
157 ok;
Christopher Piro094823a2007-07-18 00:26:12 +0000158
Christopher Piroc2e37c72007-11-15 06:26:30 +0000159 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 Piro094823a2007-07-18 00:26:12 +0000166 end.
Christopher Piroc2e37c72007-11-15 06:26:30 +0000167
Christopher Piro094823a2007-07-18 00:26:12 +0000168skip_map_repeat(This, Ktype, Vtype, Times) ->
169 ?L1(skip, Ktype),
170 ?L1(skip, Vtype),
171 skip_map_repeat(This, Ktype, Vtype, Times-1).
172
173skip_set_repeat(This, Etype, Times) ->
174 ?L1(skip, Etype),
175 skip_set_repeat(This, Etype, Times-1).