Class: Fluent::MemoryBufferChunk
- Inherits:
-
BufferChunk
- Object
- BufferChunk
- Fluent::MemoryBufferChunk
- Defined in:
- lib/fluent/plugin/buf_memory.rb
Instance Attribute Summary collapse
-
#unique_id ⇒ Object
readonly
Returns the value of attribute unique_id.
Attributes inherited from BufferChunk
Instance Method Summary collapse
- #<<(data) ⇒ Object
- #close ⇒ Object
-
#initialize(key, data = '') ⇒ MemoryBufferChunk
constructor
A new instance of MemoryBufferChunk.
-
#msgpack_each(&block) ⇒ Object
optimize.
- #open(&block) ⇒ Object
- #purge ⇒ Object
- #read ⇒ Object
- #size ⇒ Object
-
#write_to(io) ⇒ Object
optimize.
Methods inherited from BufferChunk
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_id ⇒ Object (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 |
#close ⇒ Object
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 |
#purge ⇒ Object
48 49 |
# File 'lib/fluent/plugin/buf_memory.rb', line 48 def purge end |
#read ⇒ Object
51 52 53 |
# File 'lib/fluent/plugin/buf_memory.rb', line 51 def read @data end |
#size ⇒ Object
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 |