class Fluent::Plugin::Buffer::MemoryChunk

Public Class Methods

new(metadata, compress: :text) click to toggle source
Calls superclass method Fluent::Plugin::Buffer::Chunk::new
# File lib/fluent/plugin/buffer/memory_chunk.rb, line 23
def initialize(metadata, compress: :text)
  super
  @chunk = ''.force_encoding(Encoding::ASCII_8BIT)
  @chunk_bytes = 0
  @adding_bytes = 0
  @adding_size = 0
end

Public Instance Methods

bytesize() click to toggle source
# File lib/fluent/plugin/buffer/memory_chunk.rb, line 57
def bytesize
  @chunk_bytes + @adding_bytes
end
commit() click to toggle source
# File lib/fluent/plugin/buffer/memory_chunk.rb, line 41
def commit
  @size += @adding_size
  @chunk_bytes += @adding_bytes

  @adding_bytes = @adding_size = 0
  @modified_at = Fluent::Clock.real_now
  @modified_at_object = nil
  true
end
concat(bulk, bulk_size) click to toggle source
# File lib/fluent/plugin/buffer/memory_chunk.rb, line 31
def concat(bulk, bulk_size)
  raise "BUG: concatenating to unwritable chunk, now '#{self.state}'" unless self.writable?

  bulk.force_encoding(Encoding::ASCII_8BIT)
  @chunk << bulk
  @adding_bytes += bulk.bytesize
  @adding_size += bulk_size
  true
end
empty?() click to toggle source
# File lib/fluent/plugin/buffer/memory_chunk.rb, line 65
def empty?
  @chunk.empty?
end
open(**kwargs, &block) click to toggle source
# File lib/fluent/plugin/buffer/memory_chunk.rb, line 80
def open(**kwargs, &block)
  StringIO.open(@chunk, &block)
end
purge() click to toggle source
Calls superclass method Fluent::Plugin::Buffer::Chunk#purge
# File lib/fluent/plugin/buffer/memory_chunk.rb, line 69
def purge
  super
  @chunk = ''.force_encoding("ASCII-8BIT")
  @chunk_bytes = @size = @adding_bytes = @adding_size = 0
  true
end
read(**kwargs) click to toggle source
# File lib/fluent/plugin/buffer/memory_chunk.rb, line 76
def read(**kwargs)
  @chunk
end
rollback() click to toggle source
# File lib/fluent/plugin/buffer/memory_chunk.rb, line 51
def rollback
  @chunk.slice!(@chunk_bytes, @adding_bytes)
  @adding_bytes = @adding_size = 0
  true
end
size() click to toggle source
# File lib/fluent/plugin/buffer/memory_chunk.rb, line 61
def size
  @size + @adding_size
end
write_to(io, **kwargs) click to toggle source
# File lib/fluent/plugin/buffer/memory_chunk.rb, line 84
def write_to(io, **kwargs)
  # re-implementation to optimize not to create StringIO
  io.write @chunk
end