Class | Thrift::BufferedTransport |
In: |
lib/thrift/transport/buffered_transport.rb
lib/thrift/transport/buffered_transport.rb |
Parent: | BaseTransport |
DEFAULT_BUFFER | = | 4096 |
DEFAULT_BUFFER | = | 4096 |
# File lib/thrift/transport/buffered_transport.rb, line 25 25: def initialize(transport) 26: @transport = transport 27: @wbuf = '' 28: @rbuf = '' 29: @index = 0 30: end
# File lib/thrift/transport/buffered_transport.rb, line 25 25: def initialize(transport) 26: @transport = transport 27: @wbuf = '' 28: @rbuf = '' 29: @index = 0 30: end
# File lib/thrift/transport/buffered_transport.rb, line 40 40: def close 41: flush 42: @transport.close 43: end
# File lib/thrift/transport/buffered_transport.rb, line 40 40: def close 41: flush 42: @transport.close 43: end
# File lib/thrift/transport/buffered_transport.rb, line 93 93: def flush 94: if @wbuf != '' 95: @transport.write(@wbuf) 96: @wbuf = '' 97: end 98: 99: @transport.flush 100: end
# File lib/thrift/transport/buffered_transport.rb, line 93 93: def flush 94: if @wbuf != '' 95: @transport.write(@wbuf) 96: @wbuf = '' 97: end 98: 99: @transport.flush 100: end
# File lib/thrift/transport/buffered_transport.rb, line 32 32: def open? 33: return @transport.open? 34: end
# File lib/thrift/transport/buffered_transport.rb, line 32 32: def open? 33: return @transport.open? 34: end
# File lib/thrift/transport/buffered_transport.rb, line 45 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
# File lib/thrift/transport/buffered_transport.rb, line 45 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
# File lib/thrift/transport/buffered_transport.rb, line 58 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
# File lib/thrift/transport/buffered_transport.rb, line 58 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
# File lib/thrift/transport/buffered_transport.rb, line 71 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
# File lib/thrift/transport/buffered_transport.rb, line 71 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
# File lib/thrift/transport/buffered_transport.rb, line 89 89: def write(buf) 90: @wbuf << buf 91: end