Class: Fluent::MemoryBufferChunk

Inherits:
BufferChunk show all
Defined in:
lib/fluent/plugin/buf_memory.rb

Instance Attribute Summary collapse

Attributes inherited from BufferChunk

#key

Instance Method Summary collapse

Methods inherited from BufferChunk

#empty?

Constructor Details

#initialize(key, data = '') ⇒ MemoryBufferChunk

Returns a new instance of MemoryBufferChunk.



25
26
27
28
29
30
31
32
# File 'lib/fluent/plugin/buf_memory.rb', line 25

def initialize(key, data='')
  @data = data
  @data.force_encoding('ASCII-8BIT')
  now = Time.now.utc
  u1 = ((now.to_i*1000*1000+now.usec) << 12 | rand(0xfff))
  @unique_id = [u1 >> 32, u1 & 0xffffffff, rand(0xffffffff), rand(0xffffffff)].pack('NNNN')
  super(key)
end

Instance Attribute Details

#unique_idObject (readonly)

Returns the value of attribute unique_id.



34
35
36
# File 'lib/fluent/plugin/buf_memory.rb', line 34

def unique_id
  @unique_id
end

Instance Method Details

#<<(data) ⇒ Object



36
37
38
39
# File 'lib/fluent/plugin/buf_memory.rb', line 36

def <<(data)
  data.force_encoding('ASCII-8BIT')
  @data << data
end

#closeObject



45
46
# File 'lib/fluent/plugin/buf_memory.rb', line 45

def close
end

#msgpack_each(&block) ⇒ Object

optimize



65
66
67
68
# File 'lib/fluent/plugin/buf_memory.rb', line 65

def msgpack_each(&block)
  u = Fluent::Engine.msgpack_factory.unpacker
  u.feed_each(@data, &block)
end

#open(&block) ⇒ Object



55
56
57
# File 'lib/fluent/plugin/buf_memory.rb', line 55

def open(&block)
  StringIO.open(@data, &block)
end

#purgeObject



48
49
# File 'lib/fluent/plugin/buf_memory.rb', line 48

def purge
end

#readObject



51
52
53
# File 'lib/fluent/plugin/buf_memory.rb', line 51

def read
  @data
end

#sizeObject



41
42
43
# File 'lib/fluent/plugin/buf_memory.rb', line 41

def size
  @data.bytesize
end

#write_to(io) ⇒ Object

optimize



60
61
62
# File 'lib/fluent/plugin/buf_memory.rb', line 60

def write_to(io)
  io.write @data
end