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      = Bytes.empty_byte_buffer
26:       @wbuf      = Bytes.empty_byte_buffer
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      = Bytes.empty_byte_buffer
26:       @wbuf      = Bytes.empty_byte_buffer
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:       # Array#pack should return a BINARY encoded String, so it shouldn't be necessary to force encoding
 96:       out << @wbuf
 97:       @transport.write(out)
 98:       @transport.flush
 99:       @wbuf = Bytes.empty_byte_buffer
100:     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:       # Array#pack should return a BINARY encoded String, so it shouldn't be necessary to force encoding
 96:       out << @wbuf
 97:       @transport.write(out)
 98:       @transport.flush
 99:       @wbuf = Bytes.empty_byte_buffer
100:     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 Bytes.empty_byte_buffer if sz <= 0
48: 
49:       read_frame if @index >= @rbuf.length
50: 
51:       @index += sz
52:       @rbuf.slice(@index - sz, sz) || Bytes.empty_byte_buffer
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 Bytes.empty_byte_buffer if sz <= 0
48: 
49:       read_frame if @index >= @rbuf.length
50: 
51:       @index += sz
52:       @rbuf.slice(@index - sz, sz) || Bytes.empty_byte_buffer
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 Bytes.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 Bytes.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 = Bytes.get_string_byte(@rbuf, @index)
73:         Bytes.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 = Bytes.get_string_byte(@rbuf, @index)
73:         Bytes.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 80
80:     def write(buf, sz=nil)
81:       return @transport.write(buf) unless @write
82: 
83:       buf = Bytes.force_binary_encoding(buf)
84:       @wbuf << (sz ? buf[0...sz] : buf)
85:     end

[Source]

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

[Validate]