Parent

Thrift::MemoryBufferTransport

Public Class Methods

new(buffer = nil) click to toggle source

If you pass a string to this, you should dup that string unless you want it to be modified by read and write

# File lib/thrift/transport/memory_buffer_transport.rb, line 29
def initialize(buffer = nil)
  @buf = buffer ? Bytes.force_binary_encoding(buffer) : Bytes.empty_byte_buffer
  @index = 0
end

Public Instance Methods

available() click to toggle source
# File lib/thrift/transport/memory_buffer_transport.rb, line 54
def available
  @buf.length - @index
end
close() click to toggle source
# File lib/thrift/transport/memory_buffer_transport.rb, line 41
def close
end
flush() click to toggle source
# File lib/thrift/transport/memory_buffer_transport.rb, line 105
def flush
end
inspect_buffer() click to toggle source
# File lib/thrift/transport/memory_buffer_transport.rb, line 108
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 38
def open
end
open?() click to toggle source
# File lib/thrift/transport/memory_buffer_transport.rb, line 34
def open?
  return true
end
peek() click to toggle source
# File lib/thrift/transport/memory_buffer_transport.rb, line 44
def peek
  @index < @buf.size
end
read(len) click to toggle source
# File lib/thrift/transport/memory_buffer_transport.rb, line 58
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 72
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 83
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 49
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 101
def write(wbuf)
  @buf << Bytes.force_binary_encoding(wbuf)
end

[Validate]

Generated with the Darkfish Rdoc Generator 2.