Class Thrift::FramedTransport
In: ruby/lib/thrift/transport/framed_transport.rb
Parent: BaseTransport

Methods

close   flush   new   open   open?   read   read_frame   write  

Public Class methods

[Source]

    # File ruby/lib/thrift/transport/framed_transport.rb, line 23
23:     def initialize(transport, read=true, write=true)
24:       @transport = transport
25:       @rbuf      = ''
26:       @wbuf      = ''
27:       @read      = read
28:       @write     = write
29:       @index      = 0
30:     end

Public Instance methods

[Source]

    # File ruby/lib/thrift/transport/framed_transport.rb, line 40
40:     def close
41:       @transport.close
42:     end

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

[Source]

    # File ruby/lib/thrift/transport/framed_transport.rb, line 65
65:     def flush
66:       return @transport.flush unless @write
67: 
68:       out = [@wbuf.length].pack('N')
69:       out << @wbuf
70:       @transport.write(out)
71:       @transport.flush
72:       @wbuf = ''
73:     end

[Source]

    # File ruby/lib/thrift/transport/framed_transport.rb, line 36
36:     def open
37:       @transport.open
38:     end

[Source]

    # File ruby/lib/thrift/transport/framed_transport.rb, line 32
32:     def open?
33:       @transport.open?
34:     end

[Source]

    # File ruby/lib/thrift/transport/framed_transport.rb, line 44
44:     def read(sz)
45:       return @transport.read(sz) unless @read
46: 
47:       return '' if sz <= 0
48: 
49:       read_frame if @index >= @rbuf.length
50: 
51:       @index += sz
52:       @rbuf.slice(@index - sz, sz) || ''
53:     end

[Source]

    # File ruby/lib/thrift/transport/framed_transport.rb, line 55
55:     def write(buf,sz=nil)
56:       return @transport.write(buf) unless @write
57: 
58:       @wbuf << (sz ? buf[0...sz] : buf)
59:     end

Private Instance methods

[Source]

    # File ruby/lib/thrift/transport/framed_transport.rb, line 77
77:     def read_frame
78:       sz = @transport.read_all(4).unpack('N').first
79: 
80:       @index = 0
81:       @rbuf = @transport.read_all(sz)
82:     end

[Validate]