Class: Fluent::MessagePackFormattedBufferData
- Inherits:
-
Object
- Object
- Fluent::MessagePackFormattedBufferData
- Defined in:
- lib/fluent/plugin/buf_event_limited.rb
Instance Attribute Summary collapse
-
#data ⇒ Object
(also: #to_str, #as_msg_pack)
readonly
Returns the value of attribute data.
Instance Method Summary collapse
-
#each_slice(target_sizes) {|slice_data, slice_size| ... } ⇒ Object
Partition the data into required sizes.
-
#initialize(data) ⇒ MessagePackFormattedBufferData
constructor
A new instance of MessagePackFormattedBufferData.
- #size ⇒ Object
Constructor Details
#initialize(data) ⇒ MessagePackFormattedBufferData
Returns a new instance of MessagePackFormattedBufferData.
8 9 10 |
# File 'lib/fluent/plugin/buf_event_limited.rb', line 8 def initialize(data) @data = data.to_str.freeze end |
Instance Attribute Details
#data ⇒ Object (readonly) Also known as: to_str, as_msg_pack
Returns the value of attribute data.
6 7 8 |
# File 'lib/fluent/plugin/buf_event_limited.rb', line 6 def data @data end |
Instance Method Details
#each_slice(target_sizes) {|slice_data, slice_size| ... } ⇒ Object
Partition the data into required sizes
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/fluent/plugin/buf_event_limited.rb', line 13 def each_slice(target_sizes) target_size = target_sizes.next slice_size = 0 slice_data = '' reader.each do |event| if slice_size == target_size yield(slice_data, slice_size) target_size = target_sizes.next slice_size = 0 slice_data = '' end slice_data << pack(event) slice_size += 1 end yield(slice_data, slice_size) end |
#size ⇒ Object
34 35 36 |
# File 'lib/fluent/plugin/buf_event_limited.rb', line 34 def size @size ||= reader.each.reduce(0) { |c, _| c + 1 } end |