Class | Thrift::MemoryBufferTransport |
In: |
lib/thrift/transport/memory_buffer_transport.rb
lib/thrift/transport/memory_buffer_transport.rb |
Parent: | BaseTransport |
GARBAGE_BUFFER_SIZE | = | 4*(2**10) |
GARBAGE_BUFFER_SIZE | = | 4*(2**10) |
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 30 30: def initialize(buffer = nil) 31: @buf = buffer ? Bytes.force_binary_encoding(buffer) : Bytes.empty_byte_buffer 32: @index = 0 33: end
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 30 30: def initialize(buffer = nil) 31: @buf = buffer ? Bytes.force_binary_encoding(buffer) : Bytes.empty_byte_buffer 32: @index = 0 33: end
# File lib/thrift/transport/memory_buffer_transport.rb, line 55 55: def available 56: @buf.length - @index 57: end
# File lib/thrift/transport/memory_buffer_transport.rb, line 55 55: def available 56: @buf.length - @index 57: end
# File lib/thrift/transport/memory_buffer_transport.rb, line 109 109: def inspect_buffer 110: out = [] 111: for idx in 0...(@buf.size) 112: # if idx != 0 113: # out << " " 114: # end 115: 116: if idx == @index 117: out << ">" 118: end 119: 120: out << @buf[idx].ord.to_s(16) 121: end 122: out.join(" ") 123: end
# File lib/thrift/transport/memory_buffer_transport.rb, line 109 109: def inspect_buffer 110: out = [] 111: for idx in 0...(@buf.size) 112: # if idx != 0 113: # out << " " 114: # end 115: 116: if idx == @index 117: out << ">" 118: end 119: 120: out << @buf[idx].ord.to_s(16) 121: end 122: out.join(" ") 123: end
# File lib/thrift/transport/memory_buffer_transport.rb, line 35 35: def open? 36: return true 37: end
# File lib/thrift/transport/memory_buffer_transport.rb, line 35 35: def open? 36: return true 37: end
# File lib/thrift/transport/memory_buffer_transport.rb, line 45 45: def peek 46: @index < @buf.size 47: end
# File lib/thrift/transport/memory_buffer_transport.rb, line 45 45: def peek 46: @index < @buf.size 47: end
# File lib/thrift/transport/memory_buffer_transport.rb, line 59 59: def read(len) 60: data = @buf.slice(@index, len) 61: @index += len 62: @index = @buf.size if @index > @buf.size 63: if @index >= GARBAGE_BUFFER_SIZE 64: @buf = @buf.slice(@index..-1) 65: @index = 0 66: end 67: if data.size < len 68: raise EOFError, "Not enough bytes remain in buffer" 69: end 70: data 71: end
# File lib/thrift/transport/memory_buffer_transport.rb, line 59 59: def read(len) 60: data = @buf.slice(@index, len) 61: @index += len 62: @index = @buf.size if @index > @buf.size 63: if @index >= GARBAGE_BUFFER_SIZE 64: @buf = @buf.slice(@index..-1) 65: @index = 0 66: end 67: if data.size < len 68: raise EOFError, "Not enough bytes remain in buffer" 69: end 70: data 71: end
# File lib/thrift/transport/memory_buffer_transport.rb, line 73 73: def read_byte 74: raise EOFError.new("Not enough bytes remain in buffer") if @index >= @buf.size 75: val = Bytes.get_string_byte(@buf, @index) 76: @index += 1 77: if @index >= GARBAGE_BUFFER_SIZE 78: @buf = @buf.slice(@index..-1) 79: @index = 0 80: end 81: val 82: end
# File lib/thrift/transport/memory_buffer_transport.rb, line 73 73: def read_byte 74: raise EOFError.new("Not enough bytes remain in buffer") if @index >= @buf.size 75: val = Bytes.get_string_byte(@buf, @index) 76: @index += 1 77: if @index >= GARBAGE_BUFFER_SIZE 78: @buf = @buf.slice(@index..-1) 79: @index = 0 80: end 81: val 82: end
# File lib/thrift/transport/memory_buffer_transport.rb, line 84 84: def read_into_buffer(buffer, size) 85: i = 0 86: while i < size 87: raise EOFError.new("Not enough bytes remain in buffer") if @index >= @buf.size 88: 89: # The read buffer has some data now, so copy bytes over to the output buffer. 90: byte = Bytes.get_string_byte(@buf, @index) 91: Bytes.set_string_byte(buffer, i, byte) 92: @index += 1 93: i += 1 94: end 95: if @index >= GARBAGE_BUFFER_SIZE 96: @buf = @buf.slice(@index..-1) 97: @index = 0 98: end 99: i 100: end
# File lib/thrift/transport/memory_buffer_transport.rb, line 84 84: def read_into_buffer(buffer, size) 85: i = 0 86: while i < size 87: raise EOFError.new("Not enough bytes remain in buffer") if @index >= @buf.size 88: 89: # The read buffer has some data now, so copy bytes over to the output buffer. 90: byte = Bytes.get_string_byte(@buf, @index) 91: Bytes.set_string_byte(buffer, i, byte) 92: @index += 1 93: i += 1 94: end 95: if @index >= GARBAGE_BUFFER_SIZE 96: @buf = @buf.slice(@index..-1) 97: @index = 0 98: end 99: i 100: end
this method does not use the passed object directly but copies it
# File lib/thrift/transport/memory_buffer_transport.rb, line 50 50: def reset_buffer(new_buf = '') 51: @buf.replace Bytes.force_binary_encoding(new_buf) 52: @index = 0 53: end
this method does not use the passed object directly but copies it
# File lib/thrift/transport/memory_buffer_transport.rb, line 50 50: def reset_buffer(new_buf = '') 51: @buf.replace Bytes.force_binary_encoding(new_buf) 52: @index = 0 53: end
# File lib/thrift/transport/memory_buffer_transport.rb, line 102 102: def write(wbuf) 103: @buf << Bytes.force_binary_encoding(wbuf) 104: end