Class | Thrift::FramedTransport |
In: |
lib/thrift/transport/framed_transport.rb
lib/thrift/transport/framed_transport.rb |
Parent: | BaseTransport |
# 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
# 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
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 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
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 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
# 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
# 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
# File 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