blob: 616e167a958401026ec2152fec5af884a3cadc66 [file] [log] [blame]
Roger Meier6cf0ffc2014-04-05 00:45:42 +02001--
2-- Licensed to the Apache Software Foundation (ASF) under one
3-- or more contributor license agreements. See the NOTICE file
4-- distributed with this work for additional information
5-- regarding copyright ownership. The ASF licenses this file
6-- to you under the Apache License, Version 2.0 (the
7-- "License"); you may not use this file except in compliance
8-- with the License. You may obtain a copy of the License at
9--
10-- http://www.apache.org/licenses/LICENSE-2.0
11--
12-- Unless required by applicable law or agreed to in writing,
13-- software distributed under the License is distributed on an
14-- "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15-- KIND, either express or implied. See the License for the
16-- specific language governing permissions and limitations
17-- under the License.
18--
19
20require 'Thrift'
21
22TProtocolException = TException:new {
23 UNKNOWN = 0,
24 INVALID_DATA = 1,
25 NEGATIVE_SIZE = 2,
26 SIZE_LIMIT = 3,
27 BAD_VERSION = 4,
28 INVALID_PROTOCOL = 5,
Jens Geyer6d1a83a2014-05-03 00:49:05 +020029 DEPTH_LIMIT = 6,
Roger Meier6cf0ffc2014-04-05 00:45:42 +020030 errorCode = 0,
31 __type = 'TProtocolException'
32}
33function TProtocolException:__errorCodeToString()
34 if self.errorCode == self.INVALID_DATA then
35 return 'Invalid data'
36 elseif self.errorCode == self.NEGATIVE_SIZE then
37 return 'Negative size'
38 elseif self.errorCode == self.SIZE_LIMIT then
39 return 'Size limit'
40 elseif self.errorCode == self.BAD_VERSION then
41 return 'Bad version'
42 elseif self.errorCode == self.INVALID_PROTOCOL then
43 return 'Invalid protocol'
Jens Geyer6d1a83a2014-05-03 00:49:05 +020044 elseif self.errorCode == self.DEPTH_LIMIT then
45 return 'Exceeded size limit'
Roger Meier6cf0ffc2014-04-05 00:45:42 +020046 else
47 return 'Default (unknown)'
48 end
49end
50
51TProtocolBase = __TObject:new{
52 __type = 'TProtocolBase',
53 trans
54}
55
56function TProtocolBase:new(obj)
57 if ttype(obj) ~= 'table' then
58 error(ttype(self) .. 'must be initialized with a table')
59 end
60
61 -- Ensure a transport is provided
62 if not obj.trans then
63 error('You must provide ' .. ttype(self) .. ' with a trans')
64 end
65
66 return __TObject.new(self, obj)
67end
68
69function TProtocolBase:writeMessageBegin(name, ttype, seqid) end
70function TProtocolBase:writeMessageEnd() end
71function TProtocolBase:writeStructBegin(name) end
72function TProtocolBase:writeStructEnd() end
73function TProtocolBase:writeFieldBegin(name, ttype, id) end
74function TProtocolBase:writeFieldEnd() end
75function TProtocolBase:writeFieldStop() end
76function TProtocolBase:writeMapBegin(ktype, vtype, size) end
77function TProtocolBase:writeMapEnd() end
78function TProtocolBase:writeListBegin(ttype, size) end
79function TProtocolBase:writeListEnd() end
80function TProtocolBase:writeSetBegin(ttype, size) end
81function TProtocolBase:writeSetEnd() end
82function TProtocolBase:writeBool(bool) end
83function TProtocolBase:writeByte(byte) end
84function TProtocolBase:writeI16(i16) end
85function TProtocolBase:writeI32(i32) end
86function TProtocolBase:writeI64(i64) end
87function TProtocolBase:writeDouble(dub) end
88function TProtocolBase:writeString(str) end
89function TProtocolBase:readMessageBegin() end
90function TProtocolBase:readMessageEnd() end
91function TProtocolBase:readStructBegin() end
92function TProtocolBase:readStructEnd() end
93function TProtocolBase:readFieldBegin() end
94function TProtocolBase:readFieldEnd() end
95function TProtocolBase:readMapBegin() end
96function TProtocolBase:readMapEnd() end
97function TProtocolBase:readListBegin() end
98function TProtocolBase:readListEnd() end
99function TProtocolBase:readSetBegin() end
100function TProtocolBase:readSetEnd() end
101function TProtocolBase:readBool() end
102function TProtocolBase:readByte() end
103function TProtocolBase:readI16() end
104function TProtocolBase:readI32() end
105function TProtocolBase:readI64() end
106function TProtocolBase:readDouble() end
107function TProtocolBase:readString() end
108
109function TProtocolBase:skip(ttype)
110 if type == TType.STOP then
111 return
112 elseif ttype == TType.BOOL then
113 self:readBool()
114 elseif ttype == TType.BYTE then
115 self:readByte()
116 elseif ttype == TType.I16 then
117 self:readI16()
118 elseif ttype == TType.I32 then
119 self:readI32()
120 elseif ttype == TType.I64 then
121 self:readI64()
122 elseif ttype == TType.DOUBLE then
123 self:readDouble()
124 elseif ttype == TType.STRING then
125 self:readString()
126 elseif ttype == TType.STRUCT then
127 local name = self:readStructBegin()
128 while true do
129 local name, ttype, id = self:readFieldBegin()
130 if ttype == TType.STOP then
131 break
132 end
133 self:skip(ttype)
134 self:readFieldEnd()
135 end
136 self:readStructEnd()
137 elseif ttype == TType.MAP then
138 local kttype, vttype, size = self:readMapBegin()
139 for i = 1, size, 1 do
140 self:skip(kttype)
141 self:skip(vttype)
142 end
143 self:readMapEnd()
144 elseif ttype == TType.SET then
145 local ettype, size = self:readSetBegin()
146 for i = 1, size, 1 do
147 self:skip(ettype)
148 end
149 self:readSetEnd()
150 elseif ttype == TType.LIST then
151 local ettype, size = self:readListBegin()
152 for i = 1, size, 1 do
153 self:skip(ettype)
154 end
155 self:readListEnd()
156 end
157end
158
159TProtocolFactory = __TObject:new{
160 __type = 'TProtocolFactory',
161}
162function TProtocolFactory:getProtocol(trans) end