Class: VectorAmp::Transport::SSEParser
- Inherits:
-
Object
- Object
- VectorAmp::Transport::SSEParser
- Defined in:
- lib/vector_amp/transport/http.rb
Instance Method Summary collapse
- #feed(chunk) ⇒ Object
- #flush ⇒ Object
-
#initialize ⇒ SSEParser
constructor
A new instance of SSEParser.
Constructor Details
#initialize ⇒ SSEParser
Returns a new instance of SSEParser.
113 114 115 |
# File 'lib/vector_amp/transport/http.rb', line 113 def initialize @buffer = +"" end |
Instance Method Details
#feed(chunk) ⇒ Object
117 118 119 120 121 122 123 124 |
# File 'lib/vector_amp/transport/http.rb', line 117 def feed(chunk) @buffer << chunk while (index = @buffer.index(/\r?\n\r?\n/)) frame = @buffer.slice!(0...index) @buffer.sub!(/\A\r?\n\r?\n/, "") emit(frame) { |event| yield event } end end |
#flush ⇒ Object
126 127 128 129 |
# File 'lib/vector_amp/transport/http.rb', line 126 def flush emit(@buffer) { |event| yield event } unless @buffer.empty? @buffer.clear end |