class Thrift::BufferedTransport
Constants
- DEFAULT_BUFFER
Public Class Methods
new(transport)
click to toggle source
# File lib/thrift/transport/buffered_transport.rb 25 def initialize(transport) 26 @transport = transport 27 @wbuf = '' 28 @rbuf = '' 29 @index = 0 30 end
Public Instance Methods
close()
click to toggle source
# File lib/thrift/transport/buffered_transport.rb 40 def close 41 flush 42 @transport.close 43 end
flush()
click to toggle source
# File lib/thrift/transport/buffered_transport.rb 93 def flush 94 if @wbuf != '' 95 @transport.write(@wbuf) 96 @wbuf = '' 97 end 98 99 @transport.flush 100 end
open()
click to toggle source
# File lib/thrift/transport/buffered_transport.rb 36 def open 37 @transport.open 38 end
open?()
click to toggle source
# File lib/thrift/transport/buffered_transport.rb 32 def open? 33 return @transport.open? 34 end
read(sz)
click to toggle source
# File lib/thrift/transport/buffered_transport.rb 45 def read(sz) 46 @index += sz 47 ret = @rbuf.slice(@index - sz, sz) || '' 48 49 if ret.length == 0 50 @rbuf = @transport.read([sz, DEFAULT_BUFFER].max) 51 @index = sz 52 ret = @rbuf.slice(0, sz) || '' 53 end 54 55 ret 56 end
read_byte()
click to toggle source
# File lib/thrift/transport/buffered_transport.rb 58 def read_byte 59 # If the read buffer is exhausted, try to read up to DEFAULT_BUFFER more bytes into it. 60 if @index >= @rbuf.size 61 @rbuf = @transport.read(DEFAULT_BUFFER) 62 @index = 0 63 end 64 65 # The read buffer has some data now, read a single byte. Using get_string_byte() avoids 66 # allocating a temp string of size 1 unnecessarily. 67 @index += 1 68 return ::Thrift::TransportUtils.get_string_byte(@rbuf, @index - 1) 69 end
read_into_buffer(buffer, size)
click to toggle source
# File lib/thrift/transport/buffered_transport.rb 71 def read_into_buffer(buffer, size) 72 i = 0 73 while i < size 74 # If the read buffer is exhausted, try to read up to DEFAULT_BUFFER more bytes into it. 75 if @index >= @rbuf.size 76 @rbuf = @transport.read(DEFAULT_BUFFER) 77 @index = 0 78 end 79 80 # The read buffer has some data now, so copy bytes over to the output buffer. 81 byte = ::Thrift::TransportUtils.get_string_byte(@rbuf, @index) 82 ::Thrift::TransportUtils.set_string_byte(buffer, i, byte) 83 @index += 1 84 i += 1 85 end 86 i 87 end
write(buf)
click to toggle source
# File lib/thrift/transport/buffered_transport.rb 89 def write(buf) 90 @wbuf << buf 91 end