Module: BSON::LogStashEvent

Defined in:
lib/logstash/outputs/bson/logstash_event.rb

Overview

Injects behaviour for encoding and decoding time values to and from raw bytes as specified by the BSON spec.

Defined Under Namespace

Modules: ClassMethods

Constant Summary collapse

BSON_TYPE =

An Event is an embedded document is type 0x03 in the BSON spec..

3.chr.force_encoding(BINARY).freeze

Instance Method Summary collapse

Instance Method Details

#to_bson(buffer = ByteBuffer.new) ⇒ String

Get the event as encoded BSON.

Examples:

Get the hash as encoded BSON.

Event.new("field" => "value").to_bson

Returns:

  • (String)

    The encoded string.

See Also:



33
34
35
36
37
38
39
40
41
42
43
# File 'lib/logstash/outputs/bson/logstash_event.rb', line 33

def to_bson(buffer = ByteBuffer.new)
  position = buffer.length
  buffer.put_int32(0)
  to_hash.each do |field, value|
    buffer.put_byte(value.bson_type)
    buffer.put_cstring(field.to_bson_key)
    value.to_bson(buffer)
  end
  buffer.put_byte(NULL_BYTE)
  buffer.replace_int32(position, buffer.length - position)
end

#to_bson_normalized_valueBSON::Document

Converts the event to a normalized value in a BSON document.

Examples:

Convert the event to a normalized value.

event.to_bson_normalized_value

Returns:

  • (BSON::Document)

    The normalized event.



49
50
51
# File 'lib/logstash/outputs/bson/logstash_event.rb', line 49

def to_bson_normalized_value
  Document.new(self)
end