class Thrift::MemoryBufferTransport
Constants
- GARBAGE_BUFFER_SIZE
Public Class Methods
new(buffer = nil)
click to toggle source
Public Instance Methods
available()
click to toggle source
# File lib/thrift/transport/memory_buffer_transport.rb, line 55 def available @buf.length - @index end
close()
click to toggle source
# File lib/thrift/transport/memory_buffer_transport.rb, line 42 def close end
flush()
click to toggle source
# File lib/thrift/transport/memory_buffer_transport.rb, line 106 def flush end
inspect_buffer()
click to toggle source
# File lib/thrift/transport/memory_buffer_transport.rb, line 109 def inspect_buffer out = [] for idx in 0...(@buf.size) # if idx != 0 # out << " " # end if idx == @index out << ">" end out << @buf[idx].ord.to_s(16) end out.join(" ") end
open()
click to toggle source
# File lib/thrift/transport/memory_buffer_transport.rb, line 39 def open end
open?()
click to toggle source
# File lib/thrift/transport/memory_buffer_transport.rb, line 35 def open? return true end
peek()
click to toggle source
# File lib/thrift/transport/memory_buffer_transport.rb, line 45 def peek @index < @buf.size end
read(len)
click to toggle source
# File lib/thrift/transport/memory_buffer_transport.rb, line 59 def read(len) data = @buf.slice(@index, len) @index += len @index = @buf.size if @index > @buf.size if @index >= GARBAGE_BUFFER_SIZE @buf = @buf.slice(@index..-1) @index = 0 end if data.size < len raise EOFError, "Not enough bytes remain in buffer" end data end
read_byte()
click to toggle source
# File lib/thrift/transport/memory_buffer_transport.rb, line 73 def read_byte raise EOFError.new("Not enough bytes remain in buffer") if @index >= @buf.size val = Bytes.get_string_byte(@buf, @index) @index += 1 if @index >= GARBAGE_BUFFER_SIZE @buf = @buf.slice(@index..-1) @index = 0 end val end
read_into_buffer(buffer, size)
click to toggle source
# File lib/thrift/transport/memory_buffer_transport.rb, line 84 def read_into_buffer(buffer, size) i = 0 while i < size raise EOFError.new("Not enough bytes remain in buffer") if @index >= @buf.size # The read buffer has some data now, so copy bytes over to the output buffer. byte = Bytes.get_string_byte(@buf, @index) Bytes.set_string_byte(buffer, i, byte) @index += 1 i += 1 end if @index >= GARBAGE_BUFFER_SIZE @buf = @buf.slice(@index..-1) @index = 0 end i end
reset_buffer(new_buf = '')
click to toggle source
this method does not use the passed object directly but copies it
# File lib/thrift/transport/memory_buffer_transport.rb, line 50 def reset_buffer(new_buf = '') @buf.replace Bytes.force_binary_encoding(new_buf) @index = 0 end
write(wbuf)
click to toggle source
# File lib/thrift/transport/memory_buffer_transport.rb, line 102 def write(wbuf) @buf << Bytes.force_binary_encoding(wbuf) end