Class: Quonfig::SSEConfigClient::EventParser
- Inherits:
-
Object
- Object
- Quonfig::SSEConfigClient::EventParser
- Defined in:
- lib/quonfig/sse_config_client.rb
Overview
Streaming SSE parser. Accepts byte chunks (any encoding), yields one Quonfig::StreamEvent per complete event. Tolerates:
- chunks that split a UTF-8 multi-byte character (buffer in 8-bit,
transcode whole lines)
- chunks that split a line mid-way
- any of CR / LF / CRLF as line terminators
- +data:+, +data: + (optional space per SSE spec)
- +:comment+ lines (keepalives — ignored)
- multi-line +data:+ (concatenated with +\n+, per spec)
Ignores event: and retry: — api-delivery does not emit them and the Quonfig wire contract does not honor reconnect-time directives. Malformed data: JSON is logged and skipped; one bad event does not tear down the stream.
Instance Method Summary collapse
- #feed(chunk) ⇒ Object
-
#initialize(logger: nil) ⇒ EventParser
constructor
A new instance of EventParser.
Constructor Details
#initialize(logger: nil) ⇒ EventParser
Returns a new instance of EventParser.
499 500 501 502 503 504 505 |
# File 'lib/quonfig/sse_config_client.rb', line 499 def initialize(logger: nil) @logger = logger @reader = LineReader.new @data = +'' @have_data = false @id = nil end |
Instance Method Details
#feed(chunk) ⇒ Object
507 508 509 510 511 512 513 514 515 516 517 518 |
# File 'lib/quonfig/sse_config_client.rb', line 507 def feed(chunk) @reader.feed(chunk) do |line| if line.empty? event = flush yield event if event elsif line.start_with?(':') # comment / keepalive — ignore else process_field(line) end end end |