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
10 -- http://www.apache.org/licenses/LICENSE-2.0
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
22 TBufferedTransport = TTransportBase:new{
23 __type = 'TBufferedTransport',
30 function TBufferedTransport:new(obj)
31 if ttype(obj) ~= 'table' then
32 error(ttype(self) .. 'must be initialized with a table')
35 -- Ensure a transport is provided
37 error('You must provide ' .. ttype(self) .. ' with a trans')
40 return TTransportBase.new(self, obj)
43 function TBufferedTransport:isOpen()
44 return self.trans:isOpen()
47 function TBufferedTransport:open()
48 return self.trans:open()
51 function TBufferedTransport:close()
52 return self.trans:close()
55 function TBufferedTransport:read(len)
56 return self.trans:read(len)
59 function TBufferedTransport:readAll(len)
60 return self.trans:readAll(len)
63 function TBufferedTransport:write(buf)
64 self.wBuf = self.wBuf .. buf
65 if string.len(self.wBuf) >= self.wBufSize then
66 self.trans:write(self.wBuf)
71 function TBufferedTransport:flush()
72 if string.len(self.wBuf) > 0 then
73 self.trans:write(self.wBuf)
78 TBufferedTransportFactory = TTransportFactoryBase:new{
79 __type = 'TBufferedTransportFactory'
82 function TBufferedTransportFactory:getTransport(trans)
84 terror(TTransportException:new{
85 message = 'Must supply a transport to ' .. ttype(self)
88 return TBufferedTransport:new{