Class: Thrift::FramedTransport

### Home Classes Methods

### In Files

- lib/thrift/transport/framed_transport.rb

### Parent

Thrift::BaseTransport

### Methods

- ::new
- #close
- #flush
- #open
- #open?
- #read
- #read_byte
- #read_into_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::FramedTransport

### Public Class Methods

new(transport, read=true, write=true) click to toggle source

    # File lib/thrift/transport/framed_transport.rb, line 22
    def initialize(transport, read=true, write=true)
      @transport = transport
      @rbuf      = ''
      @wbuf      = ''
      @read      = read
      @write     = write
      @index      = 0
    end

### Public Instance Methods

close() click to toggle source

    # File lib/thrift/transport/framed_transport.rb, line 39
    def close
      @transport.close
    end

flush() click to toggle source

Writes the output buffer to the stream in the format of a 4-byte length followed by the actual data.

    # File lib/thrift/transport/framed_transport.rb, line 90
    def flush
      return @transport.flush unless @write

      out = [@wbuf.length].pack('N')
      out << @wbuf
      @transport.write(out)
      @transport.flush
      @wbuf = ''
    end

open() click to toggle source

    # File lib/thrift/transport/framed_transport.rb, line 35
    def open
      @transport.open
    end

open?() click to toggle source

    # File lib/thrift/transport/framed_transport.rb, line 31
    def open?
      @transport.open?
    end

read(sz) click to toggle source

    # File lib/thrift/transport/framed_transport.rb, line 43
    def read(sz)
      return @transport.read(sz) unless @read

      return '' if sz <= 0

      read_frame if @index >= @rbuf.length

      @index += sz
      @rbuf.slice(@index - sz, sz) || ''
    end

read_byte() click to toggle source

    # File lib/thrift/transport/framed_transport.rb, line 54
    def read_byte
      return @transport.read_byte() unless @read

      read_frame if @index >= @rbuf.length

      # The read buffer has some data now, read a single byte. Using get_string_byte() avoids
      # allocating a temp string of size 1 unnecessarily.
      @index += 1
      return ::Thrift::TransportUtils.get_string_byte(@rbuf, @index - 1)
    end

read_into_buffer(buffer, size) click to toggle source

    # File lib/thrift/transport/framed_transport.rb, line 65
    def read_into_buffer(buffer, size)
      i = 0
      while i < size
        read_frame if @index >= @rbuf.length

        # The read buffer has some data now, so copy bytes over to the output buffer.
        byte = ::Thrift::TransportUtils.get_string_byte(@rbuf, @index)
        ::Thrift::TransportUtils.set_string_byte(buffer, i, byte)
        @index += 1
        i += 1
      end
      i
    end

write(buf,sz=nil) click to toggle source

    # File lib/thrift/transport/framed_transport.rb, line 80
    def write(buf,sz=nil)
      return @transport.write(buf) unless @write

      @wbuf << (sz ? buf[0...sz] : buf)
    end

[Validate]

Generated with the Darkfish Rdoc Generator 2.