class Thrift::MemoryBufferTransport
Constants
- GARBAGE_BUFFER_SIZE
Public Class Methods
Source
# File lib/thrift/transport/memory_buffer_transport.rb 27 def initialize(buffer = nil) 28 @buf = buffer ? Bytes.force_binary_encoding(buffer.dup) : Bytes.empty_byte_buffer 29 @index = 0 30 end
The transport copies the input buffer and keeps its own mutable storage.
Public Instance Methods
Source
# File lib/thrift/transport/memory_buffer_transport.rb 52 def available 53 @buf.length - @index 54 end
Source
# File lib/thrift/transport/memory_buffer_transport.rb 114 def inspect_buffer 115 out = [] 116 for idx in 0...(@buf.size) 117 # if idx != 0 118 # out << " " 119 # end 120 121 if idx == @index 122 out << ">" 123 end 124 125 out << @buf[idx].ord.to_s(16) 126 end 127 out.join(" ") 128 end
Source
# File lib/thrift/transport/memory_buffer_transport.rb 42 def peek 43 @index < @buf.size 44 end
Source
# File lib/thrift/transport/memory_buffer_transport.rb 56 def read(len) 57 raise TransportException.new(TransportException::NEGATIVE_SIZE, "Negative size") unless len >= 0 58 59 data = @buf.slice(@index, len) 60 @index += len 61 @index = @buf.size if @index > @buf.size 62 if @index >= GARBAGE_BUFFER_SIZE 63 @buf = @buf.slice(@index..-1) 64 @index = 0 65 end 66 if data.size < len 67 raise EOFError, "Not enough bytes remain in buffer" 68 end 69 data 70 end
Source
# File lib/thrift/transport/memory_buffer_transport.rb 72 def read_all(size) 73 raise TransportException.new(TransportException::NEGATIVE_SIZE, "Negative size") unless size >= 0 74 75 read(size) 76 end
Source
# File lib/thrift/transport/memory_buffer_transport.rb 78 def read_byte 79 raise EOFError.new("Not enough bytes remain in buffer") if @index >= @buf.size 80 val = Bytes.get_string_byte(@buf, @index) 81 @index += 1 82 if @index >= GARBAGE_BUFFER_SIZE 83 @buf = @buf.slice(@index..-1) 84 @index = 0 85 end 86 val 87 end
Source
# File lib/thrift/transport/memory_buffer_transport.rb 89 def read_into_buffer(buffer, size) 90 i = 0 91 while i < size 92 raise EOFError.new("Not enough bytes remain in buffer") if @index >= @buf.size 93 94 # The read buffer has some data now, so copy bytes over to the output buffer. 95 byte = Bytes.get_string_byte(@buf, @index) 96 Bytes.set_string_byte(buffer, i, byte) 97 @index += 1 98 i += 1 99 end 100 if @index >= GARBAGE_BUFFER_SIZE 101 @buf = @buf.slice(@index..-1) 102 @index = 0 103 end 104 i 105 end
Source
# File lib/thrift/transport/memory_buffer_transport.rb 47 def reset_buffer(new_buf = "") 48 @buf.replace Bytes.force_binary_encoding(new_buf) 49 @index = 0 50 end
this method does not use the passed object directly but copies it
Source
# File lib/thrift/transport/memory_buffer_transport.rb 130 def to_s 131 "memory" 132 end
Source
# File lib/thrift/transport/memory_buffer_transport.rb 107 def write(wbuf) 108 @buf << Bytes.force_binary_encoding(wbuf) 109 end