# File lib/thrift/transport/framed_transport.rb, line 22 def initialize(transport, read=true, write=true) @transport = transport @rbuf = '' @wbuf = '' @read = read @write = write @index = 0 end
# File lib/thrift/transport/framed_transport.rb, line 39 def close @transport.close end
Writes the output buffer to the stream in the format of a 4-byte length followed by the actual data.
# File lib/thrift/transport/framed_transport.rb, line 90 def flush return @transport.flush unless @write out = [@wbuf.length].pack('N') out << @wbuf @transport.write(out) @transport.flush @wbuf = '' end
# File lib/thrift/transport/framed_transport.rb, line 35 def open @transport.open end
# File lib/thrift/transport/framed_transport.rb, line 31 def open? @transport.open? end
# File lib/thrift/transport/framed_transport.rb, line 43 def read(sz) return @transport.read(sz) unless @read return '' if sz <= 0 read_frame if @index >= @rbuf.length @index += sz @rbuf.slice(@index - sz, sz) || '' end
# File lib/thrift/transport/framed_transport.rb, line 54 def read_byte return @transport.read_byte() unless @read read_frame if @index >= @rbuf.length # The read buffer has some data now, read a single byte. Using get_string_byte() avoids # allocating a temp string of size 1 unnecessarily. @index += 1 return ::Thrift::TransportUtils.get_string_byte(@rbuf, @index - 1) end
# File lib/thrift/transport/framed_transport.rb, line 65 def read_into_buffer(buffer, size) i = 0 while i < size read_frame if @index >= @rbuf.length # The read buffer has some data now, so copy bytes over to the output buffer. byte = ::Thrift::TransportUtils.get_string_byte(@rbuf, @index) ::Thrift::TransportUtils.set_string_byte(buffer, i, byte) @index += 1 i += 1 end i end
# File lib/thrift/transport/framed_transport.rb, line 80 def write(buf,sz=nil) return @transport.write(buf) unless @write @wbuf << (sz ? buf[0...sz] : buf) end
# File lib/thrift/transport/framed_transport.rb, line 102 def read_frame sz = @transport.read_all(4).unpack('N').first @index = 0 @rbuf = @transport.read_all(sz) end