Class: Fluent::Plugin::Buffer

Inherits:
Object
  • Object
show all
Defined in:
lib/fluent/plugin/in_unix_client.rb

Instance Method Summary collapse

Constructor Details

#initialize(delimiter, format_json: false) ⇒ Buffer

Returns a new instance of Buffer.



167
168
169
170
171
# File 'lib/fluent/plugin/in_unix_client.rb', line 167

def initialize(delimiter, format_json: false)
  @buf = ""
  @delimiter = delimiter
  @format_json = format_json
end

Instance Method Details

#<<(data) ⇒ Object



177
178
179
# File 'lib/fluent/plugin/in_unix_client.rb', line 177

def <<(data)
  add(data)
end

#add(data) ⇒ Object



173
174
175
# File 'lib/fluent/plugin/in_unix_client.rb', line 173

def add(data)
  @buf << data
end

#extract_recordsObject



181
182
183
184
185
186
187
188
189
190
191
192
193
194
# File 'lib/fluent/plugin/in_unix_client.rb', line 181

def extract_records
  records = []

  pos_read = 0
  while pos_next_delimiter = @buf.index(@delimiter, pos_read)
    fixed = fix_format(@buf[pos_read...pos_next_delimiter])
    records << fixed unless fixed.empty?
    pos_read = pos_next_delimiter + @delimiter.size
  end

  @buf.slice!(0, pos_read) if pos_read > 0

  records
end