class Thrift::FramedTransport

Public Class Methods

new(transport, read=true, write=true) click to toggle source
# File build/evernote-mode-FpyAOB/evernote-mode-0.41/ruby/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 build/evernote-mode-FpyAOB/evernote-mode-0.41/ruby/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 build/evernote-mode-FpyAOB/evernote-mode-0.41/ruby/thrift/transport/framed_transport.rb, line 64
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 build/evernote-mode-FpyAOB/evernote-mode-0.41/ruby/thrift/transport/framed_transport.rb, line 35
def open
  @transport.open
end
open?() click to toggle source
# File build/evernote-mode-FpyAOB/evernote-mode-0.41/ruby/thrift/transport/framed_transport.rb, line 31
def open?
  @transport.open?
end
read(sz) click to toggle source
# File build/evernote-mode-FpyAOB/evernote-mode-0.41/ruby/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
write(buf,sz=nil) click to toggle source
# File build/evernote-mode-FpyAOB/evernote-mode-0.41/ruby/thrift/transport/framed_transport.rb, line 54
def write(buf,sz=nil)
  return @transport.write(buf) unless @write

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

Private Instance Methods

read_frame() click to toggle source
# File build/evernote-mode-FpyAOB/evernote-mode-0.41/ruby/thrift/transport/framed_transport.rb, line 76
def read_frame
  sz = @transport.read_all(4).unpack('N').first

  @index = 0
  @rbuf = @transport.read_all(sz)
end