r1298@opsdev009 (orig r69998): cpiro | 2007-11-14 22:26:30 -0800
[amiethrift.git] / lib / erl / src / protocol / tProtocol.erl
blob4ef67b801b75c1d01c9f564eea0de277a5f970b3
1 %%% 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/
7 -module(tProtocol).
9 -include("oop.hrl").
11 -include("thrift.hrl").
12 -include("protocol/tProtocol.hrl").
14 -behavior(oop).
16 -export([attr/4, super/0, inspect/1]).
18 -export([
19 new/1,
20 skip/2,
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,
29 writeBool/2, writeByte/2, writeI16/2, writeI32/2,
30 writeI64/2, writeDouble/2, writeString/2,
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,
39 readBool/1, readByte/1, readI16/1, readI32/1,
40 readI64/1, readDouble/1, readString/1
41 ]).
43 %%%
44 %%% define attributes
45 %%% 'super' is required unless ?MODULE is a base class
46 %%%
48 ?DEFINE_ATTR(trans).
50 %%%
51 %%% behavior callbacks
52 %%%
54 %%% super() -> SuperModule = atom()
55 %%% | none
57 super() ->
58 none.
60 %%% inspect(This) -> string()
62 inspect(This) ->
63 ?FORMAT_ATTR(trans).
65 %%%
66 %%% class methods
67 %%%
69 new(Trans) ->
70 #?MODULE{trans=Trans}.
72 %%%
73 %%% instance methods
74 %%%
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.
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.
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.
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.
119 skip(This, Type) ->
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);
130 ?tType_STRUCT ->
131 ?L0(readStructBegin),
132 skip_struct_loop(This),
134 %% cpiro: this isn't here in the original tprotocol.rb, but i think it's a bug
135 ?L0(readStructEnd);
137 ?tType_MAP ->
138 {Ktype, Vtype, Size} = ?L0(readMapBegin),
139 skip_map_repeat(This, Ktype, Vtype, Size),
140 ?L0(readMapEnd);
142 ?tType_SET ->
143 {Etype, Size} = ?L0(readSetBegin),
144 skip_set_repeat(This, Etype, Size),
145 ?L0(readSetEnd);
147 ?tType_LIST ->
148 {Etype, Size} = ?L0(readListBegin),
149 skip_set_repeat(This, Etype, Size), % [sic] skipping same as for SET
150 ?L0(readListEnd)
151 end.
153 skip_struct_loop(This) ->
154 { _Name, Type, _Id } = ?L0(readFieldBegin),
156 Type == ?tType_STOP ->
159 true ->
160 ?L1(skip, Type),
161 ?L0(readFieldEnd),
163 %% cpiro: this is here in original tprotocol.rb, but i think it's a bug
164 %% ?L0(readStructEnd),
165 skip_struct_loop(This)
166 end.
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).
173 skip_set_repeat(This, Etype, Times) ->
174 ?L1(skip, Etype),
175 skip_set_repeat(This, Etype, Times-1).