Class: SimpleAcp::Client::SSEParser
- Inherits:
-
Object
- Object
- SimpleAcp::Client::SSEParser
- Defined in:
- lib/simple_acp/client/sse.rb
Overview
Server-Sent Events (SSE) parser for streaming responses.
Parses chunked SSE data into structured events following the SSE specification (event, data, id, retry fields).
Instance Attribute Summary collapse
-
#events ⇒ Array<Hash>
readonly
Parsed events with :event and :data keys.
Instance Method Summary collapse
-
#each_event {|Hash| ... } ⇒ void
Iterate over parsed events, clearing them after yield.
-
#feed(chunk) ⇒ void
Feed a chunk of data to the parser.
-
#initialize ⇒ SSEParser
constructor
Create a new SSE parser.
Constructor Details
#initialize ⇒ SSEParser
Create a new SSE parser.
14 15 16 17 18 19 |
# File 'lib/simple_acp/client/sse.rb', line 14 def initialize @buffer = "" @events = [] @current_event = nil @current_data = [] end |
Instance Attribute Details
#events ⇒ Array<Hash> (readonly)
Returns parsed events with :event and :data keys.
11 12 13 |
# File 'lib/simple_acp/client/sse.rb', line 11 def events @events end |
Instance Method Details
#each_event {|Hash| ... } ⇒ void
This method returns an undefined value.
Iterate over parsed events, clearing them after yield.
35 36 37 38 39 40 |
# File 'lib/simple_acp/client/sse.rb', line 35 def each_event flush_events while (event = @events.shift) yield event end end |
#feed(chunk) ⇒ void
This method returns an undefined value.
Feed a chunk of data to the parser.
25 26 27 28 29 |
# File 'lib/simple_acp/client/sse.rb', line 25 def feed(chunk) @buffer += chunk parse_buffer flush_events end |