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

Methods

close   close   flush   flush   new   new   open   open   open?   open?   read   read   read_byte   read_byte   read_into_buffer   read_into_buffer   write   write  

Public Class methods

[Source]

    # File 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

[Source]

    # File 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 lib/thrift/transport/framed_transport.rb, line 40
40:     def close
41:       @transport.close
42:     end

[Source]

    # File 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 lib/thrift/transport/framed_transport.rb, line 91
91:     def flush
92:       return @transport.flush unless @write
93: 
94:       out = [@wbuf.length].pack('N')
95:       out << @wbuf
96:       @transport.write(out)
97:       @transport.flush
98:       @wbuf = ''
99:     end

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

[Source]

    # File lib/thrift/transport/framed_transport.rb, line 91
91:     def flush
92:       return @transport.flush unless @write
93: 
94:       out = [@wbuf.length].pack('N')
95:       out << @wbuf
96:       @transport.write(out)
97:       @transport.flush
98:       @wbuf = ''
99:     end

[Source]

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

[Source]

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

[Source]

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

[Source]

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

[Source]

    # File 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 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 lib/thrift/transport/framed_transport.rb, line 55
55:     def read_byte
56:       return @transport.read_byte() unless @read
57: 
58:       read_frame if @index >= @rbuf.length
59: 
60:       # The read buffer has some data now, read a single byte. Using get_string_byte() avoids
61:       # allocating a temp string of size 1 unnecessarily.
62:       @index += 1
63:       return ::Thrift::TransportUtils.get_string_byte(@rbuf, @index - 1)
64:     end

[Source]

    # File lib/thrift/transport/framed_transport.rb, line 55
55:     def read_byte
56:       return @transport.read_byte() unless @read
57: 
58:       read_frame if @index >= @rbuf.length
59: 
60:       # The read buffer has some data now, read a single byte. Using get_string_byte() avoids
61:       # allocating a temp string of size 1 unnecessarily.
62:       @index += 1
63:       return ::Thrift::TransportUtils.get_string_byte(@rbuf, @index - 1)
64:     end

[Source]

    # File lib/thrift/transport/framed_transport.rb, line 66
66:     def read_into_buffer(buffer, size)
67:       i = 0
68:       while i < size
69:         read_frame if @index >= @rbuf.length
70: 
71:         # The read buffer has some data now, so copy bytes over to the output buffer.
72:         byte = ::Thrift::TransportUtils.get_string_byte(@rbuf, @index)
73:         ::Thrift::TransportUtils.set_string_byte(buffer, i, byte)
74:         @index += 1
75:         i += 1
76:       end
77:       i
78:     end

[Source]

    # File lib/thrift/transport/framed_transport.rb, line 66
66:     def read_into_buffer(buffer, size)
67:       i = 0
68:       while i < size
69:         read_frame if @index >= @rbuf.length
70: 
71:         # The read buffer has some data now, so copy bytes over to the output buffer.
72:         byte = ::Thrift::TransportUtils.get_string_byte(@rbuf, @index)
73:         ::Thrift::TransportUtils.set_string_byte(buffer, i, byte)
74:         @index += 1
75:         i += 1
76:       end
77:       i
78:     end

[Source]

    # File lib/thrift/transport/framed_transport.rb, line 81
81:     def write(buf,sz=nil)
82:       return @transport.write(buf) unless @write
83: 
84:       @wbuf << (sz ? buf[0...sz] : buf)
85:     end

[Source]

    # File lib/thrift/transport/framed_transport.rb, line 81
81:     def write(buf,sz=nil)
82:       return @transport.write(buf) unless @write
83: 
84:       @wbuf << (sz ? buf[0...sz] : buf)
85:     end

[Validate]