Class: Fluent::Plugin::MessagePackParser

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

Constant Summary

Constants inherited from Parser

Parser::AVAILABLE_PARSER_VALUE_TYPES, Parser::PARSER_TYPES, Parser::TRUTHY_VALUES

Constants included from Configurable

Configurable::CONFIG_TYPE_REGISTRY

Instance Attribute Summary

Attributes inherited from Parser

#type_converters

Attributes inherited from Base

#under_plugin_development

Instance Method Summary collapse

Methods inherited from Parser

#build_type_converters, #call, #convert_values, #implement?, #initialize, #parse_time, #parse_with_timeout, #start, #stop, #string_like_null

Methods included from TimeMixin::Parser

included, #time_parser_create

Methods included from OwnedByMixin

#log, #owner, #owner=

Methods inherited from Base

#acquire_worker_lock, #after_shutdown, #after_shutdown?, #after_start, #after_started?, #before_shutdown, #before_shutdown?, #called_in_test?, #close, #closed?, #configured?, #context_router, #context_router=, #fluentd_worker_id, #get_lock_path, #has_router?, #initialize, #inspect, #multi_workers_ready?, #plugin_root_dir, #reloadable_plugin?, #shutdown, #shutdown?, #start, #started?, #stop, #stopped?, #string_safe_encoding, #terminate, #terminated?

Methods included from SystemConfig::Mixin

#system_config, #system_config_override

Methods included from Configurable

#config, #configure_proxy_generate, #configured_section_create, included, #initialize, lookup_type, register_type

Constructor Details

This class inherits a constructor from Fluent::Plugin::Parser

Instance Method Details

#configure(conf) ⇒ Object



25
26
27
28
# File 'lib/fluent/plugin/parser_msgpack.rb', line 25

def configure(conf)
  super
  @unpacker = Fluent::MessagePackFactory.engine_factory.unpacker
end

#parse(data, &block) ⇒ Object Also known as: parse_partial_data



34
35
36
37
38
# File 'lib/fluent/plugin/parser_msgpack.rb', line 34

def parse(data, &block)
  @unpacker.feed_each(data) do |obj|
    parse_unpacked_data(obj, &block)
  end
end

#parse_io(io, &block) ⇒ Object



41
42
43
44
45
46
# File 'lib/fluent/plugin/parser_msgpack.rb', line 41

def parse_io(io, &block)
  u = Fluent::MessagePackFactory.engine_factory.unpacker(io)
  u.each do |obj|
    parse_unpacked_data(obj, &block)
  end
end

#parse_unpacked_data(data) ⇒ Object



48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# File 'lib/fluent/plugin/parser_msgpack.rb', line 48

def parse_unpacked_data(data)
  if data.is_a?(Hash)
    time, record = convert_values(parse_time(data), data)
    yield time, record
    return
  end

  unless data.is_a?(Array)
    yield nil, nil
    return
  end

  data.each do |record|
    unless record.is_a?(Hash)
      yield nil, nil
      next
    end
    time, converted_record = convert_values(parse_time(record), record)
    yield time, converted_record
  end
end

#parser_typeObject



30
31
32
# File 'lib/fluent/plugin/parser_msgpack.rb', line 30

def parser_type
  :binary
end