Class: Thrift::MemoryBufferTransport

### Home Classes Methods

### In Files

- lib/thrift/transport/memory_buffer_transport.rb

### Parent

Thrift::BaseTransport

### Methods

- ::new
- #available
- #close
- #flush
- #inspect_buffer
- #open
- #open?
- #peek
- #read
- #read_byte
- #read_into_buffer
- #reset_buffer
- #write

### Files

- CHANGELOG
- README
- Makefile

### Class/Module Index

Quicksearch

- Thrift
- Thrift::ApplicationException
- Thrift::BaseProtocol
- Thrift::BaseProtocolFactory
- Thrift::BaseServer
- Thrift::BaseServerTransport
- Thrift::BaseTransport
- Thrift::BaseTransportFactory
- Thrift::BinaryProtocol
- Thrift::BinaryProtocolAcceleratedFactory
- Thrift::BinaryProtocolFactory
- Thrift::BufferedTransport
- Thrift::BufferedTransportFactory
- Thrift::Client
- Thrift::CompactProtocol
- Thrift::CompactProtocol::CompactTypes
- Thrift::CompactProtocolFactory
- Thrift::Deserializer
- Thrift::Exception
- Thrift::FramedTransport
- Thrift::FramedTransportFactory
- Thrift::HTTPClientTransport
- Thrift::IOStreamTransport
- Thrift::MemoryBufferTransport
- Thrift::MessageTypes
- Thrift::MongrelHTTPServer
- Thrift::MongrelHTTPServer::Handler
- Thrift::NonblockingServer
- Thrift::Processor
- Thrift::ProtocolException
- Thrift::Serializer
- Thrift::ServerSocket
- Thrift::SimpleServer
- Thrift::Socket
- Thrift::Struct
- Thrift::Struct_Union
- Thrift::ThreadPoolServer
- Thrift::ThreadedServer
- Thrift::TransportException
- Thrift::TransportUtils
- Thrift::TypeError
- Thrift::Types
- Thrift::UNIXServerSocket
- Thrift::UNIXSocket
- Thrift::Union
- Fixnum

No matching classes.

# Thrift::MemoryBufferTransport

### Constants

GARBAGE_BUFFER_SIZE

### 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 || ''
      @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 = ::Thrift::TransportUtils.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 = ::Thrift::TransportUtils.get_string_byte(@buf, @index)
        ::Thrift::TransportUtils.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 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 << wbuf
    end

[Validate]

Generated with the Darkfish Rdoc Generator 2.