Class: Protocol::HTTY::Framer
- Inherits:
-
Object
- Object
- Protocol::HTTY::Framer
- Defined in:
- lib/protocol/htty/framer.rb
Overview
Encode and decode HTTY chunks on top of byte-oriented IO objects.
Constant Summary collapse
Instance Attribute Summary collapse
-
#input ⇒ Object
readonly
Returns the value of attribute input.
-
#output ⇒ Object
readonly
Returns the value of attribute output.
Instance Method Summary collapse
-
#close ⇒ Object
Close the wrapped input and output streams.
-
#closed? ⇒ Boolean
Check whether the output stream has been closed.
-
#flush ⇒ Object
Flush the output stream if it supports flushing.
-
#initialize(input, output = input) ⇒ Framer
constructor
Create a framer around the given input and output streams.
-
#read_chunk ⇒ Object
Read the next HTTY chunk from the input stream.
-
#write_chunk(payload) ⇒ Object
Write a single HTTY chunk to the output stream.
Constructor Details
#initialize(input, output = input) ⇒ Framer
Create a framer around the given input and output streams.
21 22 23 24 |
# File 'lib/protocol/htty/framer.rb', line 21 def initialize(input, output = input) @input = input @output = output end |
Instance Attribute Details
#input ⇒ Object (readonly)
Returns the value of attribute input.
26 27 28 |
# File 'lib/protocol/htty/framer.rb', line 26 def input @input end |
#output ⇒ Object (readonly)
Returns the value of attribute output.
27 28 29 |
# File 'lib/protocol/htty/framer.rb', line 27 def output @output end |
Instance Method Details
#close ⇒ Object
Close the wrapped input and output streams. If input and output are the same object, it is only closed once.
66 67 68 69 |
# File 'lib/protocol/htty/framer.rb', line 66 def close @output.close if @output.respond_to?(:close) @input.close if !@input.equal?(@output) && @input.respond_to?(:close) end |
#closed? ⇒ Boolean
Check whether the output stream has been closed.
73 74 75 |
# File 'lib/protocol/htty/framer.rb', line 73 def closed? @output.respond_to?(:closed?) && @output.closed? end |
#flush ⇒ Object
Flush the output stream if it supports flushing.
59 60 61 |
# File 'lib/protocol/htty/framer.rb', line 59 def flush @output.flush if @output.respond_to?(:flush) end |
#read_chunk ⇒ Object
Read the next HTTY chunk from the input stream. Non-HTTY terminal output is ignored until a valid chunk prefix is found.
43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/protocol/htty/framer.rb', line 43 def read_chunk while payload = read_payload if payload.start_with?("HTTY;") && !payload.start_with?(PREFIX) raise ProtocolError, "Unsupported HTTY chunk version: #{payload.inspect}" end next unless payload.start_with?(PREFIX) encoded = payload.delete_prefix(PREFIX) return Base64.strict_decode64(encoded) end return nil end |