Class: Coatepec::Protocol
- Inherits:
-
Object
- Object
- Coatepec::Protocol
- Defined in:
- lib/coatepec/protocol.rb
Overview
Reads and writes the newline-delimited JSON (NDJSON) messages exchanged with the test worker over its private stdio pipe.
Defined Under Namespace
Classes: FramingError
Instance Method Summary collapse
-
#initialize(input:, output:) ⇒ Protocol
constructor
A new instance of Protocol.
- #read ⇒ Object
- #write(message) ⇒ Object
Constructor Details
#initialize(input:, output:) ⇒ Protocol
Returns a new instance of Protocol.
11 12 13 14 |
# File 'lib/coatepec/protocol.rb', line 11 def initialize(input:, output:) @input = input @output = output end |
Instance Method Details
#read ⇒ Object
21 22 23 24 25 26 27 28 |
# File 'lib/coatepec/protocol.rb', line 21 def read line = @input.gets return nil if line.nil? JSON.parse(line, symbolize_names: true) rescue JSON::ParserError => e raise FramingError, "Malformed NDJSON message: #{e.}" end |
#write(message) ⇒ Object
16 17 18 19 |
# File 'lib/coatepec/protocol.rb', line 16 def write() @output.puts(JSON.generate()) @output.flush end |