Class: VectorAmp::Transport::SSEParser

Inherits:
Object
  • Object
show all
Defined in:
lib/vector_amp/transport/http.rb

Instance Method Summary collapse

Constructor Details

#initializeSSEParser

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

#flushObject



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