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.
536 537 538 539 540 541 542 |
# File 'lib/quonfig/sse_config_client.rb', line 536 def initialize(logger: nil) @logger = logger @reader = LineReader.new @data = +'' @have_data = false @id = nil end |
Instance Method Details
#feed(chunk) ⇒ Object
544 545 546 547 548 549 550 551 552 553 554 555 |
# File 'lib/quonfig/sse_config_client.rb', line 544 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 |