class Thrift::BufferedTransport
Constants
- DEFAULT_BUFFER
Public Class Methods
Source
# File lib/thrift/transport/buffered_transport.rb 26 def initialize(transport) 27 @transport = transport 28 @wbuf = Bytes.empty_byte_buffer 29 @rbuf = Bytes.empty_byte_buffer 30 @index = 0 31 end
Public Instance Methods
Source
# File lib/thrift/transport/buffered_transport.rb 41 def close 42 flush 43 @transport.close 44 end
Source
# File lib/thrift/transport/buffered_transport.rb 100 def flush 101 unless @wbuf.empty? 102 @transport.write(@wbuf) 103 @wbuf = Bytes.empty_byte_buffer 104 end 105 106 @transport.flush 107 end
Source
# File lib/thrift/transport/buffered_transport.rb 37 def open 38 @transport.open 39 end
Source
# File lib/thrift/transport/buffered_transport.rb 33 def open? 34 @transport.open? 35 end
Source
# File lib/thrift/transport/buffered_transport.rb 46 def read(sz) 47 @index += sz 48 ret = @rbuf.slice(@index - sz, sz) || Bytes.empty_byte_buffer 49 50 if ret.length == 0 51 @rbuf = @transport.read([sz, DEFAULT_BUFFER].max) 52 @index = sz 53 ret = @rbuf.slice(0, sz) || Bytes.empty_byte_buffer 54 end 55 56 ret 57 end
Source
# File lib/thrift/transport/buffered_transport.rb 59 def read_byte 60 # If the read buffer is exhausted, try to read up to DEFAULT_BUFFER more bytes into it. 61 if @index >= @rbuf.size 62 @rbuf = @transport.read(DEFAULT_BUFFER) 63 @index = 0 64 end 65 66 # The read buffer has some data now, read a single byte. Using get_string_byte() avoids 67 # allocating a temp string of size 1 unnecessarily. 68 @index += 1 69 Bytes.get_string_byte(@rbuf, @index - 1) 70 end
Source
# File lib/thrift/transport/buffered_transport.rb 78 def read_into_buffer(buffer, size) 79 i = 0 80 while i < size 81 # If the read buffer is exhausted, try to read up to DEFAULT_BUFFER more bytes into it. 82 if @index >= @rbuf.size 83 @rbuf = @transport.read(DEFAULT_BUFFER) 84 @index = 0 85 end 86 87 # The read buffer has some data now, so copy bytes over to the output buffer. 88 byte = Bytes.get_string_byte(@rbuf, @index) 89 Bytes.set_string_byte(buffer, i, byte) 90 @index += 1 91 i += 1 92 end 93 i 94 end
Reads a number of bytes from the transport into the buffer passed.
buffer - The String (byte buffer) to write data to; this is assumed to have a BINARY encoding. size - The number of bytes to read from the transport and write to the buffer.
Returns the number of bytes read.
Source
# File lib/thrift/transport/buffered_transport.rb 109 def to_s 110 "buffered(#{@transport})" 111 end
Source
# File lib/thrift/transport/buffered_transport.rb 96 def write(buf) 97 @wbuf << Bytes.force_binary_encoding(buf) 98 end