Class: Thrift::MemoryBufferTransport
- Inherits:
-
BaseTransport
- Object
- BaseTransport
- Thrift::MemoryBufferTransport
- Defined in:
- lib/thrift/transport/memory_buffer_transport.rb
Constant Summary collapse
- GARBAGE_BUFFER_SIZE =
4kB
4*(2**10)
Instance Method Summary collapse
- #available ⇒ Object
- #close ⇒ Object
- #flush ⇒ Object
-
#initialize(buffer = nil) ⇒ MemoryBufferTransport
constructor
If you pass a string to this, you should #dup that string unless you want it to be modified by #read and #write – this behavior is no longer required.
- #inspect_buffer ⇒ Object
- #open ⇒ Object
- #open? ⇒ Boolean
- #peek ⇒ Object
- #read(len) ⇒ Object
-
#reset_buffer(new_buf = '') ⇒ Object
this method does not use the passed object directly but copies it.
- #write(wbuf) ⇒ Object
Methods inherited from BaseTransport
Constructor Details
#initialize(buffer = nil) ⇒ MemoryBufferTransport
If you pass a string to this, you should #dup that string unless you want it to be modified by #read and #write – this behavior is no longer required. If you wish to change it go ahead, just make sure the specs pass
30 31 32 33 |
# File 'lib/thrift/transport/memory_buffer_transport.rb', line 30 def initialize(buffer = nil) @buf = buffer || '' @index = 0 end |
Instance Method Details
#available ⇒ Object
55 56 57 |
# File 'lib/thrift/transport/memory_buffer_transport.rb', line 55 def available @buf.length - @index end |
#close ⇒ Object
42 43 |
# File 'lib/thrift/transport/memory_buffer_transport.rb', line 42 def close end |
#flush ⇒ Object
77 78 |
# File 'lib/thrift/transport/memory_buffer_transport.rb', line 77 def flush end |
#inspect_buffer ⇒ Object
80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 |
# File 'lib/thrift/transport/memory_buffer_transport.rb', line 80 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 ⇒ Object
39 40 |
# File 'lib/thrift/transport/memory_buffer_transport.rb', line 39 def open end |
#open? ⇒ Boolean
35 36 37 |
# File 'lib/thrift/transport/memory_buffer_transport.rb', line 35 def open? return true end |
#peek ⇒ Object
45 46 47 |
# File 'lib/thrift/transport/memory_buffer_transport.rb', line 45 def peek @index < @buf.size end |
#read(len) ⇒ Object
59 60 61 62 63 64 65 66 67 68 69 70 71 |
# 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 |
#reset_buffer(new_buf = '') ⇒ Object
this method does not use the passed object directly but copies it
50 51 52 53 |
# File 'lib/thrift/transport/memory_buffer_transport.rb', line 50 def reset_buffer(new_buf = '') @buf.replace new_buf @index = 0 end |
#write(wbuf) ⇒ Object
73 74 75 |
# File 'lib/thrift/transport/memory_buffer_transport.rb', line 73 def write(wbuf) @buf << wbuf end |